healthonnet/hon-lucene-synonyms — pull request #15 by rmerizalde (2013-04-12 23:33:15+00:00)
Title: Issue when synonym list is empty

Hey Nolan, this is a great plugin. Its helping us sort out some of the business needs.

While I was testing the plugin I found a small issue. For example if you have a simple analyzer like this and synonym list is empty the plugin causes all searches to crash:

solr.WhitespaceTokenizerFactory

solr.SynonymFilterFactory
synonyms-${solr.env.dir:preview}/query_parser_synonyms.txt
false
true

The problem happens because the SynonymFilter return the input TokenStream if no synonyms have been defined.

return map.fst == null ? input : new SynonymFilter(input, map, ignoreCase);

Also, I noticed that plugin changes the order of the terms in some cases. For example:

jacket=>north face

Will output face before north in the generated query.

While looking at to code to figure out why I noticed you are using a TreeSet with the following comparison:

if (this.startPosition != other.startPosition) {
return this.startPosition - other.startPosition;
} else if (this.endPosition != other.endPosition) {
return this.endPosition - other.endPosition;
}
return this.text.compareTo(other.text);

If there any reason to sort the terms in the same position like this. The only reason I brought this up is because we could use a LinkedHashSet or List instead of a TreeSet. It will preserve the order of tokens in the synonym for a given position and we get O(1) vs. O(log n) for basic operations. I guess you had a reason for doing the TreeSet.