org.apache.solr.search
Class SolrIndexSearcher

java.lang.Object
  extended by org.apache.lucene.search.IndexSearcher
      extended by org.apache.solr.search.SolrIndexSearcher
All Implemented Interfaces:
Closeable, SolrInfoMBean

public class SolrIndexSearcher
extends IndexSearcher
implements Closeable, SolrInfoMBean

SolrIndexSearcher adds schema awareness and caching functionality over the lucene IndexSearcher.

Since:
solr 0.9

Nested Class Summary
static class SolrIndexSearcher.DocsEnumState
           
static class SolrIndexSearcher.ProcessedFilter
           
static class SolrIndexSearcher.QueryCommand
          A query request command to avoid having to change the method signatures if we want to pass additional information to the searcher.
static class SolrIndexSearcher.QueryResult
          The result of a search.
 
Nested classes/interfaces inherited from class org.apache.lucene.search.IndexSearcher
IndexSearcher.LeafSlice
 
Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoMBean
SolrInfoMBean.Category
 
Field Summary
 boolean enableLazyFieldLoading
           
static int GET_DOCLIST
           
static int GET_DOCSET
           
static int GET_SCORES
           
static AtomicLong numCloses
           
static AtomicLong numOpens
           
static int TERMINATE_EARLY
           
 
Fields inherited from class org.apache.lucene.search.IndexSearcher
leafContexts, leafSlices, readerContext
 
Constructor Summary
SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, SolrIndexConfig config, String name, boolean enableCache, DirectoryFactory directoryFactory)
           
SolrIndexSearcher(SolrCore core, String path, IndexSchema schema, SolrIndexConfig config, String name, DirectoryReader r, boolean closeReader, boolean enableCache, boolean reserveDirectory, DirectoryFactory directoryFactory)
           
 
Method Summary
 void cacheDocSet(Query query, DocSet optionalAnswer, boolean mustCache)
          Compute and cache the DocSet that matches a query.
 Object cacheInsert(String cacheName, Object key, Object val)
          insert an entry in a generic cache
 Object cacheLookup(String cacheName, Object key)
          lookup an entry in a generic cache
 void close()
          Free's resources associated with this searcher.
 Document doc(int i)
          Retrieve the Document instance corresponding to the document id.
 Document doc(int i, Set<String> fields)
          Retrieve the Document instance corresponding to the document id.
 void doc(int n, StoredFieldVisitor visitor)
          Visit a document's fields using a StoredFieldVisitor This method does not currently add to the Solr document cache.
 int docFreq(Term term)
           
 Explanation explain(Query query, int doc)
           
 AtomicReader getAtomicReader()
           
 SolrCache getCache(String cacheName)
          return the named generic cache
 SolrInfoMBean.Category getCategory()
          Purpose of this Class
 SolrCore getCore()
           
 String getDescription()
          Simple one or two line description
 DocList getDocList(Query query, DocSet filter, Sort lsort, int offset, int len)
          Returns documents matching both query and filter and sorted by sort.
 DocList getDocList(Query query, List<Query> filterList, Sort lsort, int offset, int len, int flags)
          Returns documents matching both query and the intersection of the filterList, sorted by sort.
 DocList getDocList(Query query, Query filter, Sort lsort, int offset, int len)
          Returns documents matching both query and filter and sorted by sort.
 DocListAndSet getDocListAndSet(Query query, DocSet filter, Sort lsort, int offset, int len)
          Returns documents matching both query and filter and sorted by sort.
 DocListAndSet getDocListAndSet(Query query, DocSet filter, Sort lsort, int offset, int len, int flags)
          Returns documents matching both query and filter and sorted by sort.
 DocListAndSet getDocListAndSet(Query query, List<Query> filterList, Sort lsort, int offset, int len)
          Returns documents matching both query and the intersection of filterList, sorted by sort.
 DocListAndSet getDocListAndSet(Query query, List<Query> filterList, Sort lsort, int offset, int len, int flags)
          Returns documents matching both query and the intersection of filterList, sorted by sort.
 DocListAndSet getDocListAndSet(Query query, Query filter, Sort lsort, int offset, int len)
          Returns documents matching both query and filter and sorted by sort.
 DocListAndSet getDocListAndSet(Query query, Query filter, Sort lsort, int offset, int len, int flags)
          Returns documents matching both query and filter and sorted by sort.
 URL[] getDocs()
          Documentation URL list.
 DocSet getDocSet(List<Query> queries)
          Returns the set of document ids matching all queries.
 DocSet getDocSet(Query query)
          Returns the set of document ids matching a query.
 DocSet getDocSet(Query query, DocSet filter)
          Returns the set of document ids matching both the query and the filter.
 DocSet getDocSet(SolrIndexSearcher.DocsEnumState deState)
          lucene.internal
