magibney commented on code in PR #2221:
URL: https://github.com/apache/solr/pull/2221#discussion_r2535092354
##########
solr/core/src/java/org/apache/solr/search/QueryUtils.java:
##########
@@ -53,34 +53,44 @@ public static boolean isNegative(Query q) {
return true;
}
+ /** Use instead: {@link #getConstantScore(Query)} */
+ @Deprecated
+ public static boolean isConstantScoreQuery(Query q) {
+ return getConstantScore(q) != null;
+ }
+
/**
* Recursively unwraps the specified query to determine whether it is
capable of producing a score
- * that varies across different documents. Returns true if this query is not
capable of producing
- * a varying score (i.e., it is a constant score query).
+ * that varies across different documents. Returns the constant score if
this query is not capable
+ * of producing a varying score (i.e., it is a constant score query), else
returns null.
Review Comment:
This is the main change. I _think_ that so long as we can recognize a
constant-score query, we can also determine the particular constant score, and
use it to provide scores (and maxScore) without actually sorting/scoring
anything.
I'd appreciate other eyes on this, in case there are edge cases that I'm
missing. Not sure what the best way is to directly test this ... open to ideas.
##########
solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java:
##########
@@ -1710,14 +1710,15 @@ private QueryResult getDocListC(QueryResult qr,
QueryCommand cmd) throws IOExcep
// - the sort doesn't contain score
// - we don't want score returned.
- // check if we should try and use the filter cache
+ // check if we should try and use the filter cache for the query itself
final boolean needSort;
- final boolean useFilterCache;
- if ((flags & (GET_SCORES | NO_CHECK_FILTERCACHE)) != 0 || filterCache ==
null) {
- needSort = true; // this value should be irrelevant when
`useFilterCache=false`
- useFilterCache = false;
+ final boolean useFilterCacheForQuery;
+ Float constantScore = 1.0f;
+ if ((flags & (NO_CHECK_FILTERCACHE)) != 0 || filterCache == null) {
Review Comment:
I think we can still optimize here even if scores are requested -- we just
need to supply the scores without actually running the query/scoring.
##########
solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java:
##########
@@ -1759,13 +1760,16 @@ private QueryResult getDocListC(QueryResult qr,
QueryCommand cmd) throws IOExcep
// todo: there could be a sortDocSet that could take a list of
// the filters instead of anding them first...
// perhaps there should be a multi-docset-iterator
+ if ((flags & GET_SCORES) == 0) {
+ constantScore = null;
+ }
Review Comment:
`constantScore ?= null` determines whether scores are added, so if the
client hasn't asked for scores, it doesn't matter whether we could provide them
... set `constantScore = null` so that we don't add scores to the response.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]