org.compass.core.lucene.util
Class LuceneHelper

java.lang.Object
  extended by org.compass.core.lucene.util.LuceneHelper

public abstract class LuceneHelper
extends Object

Allows to create Compass related objects based on external (internally no supported by Compass) Lucene objects.

Author:
kimchy

Constructor Summary
LuceneHelper()
           
 
Method Summary
static CompassQuery createCompassQuery(Compass compass, Query query)
          Creates a new CompassQuery based on a Lucene Query.
static CompassQuery createCompassQuery(CompassSession session, Query query)
          Creates a new CompassQuery based on a Lucene Query.
static CompassQueryFilter createCompassQueryFilter(CompassSession session, Filter filter)
          Creates a new CompassQueryFilter based on a Lucene Filter.
static String[] findPropertyValues(CompassSession session, String propertyName)
          Returns all the values of for the given propery name.
static Directory getDirectory(Compass compass, String subIndex)
          Returns the lucene Directory associated with the given sub index.
static Document getDocument(Resource resource)
          Returns the actual Lucene Document that the Resource wraps.
static LuceneAnalyzerManager getLuceneAnalyzerManager(Compass compass)
          Returns Compass own internal LuceneAnalyzerManager.
static LuceneSearchEngineInternalSearch getLuceneInternalSearch(CompassSession session)
          Returns the given search engine "internals" used for search.
static LuceneSearchEngineInternalSearch getLuceneInternalSearch(CompassSession session, String[] subIndexes, String[] aliases)
          Returns the given search engine "internals" used for search.
static LuceneSearchEngineHits getLuceneSearchEngineHits(CompassHits hits)
          Returns the underlying LuceneSearchEngineHits of the given CompassHits.
static LuceneSearchEngineQuery getLuceneSearchEngineQuery(CompassQuery query)
          Returns the underlying LuceneSearchEngineQuery of the given CompassQuery.
static LuceneSearchEngineQueryFilter getLuceneSearchEngineQueryFilter(CompassQueryFilter filter)
          Returns the underlying LuceneSearchEngineQueryFilter of the given CompassQueryFilter.
static TermFreqVector getTermFreqVector(CompassSession session, Resource resource, String propertyName)
          Returns Lucene TermFreqVector for the given property and resource, using the session.
static TermFreqVector[] getTermFreqVectors(CompassSession session, Resource resource)
          Returns Lucene TermFreqVector using the given Compass session and Resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LuceneHelper

public LuceneHelper()
Method Detail

createCompassQuery

public static CompassQuery createCompassQuery(Compass compass,
                                              Query query)
Creates a new CompassQuery based on a Lucene Query.

Allows to create CompassQuery based on external Lucene Query that is not supported by one of Compass query builders.

Parameters:
compass - Compass instance
query - The lucene query to wrap
Returns:
A compass query wrapping the lucene query

createCompassQuery

public static CompassQuery createCompassQuery(CompassSession session,
                                              Query query)
Creates a new CompassQuery based on a Lucene Query.

Allows to create CompassQuery based on external Lucene Query that is not supported by one of Compass query builders.

Parameters:
session - Compass session
query - The lucene query to wrap
Returns:
A compass query wrapping the lucene query

getLuceneSearchEngineQuery

public static LuceneSearchEngineQuery getLuceneSearchEngineQuery(CompassQuery query)
Returns the underlying LuceneSearchEngineQuery of the given CompassQuery.

Can be used for example to add custom Sorting using LuceneSearchEngineQuery.addSort(org.apache.lucene.search.SortField), or get the actual lucene query using LuceneSearchEngineQuery.getQuery().

Parameters:
query - The compass query to extract the lucene search engine query from
Returns:
The lucene search engine query extracted from the compass query

createCompassQueryFilter

public static CompassQueryFilter createCompassQueryFilter(CompassSession session,
                                                          Filter filter)
Creates a new CompassQueryFilter based on a Lucene Filter.