protected  DocSet getDocSetNC(Query query, DocSet filter)
           
 Collection<String> getFieldNames()
          Returns a collection of all field names the index reader knows about.
 SolrCache<String,UnInvertedField> getFieldValueCache()
          expert: internal API, subject to change
 int getFirstMatch(Term t)
          Returns the first document number containing the term t Returns -1 if no document was found.
 DirectoryReader getIndexReader()
           
 String getName()
          Simple common usage name, e.g.
 long getOpenTime()
           
 String getPath()
           
 SolrIndexSearcher.ProcessedFilter getProcessedFilter(DocSet setFilter, List<Query> queries)
           
 IndexSchema getSchema()
          Direct access to the IndexSchema for use with this searcher
 String getSource()
          CVS Source, SVN Source, etc
 NamedList<Object> getStatistics()
          Any statistics this instance would like to be publicly available via the Solr Administration interface.
 Collection<String> getStoredHighlightFieldNames()
          Returns a collection of the names of all stored fields which can be highlighted the index reader knows about.
 String getVersion()
          Simple common usage version, e.g.
static void initRegenerators(SolrConfig solrConfig)
           
 long lookupId(BytesRef idBytes)
          lookup the docid by the unique key field, and return the id *within* the leaf reader in the low 32 bits, and the index of the leaf reader in the high 32 bits.
 int maxDoc()
           
 int numDocs(DocSet a, SolrIndexSearcher.DocsEnumState deState)
           
 int numDocs(Query a, DocSet b)
          Returns the number of documents that match both a and b.
 int numDocs(Query a, Query b)
          Returns the number of documents that match both a and b.
 Document[] readDocs(DocList ids)
          Takes a list of docs (the doc ids actually), and returns an array of Documents containing all of the stored fields.
 void readDocs(Document[] docs, DocList ids)
          Takes a list of docs (the doc ids actually), and reads them into an array of Documents.
 void readDocs(Document[] docs, DocList ids, Set<String> fields)
          Takes a list of docs (the doc ids actually) and a set of fields to load, and reads them into an array of Documents.
 void register()
          Register sub-objects such as caches
 SolrIndexSearcher.QueryResult search(SolrIndexSearcher.QueryResult qr, SolrIndexSearcher.QueryCommand cmd)
           
protected  void sortDocSet(SolrIndexSearcher.QueryResult qr, SolrIndexSearcher.QueryCommand cmd)
           
 String toString()
           
 void warm(SolrIndexSearcher old)
          Warm this searcher based on an old one (primarily for auto-cache warming).
 Sort weightSort(Sort sort)
          Returns a weighted sort according to this searcher
 
Methods inherited from class org.apache.lucene.search.IndexSearcher
collectionStatistics, createNormalizedWeight, document, explain, getDefaultSimilarity, getSimilarity, getTopReaderContext, rewrite, search, search, search, search, search, search, search, search, search, search, search, search, search, searchAfter, searchAfter, searchAfter, searchAfter, searchAfter, setSimilarity, slices, termStatistics, wrapFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numOpens

public static final AtomicLong numOpens

numCloses

public static final AtomicLong numCloses

enableLazyFieldLoading

public final boolean enableLazyFieldLoading

GET_DOCSET

public static final int GET_DOCSET
See Also:
Constant Field Values

TERMINATE_EARLY

public static final int TERMINATE_EARLY
See Also:
Constant Field Values

GET_DOCLIST

