From ecddbc6337ee5d20da37d066f46c7813390fedf2 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Wed, 26 Jul 2006 00:34:14 +0000 Subject: [PATCH] allow flags on getDocListAndSet method: SOLR-39 git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@425567 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 + .../apache/solr/search/SolrIndexSearcher.java | 57 ++++++++++++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ce44570ae44..cb873730eed 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -38,6 +38,8 @@ New Features 20. Made query parser default operator configurable via schema.xml: The default operator remains "OR". +21. JAVA API: new version of SolrIndexSearcher.getDocListAndSet() which takes + flags (Greg Ludington via yonik, SOLR-39) Changes in runtime behavior 1. classes reorganized into different packages, package names changed to Apache diff --git a/src/java/org/apache/solr/search/SolrIndexSearcher.java b/src/java/org/apache/solr/search/SolrIndexSearcher.java index 6fc72597752..77db98744c6 100644 --- a/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -1008,15 +1008,49 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean { * @throws IOException */ public DocListAndSet getDocListAndSet(Query query, Query filter, Sort lsort, int offset, int len) throws IOException { - List filterList = null; - if (filter != null) { - filterList = new ArrayList(2); - filterList.add(filter); - } + List filterList = buildQueryList(filter); return getDocListAndSet(query, filterList, lsort, offset, len); } - + /** + * 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 query + * @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 + */ + public DocListAndSet getDocListAndSet(Query query, Query filter, Sort lsort, int offset, int len, int flags) throws IOException { + List filterList = buildQueryList(filter); + return getDocListAndSet(query, filterList, lsort, offset, len, flags); + } + + /** + * A simple utility method for to build a filterList from a query + * @param filter + * @return + */ + private List buildQueryList(Query filter) { + List filterList = null; + if (filter != null) { + filterList = new ArrayList(2); + filterList.add(filter); + } + return filterList; + } public DocListAndSet getDocListAndSet(Query query, List filterList, Sort lsort, int offset, int len) throws IOException { DocListAndSet ret = new DocListAndSet(); @@ -1024,7 +1058,11 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean { return ret; } - + public DocListAndSet getDocListAndSet(Query query, List filterList, Sort lsort, int offset, int len, int flags) throws IOException { + DocListAndSet ret = new DocListAndSet(); + getDocListC(ret,query,filterList,null,lsort,offset,len, flags |= GET_DOCSET); + return ret; + } /** * Returns documents matching both query and filter @@ -1047,6 +1085,11 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean { return ret; } + public DocListAndSet getDocListAndSet(Query query, DocSet filter, Sort lsort, int offset, int len, int flags) throws IOException { + DocListAndSet ret = new DocListAndSet(); + getDocListC(ret,query,null,filter,lsort,offset,len, flags |= GET_DOCSET); + return ret; + } protected DocList sortDocSet(DocSet set, Sort sort, int nDocs) throws IOException { final FieldSortedHitQueue hq =