diff --git a/changelog/unreleased/SOLR-18371-remove-prequerycommand-solrindexsearcher-methods.yml b/changelog/unreleased/SOLR-18371-remove-prequerycommand-solrindexsearcher-methods.yml new file mode 100644 index 000000000000..455fde7f5442 --- /dev/null +++ b/changelog/unreleased/SOLR-18371-remove-prequerycommand-solrindexsearcher-methods.yml @@ -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 diff --git a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java index f1a87df3e0ba..28874ada8a7b 100644 --- a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java @@ -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 */ @@ -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 + QueryCommand qc = + new QueryCommand() + .setQuery(boostedMLTQuery) + .setFilterList(filters) + .setOffset(start) + .setLen(rows) + .setFlags(flags) + .setNeedDocSet(this.needDocSet); + return qc.search(searcher).getDocListAndSet(); } /** diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java index 33d86a7de777..e7786f71d3b0 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -778,8 +778,8 @@ public boolean regenerateItem( .setLen(nDocs) .setSupersetMaxDoc(nDocs) .setFlags(flags); - QueryResult qr = new QueryResult(); - newSearcher.getDocListC(qr, qc); + // called for its cache side effect; the returned QueryResult is unused + newSearcher.getDocListC(qc); return true; } }); @@ -788,13 +788,7 @@ public boolean regenerateItem( /** Primary entrypoint for searching, using a {@link QueryCommand}. */ public QueryResult search(QueryCommand cmd) throws IOException { - return search(new QueryResult(), cmd); - } - - @Deprecated - public QueryResult search(QueryResult qr, QueryCommand cmd) throws IOException { - getDocListC(qr, cmd); - return qr; + return getDocListC(cmd); } /** @@ -835,46 +829,6 @@ void searchWithTimeout() throws IOException { } } - /** - * Retrieve the {@link Document} instance corresponding to the document id. - * - * @see SolrDocumentFetcher - */ - /* @Override - @Deprecated - public Document doc(int docId) throws IOException { - return doc(docId, (Set) null); - }*/ - - /** - * Visit a document's fields using a {@link StoredFieldVisitor}. This method does not currently - * add to the Solr document cache. - * - * @see IndexReader#document(int, StoredFieldVisitor) - * @see SolrDocumentFetcher - */ - /*@Override - @Deprecated - public final void doc(int docId, StoredFieldVisitor visitor) throws IOException { - getDocFetcher().doc(docId, visitor); - }*/ - - /** - * Retrieve the {@link Document} instance corresponding to the document id. - * - *

NOTE: the document will have all fields accessible, but if a field filter is - * provided, only the provided fields will be loaded (the remainder will be available lazily). - * - * @see SolrDocumentFetcher - */ - /* - @Override - @Deprecated - public final Document doc(int i, Set fields) throws IOException { - return getDocFetcher().doc(i, fields); - } - */ - /** expert: internal API, subject to change */ public SolrCache getFieldValueCache() { return fieldValueCache; @@ -1529,66 +1483,6 @@ public DocSet getDocSet(Query query, DocSet filter) throws IOException { } } - /** - * Returns documents matching both query and filter and sorted by - * sort. - * - *

This method is cache aware and may retrieve filter from the cache or make an - * insertion into the cache as a result of this call. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - * @param filter may be null - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @return DocList meeting the specified criteria, should not be modified by the caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocList getDocList(Query query, Query filter, Sort lsort, int offset, int len) - throws IOException { - return new QueryCommand() - .setQuery(query) - .setFilterList(filter) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .search(this) - .getDocList(); - } - - /** - * Returns documents matching both query and the intersection of the filterList - * , sorted by sort. - * - *

This method is cache aware and may retrieve filter from the cache or make an - * insertion into the cache as a result of this call. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - * @param filterList may be null - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @return DocList meeting the specified criteria, should not be modified by the caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocList getDocList( - Query query, List filterList, Sort lsort, int offset, int len, int flags) - throws IOException { - return new QueryCommand() - .setQuery(query) - .setFilterList(filterList) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .setFlags(flags) - .search(this) - .getDocList(); - } - public static final int NO_CHECK_QCACHE = 0x80000000; public static final int GET_DOCSET = 0x40000000; static final int NO_CHECK_FILTERCACHE = 0x20000000; @@ -1630,8 +1524,8 @@ private boolean useFilterCacheForDynamicScoreQuery(boolean needSort, QueryComman * getDocList version that uses+populates query and filter caches. In the event of a timeout, the * cache is not populated. */ - private QueryResult getDocListC(QueryResult qr, QueryCommand cmd) throws IOException { - // TODO don't take QueryResult as arg; create one here + private QueryResult getDocListC(QueryCommand cmd) throws IOException { + QueryResult qr = new QueryResult(); if (cmd.getSegmentTerminateEarly()) { qr.setSegmentTerminatedEarly(Boolean.FALSE); } @@ -2152,197 +2046,6 @@ public ScoreMode scoreMode() { return pf.filter == null && pf.postFilter == null ? qr.getDocSet() : null; } - /** - * Returns documents matching query, sorted by sort. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @return DocList meeting the specified criteria, should not be modified by the caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocList getDocList(Query query, Sort lsort, int offset, int len) throws IOException { - return new QueryCommand() - .setQuery(query) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .search(this) - .getDocList(); - } - - /** - * Returns documents matching both query and filter and sorted by - * sort. Also returns the complete set of documents matching query and - * filter (regardless of offset and len). - * - *

This method is cache aware and may retrieve filter from the cache or make an - * insertion into the cache as a result of this call. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - *

The DocList and DocSet returned should not be modified. - * - * @param filter may be null - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @return DocListAndSet meeting the specified criteria, should not be modified by the - * caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocListAndSet getDocListAndSet(Query query, Query filter, Sort lsort, int offset, int len) - throws IOException { - return new QueryCommand() - .setQuery(query) - .setFilterList(filter) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .setNeedDocSet(true) - .search(this) - .getDocListAndSet(); - } - - /** - * Returns documents matching both query and filter and sorted by - * sort. Also returns the compete set of documents matching query and - * filter (regardless of offset and len). - * - *

This method is cache aware and may retrieve filter from the cache or make an - * insertion into the cache as a result of this call. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - *

The DocList and DocSet returned should not be modified. - * - * @param filter may be null - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @param flags user supplied flags for the result set - * @return DocListAndSet meeting the specified criteria, should not be modified by the - * caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocListAndSet getDocListAndSet( - Query query, Query filter, Sort lsort, int offset, int len, int flags) throws IOException { - return new QueryCommand() - .setQuery(query) - .setFilterList(filter) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .setFlags(flags) - .setNeedDocSet(true) - .search(this) - .getDocListAndSet(); - } - - /** - * Returns documents matching both query and the intersection of filterList - * , sorted by sort. Also returns the compete set of documents matching - * query and filter (regardless of offset and len). - * - *

This method is cache aware and may retrieve filter from the cache or make an - * insertion into the cache as a result of this call. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - *

The DocList and DocSet returned should not be modified. - * - * @param filterList may be null - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @return DocListAndSet meeting the specified criteria, should not be modified by the - * caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocListAndSet getDocListAndSet( - Query query, List filterList, Sort lsort, int offset, int len) throws IOException { - return new QueryCommand() - .setQuery(query) - .setFilterList(filterList) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .setNeedDocSet(true) - .search(this) - .getDocListAndSet(); - } - - /** - * Returns documents matching both query and the intersection of filterList - * , sorted by sort. Also returns the complete set of documents matching - * query and filter (regardless of offset and len - * ). - * - *

This method is cache aware and may retrieve filters from the cache or make an insertion into - * the cache as a result of this call. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - *

The DocList and DocSet returned should not be modified. - * - * @param filterList may be null - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @param flags user supplied flags for the result set - * @return DocListAndSet meeting the specified criteria, should not be modified by the - * caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocListAndSet getDocListAndSet( - Query query, List filterList, Sort lsort, int offset, int len, int flags) - throws IOException { - return new QueryCommand() - .setQuery(query) - .setFilterList(filterList) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .setFlags(flags) - .setNeedDocSet(true) - .search(this) - .getDocListAndSet(); - } - - /** - * Returns the top documents matching the query and sorted by - * sort, limited by offset and len. Also returns compete set of - * matching documents as a {@link DocSet}. - * - *

FUTURE: The returned DocList may be retrieved from a cache. - * - * @param lsort criteria by which to sort (if null, query relevance is used) - * @param offset offset into the list of documents to return - * @param len maximum number of documents to return - * @return DocListAndSet meeting the specified criteria, should not be modified by the - * caller. - * @throws IOException If there is a low-level I/O error. - */ - @Deprecated - public DocListAndSet getDocListAndSet(Query query, Sort lsort, int offset, int len) - throws IOException { - return new QueryCommand() - .setQuery(query) - .setSort(lsort) - .setOffset(offset) - .setLen(len) - .setNeedDocSet(true) - .search(this) - .getDocListAndSet(); - } - private DocList constantScoreDocList(int offset, int length, DocSet docs) { final int size = docs.size(); diff --git a/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java b/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java index 0f50498c75b6..23ad0ca65336 100644 --- a/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java +++ b/solr/core/src/test/org/apache/solr/highlight/HighlighterTest.java @@ -41,6 +41,7 @@ import org.apache.solr.handler.component.SearchComponent; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.search.QueryCommand; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; @@ -1397,7 +1398,14 @@ public void payloadFilteringSpanQuery() throws IOException { SolrQueryResponse resp = new SolrQueryResponse(); ResponseBuilder rb = new ResponseBuilder(req, resp, List.of(hlComp)); rb.setHighlightQuery(query); - rb.setResults(req.getSearcher().getDocListAndSet(query, null, 0, 1)); + rb.setResults( + new QueryCommand() + .setQuery(query) + .setOffset(0) + .setLen(1) + .setNeedDocSet(true) + .search(req.getSearcher()) + .getDocListAndSet()); // highlight: hlComp.prepare(rb); hlComp.process(rb);