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

Removed Scorer#getWeight #13440

Merged
merged 7 commits into from
Jun 6, 2024

Conversation

iamsanjay
Copy link
Contributor

Description

Closes #13410

If Caller requires Weight then they have to keep track of Weight with which Scorer was created in the first place instead of relying on Scorer as @jpountz mentioned in the comment as well.

@iamsanjay
Copy link
Contributor Author

There is one issue that I have faced. To get reference of weight instance in Collector instance, one can override below method.

default void setWeight(Weight weight) {}

For BooleanWeight instance, I tried to create a Map.of(Scorer, Query) in above method and then use it setScorer to fetch the query as getWeight is not available now and therefore no way to fetch the respective query,

Map<Scorer, Query> mapScQy= new HashMap<Scorer, Query>();
          if(weight instanceof BooleanWeight bw){
            for(BooleanWeight.WeightedBooleanClause clause: bw.weightedClauses){
              mapScQy.put(clause.weight.scorer(context), clause.clause.query());
            }
          }

However, the scorer object that I found inside BooleanWeight#WeightedBooleanClause and the one with which setScorer is called, both are different. My point is that yes you can have get access to weight instance, However, It is not possible to fetch the Query for which that Scorer was created. IMO, It's not possible to create the Map and then use it in collect method.

Consequently I removed TestSubScorerFreqs.java and some other parts of code from the other test cases.

@jpountz
Copy link
Contributor

jpountz commented May 30, 2024

Could you also look into removing Weight from the Scorer constructor? To me this is the most annoying bit.

Regarding TestSubScorerFreqs, does using ScorerIndexSearcher rather than IndexSearcher help get scorer instances that match the Scorable?

@iamsanjay
Copy link
Contributor Author

Could you also look into removing Weight from the Scorer constructor? To me this is the most annoying bit.

Yup I am on it! Total 49 usages as per quick IntelliJ search.

Regarding TestSubScorerFreqs, does using ScorerIndexSearcher rather than IndexSearcher help get scorer instances that match the Scorable?

Okay, I will check If switching to ScorerIndexSearcher can help me getting same Scorer. Thanks!

@iamsanjay
Copy link
Contributor Author

@jpountz We are also removing weight from Subclasses of Scorer as well, right? Because I already removed from good amount of classes such as ConstantScoreScorer and few others. Just want to make sure before moving ahead.

@iamsanjay
Copy link
Contributor Author

  1. There were three classes that are using weight in some way so I leave them to be for now.

    FunctionQuery#AllScorer

    vals = func.getValues(weight.context, context);

    TermAutomatonScorer

    this.runAutomaton = new TermRunAutomaton(weight.automaton, subs.length);

    TestMinShouldMatch2#SlowMinShouldMatchScorer

    BooleanQuery bq = (BooleanQuery) weight.getQuery();

  2. As I removed weight, few ctors -- JustCompileScorer, SimpleScorer, TestScoreCachingWrappingScorer#SimpleScorer, Scorer -- have been reduced to default ctor. Should I removed those as well?

  3. As we removing Weight, some APIs that were calling with weight is not required. Hence I removed the weight from their method signature as well -- Check: FunctionValues#getRangeScorer and all the respective overrides.

  4. SpatialQuery has also one method where we could possibly change the API to remove the weight parameter as it is not required now. Should I change that as well? There is a possibility we may found some more APIs where the weight can be removed now.

@jpountz
Copy link
Contributor

jpountz commented May 31, 2024

We are also removing weight from Subclasses of Scorer as well, right?

Yes, that would be great. If there are a few sub classes that really need a Weight, we could keep it, it looks like you identitfied a few of them already.

@jpountz
Copy link
Contributor

jpountz commented May 31, 2024

few ctors have been reduced to default ctor. Should I removed those as well?

For those that are in the java folder, I'd keep them and add javadocs (I thought the build checked that). For those under the test folder, we can remove.

Check: FunctionValues#getRangeScorer

Good question. Your change looks good this way, but I know Solr is a heavy user of FunctionValues, I'm curious if that would be annoying to them. @gerlowskija @dsmiley @HoustonPutman Do you have an opinion on this?

SpatialQuery has also one method where we could possibly change the API to remove the weight parameter as it is not required now. Should I change that as well?

Yes. It looks like it was only there to be able to pass the Weight to a Scorer constructor.

@dsmiley
Copy link
Contributor

dsmiley commented May 31, 2024

It's not clear why Solr would care with regards to FunctionValues & Weights in particular. I don't notice Solr using Weights there but maybe I'm not looking in quite the right spot?

if Scorer.getWeight is being removed, I only see a couple places in Solr where this is used, both in LTR, interestingly. This shouldn't stop Lucene from doing what it ought to do.

@jpountz
Copy link
Contributor

jpountz commented Jun 3, 2024

It's not clear why Solr would care with regards to FunctionValues & Weights in particular. I don't notice Solr using Weights there but maybe I'm not looking in quite the right spot?

Maybe it doesn't use them, I was just trying to be careful since I believe that Solr is using the FunctionValues API a lot for custom scoring/sorting.

This shouldn't stop Lucene from doing what it ought to do.

Thanks for the guidance, this is the sort of feedback I was looking for.

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -458,7 +460,8 @@ API Changes
IndexSearcher#search(Query, CollectorManager) for TopFieldCollectorManager
and TopScoreDocCollectorManager. (Zach Chen, Adrien Grand, Michael McCandless, Greg Miller, Luca Cavanna)

* GITHUB#12854: Mark DrillSideways#createDrillDownFacetsCollector as @Deprecated. (Greg Miller)
* GITHUB#12854: Mark DrillSideways#createDrillDownFacetsCollector as @
Deprecated. (Greg Miller)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo the new line?

@jpountz jpountz merged commit d0d2aa2 into apache:main Jun 6, 2024
3 checks passed
@jpountz
Copy link
Contributor

jpountz commented Jun 6, 2024

Thank you!

cbuescher added a commit to elastic/elasticsearch that referenced this pull request Aug 29, 2024
Since apache/lucene#13440 Scorers don't keep track of a
Weight any longer, so the constructor doesn't exist any longer and callers need
to track the Weight if needed. So far I don't think we have any cases of this.
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.

Remove Scorer#getWeight.
3 participants