Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synonyms aren't expanded if boost applied in Solr 7.3 #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YegorKozlov
Copy link

This used to work in Solr 6 but got broken in Solr 7.+
If a boost parameter is specified then synonyms are not expanded. The bug originates from SynonymExpandingExtendedDismaxQParserPlugin#applySynonymQueries which assumes that the input query is either a BoostedQuery or a BooleanQuery :

if (query instanceof BoostedQuery) {
  ...
} else if (query instanceof BooleanQuery) {
  ...
}

This is no longer the case in Solr 7 where BoostedQuery is deprecated and replaced by FunctionScoreQuery. With this in mind, the code flow in applySynonymQueries becomes

if (query instanceof BoostedQuery) {
  ...
} else if (query instanceof FunctionScoreQuery) { 
  FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) query;
  Query q = applySynonymQueries(functionScoreQuery.getWrappedQuery(), synonymQueries, originalBoost, synonymBoost);
  return new FunctionScoreQuery(q, source);
} else if (query instanceof BooleanQuery) {
  ...
}

The idea is to expand the wrapped query and then re-wrap the result.
The second argument in the constructor of FunctionScoreQuery is DoubleValuesSource. Unfortunately this is a private field without a getter and I found nothing better than to use introspection. This might not work in Java 9 and 10 as the semantics of Field#setAccessible changed. I tested with Java 8 and it worked for me.

Regards,
Yegor

@ghost
Copy link

ghost commented Jan 25, 2019

I applied this patch locally and confirmed it works. Any chance it gets merged?

AFAIK this is all that is needed to upgrade to Solr 7.

@smyadam
Copy link

smyadam commented Apr 27, 2020

Hi @jmendez-backcountry @YegorKozlov ,

We are facing the same issue in Solr 7.2.1 . Below is our configuration, will the patch work for Solr 7.2.1.
Below is our Configuration :

<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="defType">synonym_edismax</str>
<str name="synonyms">true</str>
<str name="synonyms.analyzer">enAnalyzer</str>
<str name="synonyms.originalBoost">2</str>
<str name="synonyms.synonymBoost">1.99</str>
<str name="synonyms.constructPhrases">true</str>
.....
<str name="boost">vintage_date</str> ->  this boost is not applied if I search for a synonym. 

Also how do I get the Jar file with the patch.

Also is there a reason you are not using default Solr Synonym feature. Not sure how active this group is.

@dsmiley
Copy link

dsmiley commented Apr 27, 2020

The project here looks 4 years old, which means it pre-dates some important improvements to Lucene/Solr that occurred a few years ago, especially the "sow" parameter. https://lucene.apache.org/solr/guide/7_4/the-extended-dismax-query-parser.html
Even 6.6 has this but using a backwards-compatible value of true for this param.

@smyadam
Copy link

smyadam commented Apr 27, 2020

Thanks @dsmiley for your reply.

are you saying since project is 4 years old there is no point using this in Solr 7.2.1 and use the default Solr Synonym feature or Still use this project but use the sow value as true in Solr.

Please advise, your comments will be very useful.

@dsmiley
Copy link

dsmiley commented Apr 27, 2020

Perhaps I shouldn't have waded into this :-), I've been following this project for years but didn't use it.

I browsed over the README.md and I think this plugin is not totally obsolete/redundant. But some of its features have become so. Multi-term synonyms is in 6.6 via "sow". Synonym boosting is in the newly released 8.5: https://sease.io/2020/03/introducing-weighted-synonyms-in-apache-lucene.html

Perhaps @softwaredoug at OSC may care to comment further. OSC always seems to be on top of the latest synonym situation. There ought to be a small book on this subject alone :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants