org.opencms.search
Class CmsSearchCategoryCollector

java.lang.Object
  extended by org.apache.lucene.search.Collector
      extended by org.opencms.search.CmsSearchCategoryCollector

public class CmsSearchCategoryCollector
extends org.apache.lucene.search.Collector

Collects category information during a search process.

Please note: The calculation of the category count slows down the search time by an order of magnitude. Make sure that you only use this feature if it's really required! Be especially careful if your search result list can become large (> 1000 documents), since in this case overall system performance will certainly be impacted considerably when calculating the categories.

Since:
6.0.0

Field Summary
static java.lang.String UNKNOWN_CATEGORY
          Category used in case the document belongs to no category.
 
Constructor Summary
CmsSearchCategoryCollector(org.apache.lucene.search.IndexSearcher searcher)
          Creates a new category search collector instance.
 
Method Summary
 boolean acceptsDocsOutOfOrder()
           
 void collect(int id)
           
static java.lang.String formatCategoryMap(java.util.Map<java.lang.String,java.lang.Integer> categories)
          Convenience method to format a map of categories in a nice 2 column list, for example for display of debugging output.
 java.util.Map<java.lang.String,java.lang.Integer> getCategoryCountResult()
          Returns the category count result, the returned map contains Strings (category names) mapped to an Integer (the count).
 void setNextReader(org.apache.lucene.index.IndexReader reader, int docBase)
           
 void setScorer(org.apache.lucene.search.Scorer arg0)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNKNOWN_CATEGORY

public static final java.lang.String UNKNOWN_CATEGORY
Category used in case the document belongs to no category.

See Also:
Constant Field Values
Constructor Detail

CmsSearchCategoryCollector

public CmsSearchCategoryCollector(org.apache.lucene.search.IndexSearcher searcher)
Creates a new category search collector instance.

Parameters:
searcher - the index searcher used
Method Detail

formatCategoryMap

public static final java.lang.String formatCategoryMap(java.util.Map<java.lang.String,java.lang.Integer> categories)
Convenience method to format a map of categories in a nice 2 column list, for example for display of debugging output.

Parameters:
categories - the map to format
Returns:
the formatted category map

acceptsDocsOutOfOrder

public boolean acceptsDocsOutOfOrder()
Specified by:
acceptsDocsOutOfOrder in class org.apache.lucene.search.Collector
See Also:
Collector.acceptsDocsOutOfOrder()

collect

public void collect(int id)
Specified by:
collect in class org.apache.lucene.search.Collector
See Also:
Collector.collect(int)

getCategoryCountResult

public java.util.Map<java.lang.String,java.lang.Integer> getCategoryCountResult()
Returns the category count result, the returned map contains Strings (category names) mapped to an Integer (the count).

Returns:
the category count result

setNextReader

public void setNextReader(org.apache.lucene.index.IndexReader reader,
                          int docBase)
Specified by:
setNextReader in class org.apache.lucene.search.Collector
See Also:
Collector.setNextReader(org.apache.lucene.index.IndexReader, int)

setScorer

public void setScorer(org.apache.lucene.search.Scorer arg0)
Specified by:
setScorer in class org.apache.lucene.search.Collector
See Also:
Collector.setScorer(org.apache.lucene.search.Scorer)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()