Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
title: Remove the deprecated pre-QueryCommand SolrIndexSearcher methods - search(QueryResult, QueryCommand), three getDocList overloads and five getDocListAndSet overloads. Build a QueryCommand and call search(searcher) instead, using setNeedDocSet(true) where getDocListAndSet was used.
type: removed
authors:
- name: Serhiy Bzhezytskyy
links:
- name: SOLR-18371
url: https://issues.apache.org/jira/browse/SOLR-18371
34 changes: 20 additions & 14 deletions solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,16 @@ public DocListAndSet getMoreLikeThis(
BooleanClause.Occur.MUST_NOT);
this.realMLTQuery = realMLTQuery.build();

DocListAndSet results = new DocListAndSet();
if (this.needDocSet) {
results = searcher.getDocListAndSet(this.realMLTQuery, filters, null, start, rows, flags);
} else {
results.docList = searcher.getDocList(this.realMLTQuery, filters, null, start, rows, flags);
}
return results;
// setNeedDocSet must follow setFlags: it sets or clears GET_DOCSET within the flags
QueryCommand qc =
new QueryCommand()
.setQuery(this.realMLTQuery)
.setFilterList(filters)
.setOffset(start)
.setLen(rows)
.setFlags(flags)
.setNeedDocSet(this.needDocSet);
return qc.search(searcher).getDocListAndSet();
}

/** Sets {@link #boostedMLTQuery} and returns it */
Expand Down Expand Up @@ -455,13 +458,16 @@ public DocListAndSet getMoreLikeThis(
rawMLTQuery = mlt.like(multifieldDoc);
}
boostedMLTQuery = getBoostedQuery(rawMLTQuery);
DocListAndSet results = new DocListAndSet();
if (this.needDocSet) {
results = searcher.getDocListAndSet(boostedMLTQuery, filters, null, start, rows, flags);
} else {
results.docList = searcher.getDocList(boostedMLTQuery, filters, null, start, rows, flags);
}
return results;
// setNeedDocSet must follow setFlags: it sets or clears GET_DOCSET within the flags

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ugh... wow, that sounds like a "foot gun"... is there anyway to prevent someone from making this mistake? Or, is it so localized to just this class that no one else will accidetnally do setNeedDocSet before setFlags?

Any ideas?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

setFlags ORs bits in; setNeedDocSet OR's/AND-NOTs the GET_DOCSET bit in that same field. Order only matters for the false case — clearing, then a later setFlags whose value includes that bit, would undo the clear. Here flags only ever carries GET_SCORES, so it can't actually collide.

QueryCommand qc =
new QueryCommand()
.setQuery(boostedMLTQuery)
.setFilterList(filters)
.setOffset(start)
.setLen(rows)
.setFlags(flags)
.setNeedDocSet(this.needDocSet);
return qc.search(searcher).getDocListAndSet();
}

/**
Expand Down
Loading
Loading