-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Rescore functionality #1688
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
Changes from all commits
130cf63
79b2320
e3035d3
e70a533
1dc3a16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,94 @@ | ||||||||||||||||||||||||
/* | ||||||||||||||||||||||||
* Copyright 2020-2021 the original author or authors. | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||
* you may not use this file except in compliance with the License. | ||||||||||||||||||||||||
* You may obtain a copy of the License at | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||
* See the License for the specific language governing permissions and | ||||||||||||||||||||||||
* limitations under the License. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
package org.springframework.data.elasticsearch.core.query; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import org.elasticsearch.index.query.QueryBuilder; | ||||||||||||||||||||||||
import org.elasticsearch.search.rescore.QueryRescorerBuilder; | ||||||||||||||||||||||||
import org.springframework.lang.Nullable; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Implementation of RescorerQuery to be used for rescoring filtered search results. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @author Peer Mueller | ||||||||||||||||||||||||
* @since 4.2 | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
public class RescorerQuery { | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private final Query query; | ||||||||||||||||||||||||
private ScoreMode scoreMode = ScoreMode.Default; | ||||||||||||||||||||||||
@Nullable private Integer windowSize; | ||||||||||||||||||||||||
@Nullable private Float queryWeight; | ||||||||||||||||||||||||
@Nullable private Float rescoreQueryWeight; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public RescorerQuery(Query query) { | ||||||||||||||||||||||||
this.query = query; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
we must make sure this is never null. |
||||||||||||||||||||||||
|
||||||||||||||||||||||||
public Query getQuery() { | ||||||||||||||||||||||||
return query; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public ScoreMode getScoreMode() { | ||||||||||||||||||||||||
return scoreMode; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
@Nullable | ||||||||||||||||||||||||
public Integer getWindowSize() { | ||||||||||||||||||||||||
return windowSize; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
@Nullable | ||||||||||||||||||||||||
public Float getQueryWeight() { | ||||||||||||||||||||||||
return queryWeight; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
@Nullable | ||||||||||||||||||||||||
public Float getRescoreQueryWeight() { | ||||||||||||||||||||||||
return rescoreQueryWeight; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public RescorerQuery withScoreMode(ScoreMode scoreMode) { | ||||||||||||||||||||||||
this.scoreMode = scoreMode; | ||||||||||||||||||||||||
return this; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+63
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
public RescorerQuery withWindowSize(int windowSize) { | ||||||||||||||||||||||||
this.windowSize = windowSize; | ||||||||||||||||||||||||
return this; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public RescorerQuery withQueryWeight(float queryWeight) { | ||||||||||||||||||||||||
this.queryWeight = queryWeight; | ||||||||||||||||||||||||
return this; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public RescorerQuery withRescoreQueryWeight(float rescoreQueryWeight) { | ||||||||||||||||||||||||
this.rescoreQueryWeight = rescoreQueryWeight; | ||||||||||||||||||||||||
return this; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
public enum ScoreMode { | ||||||||||||||||||||||||
Default, | ||||||||||||||||||||||||
Avg, | ||||||||||||||||||||||||
Max, | ||||||||||||||||||||||||
Min, | ||||||||||||||||||||||||
Total, | ||||||||||||||||||||||||
Multiply | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a
NullPointerException
we should throw anIllegalArgumentException
here