public static final int GET_DOCLIST
See Also:
Constant Field Values

GET_SCORES

public static final int GET_SCORES
See Also:
Constant Field Values
Constructor Detail

SolrIndexSearcher

public SolrIndexSearcher(SolrCore core,
                         String path,
                         IndexSchema schema,
                         SolrIndexConfig config,
                         String name,
                         boolean enableCache,
                         DirectoryFactory directoryFactory)
                  throws IOException
Throws:
IOException

SolrIndexSearcher

public SolrIndexSearcher(SolrCore core,
                         String path,
                         IndexSchema schema,
                         SolrIndexConfig config,
                         String name,
                         DirectoryReader r,
                         boolean closeReader,
                         boolean enableCache,
                         boolean reserveDirectory,
                         DirectoryFactory directoryFactory)
                  throws IOException
Throws:
IOException
Method Detail

getPath

public String getPath()

toString

public String toString()
Overrides:
toString in class IndexSearcher

getCore

public SolrCore getCore()

maxDoc

public final int maxDoc()

docFreq

public final int docFreq(Term term)
                  throws IOException
Throws:
IOException

getAtomicReader

public final AtomicReader getAtomicReader()

getIndexReader

public final DirectoryReader getIndexReader()
Overrides:
getIndexReader in class IndexSearcher

register

public void register()
Register sub-objects such as caches


close

public void close()
           throws IOException
Free's resources associated with this searcher. In particular, the underlying reader and any cache's in use are closed.

Specified by:
close in interface Closeable
Throws:
IOException

getSchema

public IndexSchema getSchema()
Direct access to the IndexSchema for use with this searcher


getFieldNames

public Collection<String> getFieldNames()
Returns a collection of all field names the index reader knows about.


getStoredHighlightFieldNames

public Collection<String> getStoredHighlightFieldNames()
Returns a collection of the names of all stored fields which can be highlighted the index reader knows about.


initRegenerators

public static void initRegenerators(SolrConfig solrConfig)

search

public SolrIndexSearcher.QueryResult search(SolrIndexSearcher.QueryResult qr,
                                            SolrIndexSearcher.QueryCommand cmd)
                                     throws IOException
Throws:
IOException

doc

public Document doc(int i)
             throws IOException
Retrieve the Document instance corresponding to the document id.

Overrides:
doc in class IndexSearcher
Throws:
IOException

doc

public void doc(int n,
                StoredFieldVisitor visitor)
         throws IOException
Visit a document's fields using a StoredFieldVisitor This method does not currently add to the Solr document cache.

Overrides:
doc in class IndexSearcher
Throws:
IOException
See Also:
IndexReader.document(int, StoredFieldVisitor)

doc

public Document doc(int i,
                    Set<String> fields)
             throws IOException
Retrieve the 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).

Overrides:
doc in class IndexSearcher
Throws:
IOException

readDocs

public void readDocs(Document[] docs,
                     DocList ids)
              throws IOException
Takes a list of docs (the doc ids actually), and reads them into an array of Documents.

Throws:
IOException

readDocs

public void readDocs(Document[] docs,
                     DocList ids,
                     Set<String> fields)
              throws IOException
Takes a list of docs (the doc ids actually) and a set of fields to load, and reads them into an array of Documents.

Throws:
IOException

getFieldValueCache

public SolrCache<String,UnInvertedField> getFieldValueCache()
expert: internal API, subject to change


weightSort

public Sort weightSort(Sort sort)
                throws IOException
Returns a weighted sort according to this searcher

Throws:
IOException

getFirstMatch

public int getFirstMatch(Term t)
                  throws IOException
Returns the first document number containing the term t Returns -1 if no document was found. This method is primarily intended for clients that want to fetch documents using a unique identifier."

Returns:
the first document number containing the term
Throws:
IOException

lookupId

public long lookupId(BytesRef idBytes)
              throws IOException
lookup the docid by the unique key field, and return the id *within* the leaf reader in the low 32 bits, and the index of the leaf reader in the high 32 bits. -1 is returned if not found.

Throws:
IOException
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

cacheDocSet

public void cacheDocSet(Query query,
                        DocSet optionalAnswer,
                        boolean mustCache)
                 throws IOException
Compute and cache the DocSet that matches a query. The normal usage is expected to be cacheDocSet(myQuery, null,false) meaning that Solr will determine if the Query warrants caching, and if so, will compute the DocSet that matches the Query and cache it. If the answer to the query is already cached, nothing further will be done.

If the optionalAnswer DocSet is provided, it should *not* be modified after this call.

Parameters:
query - the lucene query that will act as the key
optionalAnswer - the DocSet to be cached - if null, it will be computed.
mustCache - if true, a best effort will be made to cache this entry. if false, heuristics may be used to determine if it should be cached.
Throws:
IOException

getDocSet

public DocSet getDocSet(Query query)
                 throws IOException
Returns the set of document ids matching a query. This method is cache-aware and attempts to retrieve the answer from the cache if possible. If the answer was not cached, it may have been inserted into the cache as a result of this call. This method can handle negative queries.

The DocSet returned should not be modified.

Throws:
IOException

getDocSet

public DocSet getDocSet(List<Query> queries)
                 throws IOException
Returns the set of document ids matching all queries. This method is cache-aware and attempts to retrieve the answer from the cache if possible. If the answer was not cached, it may have been inserted into the cache as a result of this call. This method can handle negative queries.

The DocSet returned should not be modified.

Throws:
IOException

getProcessedFilter

public SolrIndexSearcher.ProcessedFilter getProcessedFilter(DocSet setFilter,
                                                            List<Query> queries)
                                                     throws IOException
Throws:
IOException

getDocSet

public DocSet getDocSet(SolrIndexSearcher.DocsEnumState deState)
                 throws IOException
lucene.internal

Throws:
IOException

getDocSetNC

protected DocSet getDocSetNC(Query query,
                             DocSet filter)
                      throws IOException
Throws:
IOException

getDocSet

public DocSet getDocSet(Query query,
                        DocSet filter)
                 throws IOException
Returns the set of document ids matching both the query and the filter. This method is cache-aware and attempts to retrieve the answer from the cache if possible. If the answer was not cached, it may have been inserted into the cache as a result of this call.

Parameters:
filter - may be null
Returns:
DocSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException

getDocList

public DocList getDocList(Query query,
                          Query filter,
                          Sort lsort,
                          int offset,
                          int len)
                   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.

Parameters:
filter - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
Returns:
DocList meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocList

public DocList getDocList(Query query,
                          List<Query> filterList,
                          Sort lsort,
                          int offset,
                          int len,
                          int flags)
                   throws IOException
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.

Parameters:
filterList - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
Returns:
DocList meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocList

public DocList getDocList(Query query,
                          DocSet filter,
                          Sort lsort,
                          int offset,
                          int len)
                   throws IOException
Returns documents matching both query and filter and sorted by sort. FUTURE: The returned DocList may be retrieved from a cache.

Parameters:
filter - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
Returns:
DocList meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocListAndSet

public DocListAndSet getDocListAndSet(Query query,
                                      Query filter,
                                      Sort lsort,
                                      int offset,
                                      int len)
                               throws IOException
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.

Parameters:
filter - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
Returns:
DocListAndSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocListAndSet

public DocListAndSet getDocListAndSet(Query query,
                                      Query filter,
                                      Sort lsort,
                                      int offset,
                                      int len,
                                      int flags)
                               throws IOException
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.

Parameters:
filter - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
flags - user supplied flags for the result set
Returns:
DocListAndSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocListAndSet

public DocListAndSet getDocListAndSet(Query query,
                                      List<Query> filterList,
                                      Sort lsort,
                                      int offset,
                                      int len)
                               throws IOException
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.

Parameters:
filterList - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
Returns:
DocListAndSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocListAndSet

public DocListAndSet getDocListAndSet(Query query,
                                      List<Query> filterList,
                                      Sort lsort,
                                      int offset,
                                      int len,
                                      int flags)
                               throws IOException
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.

Parameters:
filterList - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
flags - user supplied flags for the result set
Returns:
DocListAndSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocListAndSet

