Skip to content

Commit

Permalink
Update SynonymExpandingExtendedDismaxQParserPlugin.java
Browse files Browse the repository at this point in the history
Issue healthonnet#41, when original search term is quoted and synonym being expanded is item quoted don't re-quote when doing constructPhraseQueries.  Removes issue where double quotes appear in result.  Also when doing constructPhraseQueries, only quote phrases not single term synonyms.
  • Loading branch information
rpialum committed Jun 18, 2014
1 parent f2fe904 commit 4866bd8
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,12 @@ private void applySynonymQueries(Query query, List<Query> synonymQueries, float
*/
private List<Query> generateSynonymQueries(Analyzer synonymAnalyzer, SolrParams solrParams) throws IOException {

String origQuery = getQueryStringFromParser();
int queryLen = origQuery.length();

// TODO: make the token stream reusable?
TokenStream tokenStream = synonymAnalyzer.tokenStream(Const.IMPOSSIBLE_FIELD_NAME,
new StringReader(getQueryStringFromParser()));
new StringReader(origQuery);

SortedSetMultimap<Integer, TextInQuery> startPosToTextsInQuery = TreeMultimap.create();

Expand All @@ -460,10 +463,20 @@ private List<Query> generateSynonymQueries(Analyzer synonymAnalyzer, SolrParams
synonymBag.add(termToAdd);
}

if (constructPhraseQueries && typeAttribute.type().equals("SYNONYM")) {
// make a phrase out of the synonym
termToAdd = new StringBuilder(termToAdd).insert(0,'"').append('"').toString();
}
//Don't quote sibgle term term synonyms
if (constructPhraseQueries && typeAttribute.type().equals("SYNONYM") &&
termToAdd.contains(" "))
{
//Don't Quote when original is already surrounded by quotes
if( offsetAttribute.startOffset()==0 ||
offsetAttribute.endOffset() == queryLen ||
origQuery.charAt(offsetAttribute.startOffset()-1)!='"' ||
origQuery.charAt(offsetAttribute.endOffset())!='"')
{
// make a phrase out of the synonym
termToAdd = new StringBuilder(termToAdd).insert(0,'"').append('"').toString();
}
}
if (!bag) {
// create a graph of all possible synonym combinations,
// e.g. dog bite, hound bite, dog nibble, hound nibble, etc.
Expand Down

0 comments on commit 4866bd8

Please sign in to comment.