Allows to create CompassQueryFilter based on external Lucene Filter that is not supported by one fo Comapss query filter builders.

Parameters:
session - Comapss session
filter - The lucene filter to wrap
Returns:
A compass query filter wrapping lucene query.

getLuceneSearchEngineQueryFilter

public static LuceneSearchEngineQueryFilter getLuceneSearchEngineQueryFilter(CompassQueryFilter filter)
Returns the underlying LuceneSearchEngineQueryFilter of the given CompassQueryFilter.

Can be used to get the actual Lucene Filter using LuceneSearchEngineQueryFilter.getFilter().

Parameters:
filter - The compass query filter to extract the lucene search engine query filter from
Returns:
The lucene search engine query filter extracted from the compass query filter

getLuceneSearchEngineHits

public static LuceneSearchEngineHits getLuceneSearchEngineHits(CompassHits hits)
Returns the underlying LuceneSearchEngineHits of the given CompassHits.

Used mainly to access the actual Lucene Hits, or get Lucene Explanation.


getLuceneAnalyzerManager

public static LuceneAnalyzerManager getLuceneAnalyzerManager(Compass compass)
Returns Compass own internal LuceneAnalyzerManager. Can be used to access Lucene Analyzer at runtime.


getLuceneInternalSearch

public static LuceneSearchEngineInternalSearch getLuceneInternalSearch(CompassSession session)
Returns the given search engine "internals" used for search. For Lucene, returns LuceneSearchEngineInternalSearch which allows to access Lucene IndexReader and Searcher.

The search intenrals will be ones that are executed against the whole index. In order to search on specific aliases or sub indexes, please use getLuceneInternalSearch(org.compass.core.CompassSession,String[],String[]) .

Parameters:
session - A compass session within a transaction
Returns:
Lucene search "internals"

getLuceneInternalSearch

public static LuceneSearchEngineInternalSearch getLuceneInternalSearch(CompassSession session,
                                                                       String[] subIndexes,
                                                                       String[] aliases)
Returns the given search engine "internals" used for search. For Lucene, returns LuceneSearchEngineInternalSearch which allows to access Lucene IndexReader and Searcher.

The search can be narrowed down to specific sub indexes or aliases. A null value means all the sub indexes/aliases.

Parameters:
session - A compass sessino within a transaction
subIndexes - A set of sub indexes to narrow down the index scope
aliases - A set of aliases to narrow down the index scope
Returns:
Lucene search "internals"

getDocument

public static Document getDocument(Resource resource)
Returns the actual Lucene Document that the Resource wraps.

Parameters:
resource - The resource to get the document from
Returns:
The Lucene document that resource wraps

getTermFreqVectors

public static TermFreqVector[] getTermFreqVectors(CompassSession session,
                                                  Resource resource)
                                           throws SearchEngineException
Returns Lucene TermFreqVector using the given Compass session and Resource.

Parameters:
session - Compass session
resource - The resource to get the term freq vector for
Returns:
The term infos freq vector for the given resource
Throws:
SearchEngineException

getTermFreqVector

public static TermFreqVector getTermFreqVector(CompassSession session,
                                               Resource resource,
                                               String propertyName)
                                        throws SearchEngineException
Returns Lucene TermFreqVector for the given property and resource, using the session.

Parameters:
session - Compass session
resource - The resource to get the term freq vector for
propertyName - Theh property name (Lucene field name) to get the term freq vector for
Returns:
Teh term info freq vector for the given resource and property
Throws:
SearchEngineException

getDirectory

public static Directory getDirectory(Compass compass,
                                     String subIndex)
Returns the lucene Directory associated with the given sub index.


findPropertyValues

public static String[] findPropertyValues(CompassSession session,
                                          String propertyName)
                                   throws SearchEngineException
Returns all the values of for the given propery name.

Throws:
SearchEngineException


Copyright (c) 2004-2009 The Compass Project.