public DocListAndSet getDocListAndSet(Query query,
                                      DocSet filter,
                                      Sort lsort,
                                      int offset,
                                      int len)
                               throws IOException
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).

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

Parameters:
filter - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
Returns:
DocListAndSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

getDocListAndSet

public DocListAndSet getDocListAndSet(Query query,
                                      DocSet filter,
                                      Sort lsort,
                                      int offset,
                                      int len,
                                      int flags)
                               throws IOException
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 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.

Parameters:
filter - may be null
lsort - criteria by which to sort (if null, query relevance is used)
offset - offset into the list of documents to return
len - maximum number of documents to return
flags - user supplied flags for the result set
Returns:
DocListAndSet meeting the specified criteria, should not be modified by the caller.
Throws:
IOException - If there is a low-level I/O error.

sortDocSet

protected void sortDocSet(SolrIndexSearcher.QueryResult qr,
                          SolrIndexSearcher.QueryCommand cmd)
                   throws IOException
Throws:
IOException

numDocs

public int numDocs(Query a,
                   DocSet b)
            throws IOException
Returns the number of documents that match both a and b.

This method is cache-aware and may check as well as modify the cache.

Returns:
the number of documents in the intersection between a and b.
Throws:
IOException - If there is a low-level I/O error.

numDocs

public int numDocs(DocSet a,
                   SolrIndexSearcher.DocsEnumState deState)
            throws IOException
Throws:
IOException
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

numDocs

public int numDocs(Query a,
                   Query b)
            throws IOException
Returns the number of documents that match both a and b.

This method is cache-aware and may check as well as modify the cache.

Returns:
the number of documents in the intersection between a and b.
Throws:
IOException - If there is a low-level I/O error.

readDocs

public Document[] readDocs(DocList ids)
                    throws IOException
Takes a list of docs (the doc ids actually), and returns an array of Documents containing all of the stored fields.

Throws:
IOException

warm

public void warm(SolrIndexSearcher old)
          throws IOException
Warm this searcher based on an old one (primarily for auto-cache warming).

Throws:
IOException

getCache

public SolrCache getCache(String cacheName)
return the named generic cache


cacheLookup

public Object cacheLookup(String cacheName,
                          Object key)
lookup an entry in a generic cache


cacheInsert

public Object cacheInsert(String cacheName,
                          Object key,
                          Object val)
insert an entry in a generic cache


getOpenTime

public long getOpenTime()

explain

public Explanation explain(Query query,
                           int doc)
                    throws IOException
Overrides:
explain in class IndexSearcher
Throws:
IOException

getName

public String getName()
Description copied from interface: SolrInfoMBean
Simple common usage name, e.g. BasicQueryHandler, or fully qualified clas name.

Specified by:
getName in interface SolrInfoMBean

getVersion

public String getVersion()
Description copied from interface: SolrInfoMBean
Simple common usage version, e.g. 2.0

Specified by:
getVersion in interface SolrInfoMBean

getDescription

public String getDescription()
Description copied from interface: SolrInfoMBean
Simple one or two line description

Specified by:
getDescription in interface SolrInfoMBean

getCategory

public SolrInfoMBean.Category getCategory()
Description copied from interface: SolrInfoMBean
Purpose of this Class

Specified by:
getCategory in interface SolrInfoMBean

getSource

public String getSource()
Description copied from interface: SolrInfoMBean
CVS Source, SVN Source, etc

Specified by:
getSource in interface SolrInfoMBean

getDocs

public URL[] getDocs()
Description copied from interface: SolrInfoMBean
Documentation URL list.

Suggested documentation URLs: Homepage for sponsoring project, FAQ on class usage, Design doc for class, Wiki, bug reporting URL, etc...

Specified by:
getDocs in interface SolrInfoMBean

getStatistics

public NamedList<Object> getStatistics()
Description copied from interface: SolrInfoMBean
Any statistics this instance would like to be publicly available via the Solr Administration interface.

Any Object type may be stored in the list, but only the toString() representation will be used.

Specified by:
getStatistics in interface SolrInfoMBean


Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.