org.weborganic.bastille.flint.helpers
Class IndexMaster

java.lang.Object
  extended by org.weborganic.bastille.flint.helpers.IndexMaster

public final class IndexMaster
extends Object

Centralizes all the indexing and searching function using Flint for one index.

Since:
0.6.0

Constructor Summary
IndexMaster(File directory)
          Sets up the index master using the default Flint configuration.
 
Method Summary
 void clear()
          Clears the content of the wrapped index.
 IndexConfig config()
          Returns the index config this class operates on.
 Facet getFacet(String field, int upTo, Query query)
          Returns the list of term and how frequently they are used by performing a fuzzy match on the specified term.
 SearchResults getSuggestions(List<String> fields, List<String> texts, int max, String predicate)
          Suggests results for the given fields and text.
 IndexReader grabReader()
          Return an index reader on the index.
 IndexSearcher grabSearcher()
          Return an index searcher on the index.
 Index index()
          Returns the index instance this class operates on.
 void index(File file, Map<String,String> parameters)
          Index the specified file with the given parameters.
 long lastModified()
          Returns the last time an index job was requested or if none was requested the last time the index was updated.
 List<File> list()
          Returns the list of files that have been indexed form the index content.
 List<File> list(Term t)
          Deprecated. This method ignores the term, use list() instead.
 IndexManager manager()
          Returns the underlying Index Manager.
 SearchResults query(SearchQuery query)
          Makes a query to the wrapped index.
 SearchResults query(SearchQuery query, SearchPaging paging)
          Makes a query to the wrapped index.
 void releaseSilently(IndexReader reader)
          Releases this reader for use by other threads silently (any exception will be ignored).
 void releaseSilently(IndexSearcher searcher)
          Releases this searcher for use by other threads silently (any exception will be ignored).
static Query toQuery(String predicate)
          Returns the query for the specified predicate using the Query Parser.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexMaster

public IndexMaster(File directory)
Sets up the index master using the default Flint configuration.

Parameters:
directory - the index directory
Method Detail

index

public Index index()
Returns the index instance this class operates on.

Returns:
the index instance this class operates on.

config

public IndexConfig config()
Returns the index config this class operates on.

Returns:
the index config this class operates on.

manager

public IndexManager manager()
Returns the underlying Index Manager.

Returns:
the underlying Index Manager.

index

public void index(File file,
                  Map<String,String> parameters)
Index the specified file with the given parameters.

Parameters:
file - The file to index.
parameters - The parameters to pass to the stylesheet.

clear

public void clear()
Clears the content of the wrapped index.


query

public SearchResults query(SearchQuery query)
                    throws IndexException
Makes a query to the wrapped index.

Parameters:
query - The query to make
Returns:
The search results
Throws:
IndexException - Should any error while the query is made.

query

public SearchResults query(SearchQuery query,
                           SearchPaging paging)
                    throws IndexException
Makes a query to the wrapped index.

Parameters:
query - The query to make
paging - The paging configuration
Returns:
The search results
Throws:
IndexException - Should any error while the query is made.

lastModified

public long lastModified()
Returns the last time an index job was requested or if none was requested the last time the index was updated.

Returns:
the last time an index job was requested.

getFacet

public Facet getFacet(String field,
                      int upTo,
                      Query query)
               throws IndexException,
                      IOException
Returns the list of term and how frequently they are used by performing a fuzzy match on the specified term.

Parameters:
field - the field to use as a facet
upTo - the max number of values to return
query - a predicate to apply on the facet (can be null or empty)
Returns:
the facte instance.
Throws:
IOException - if there was an error reading the index or creating the condition query
IndexException - if there was an error getting the reader or searcher.

list

@Deprecated
public List<File> list(Term t)
                throws IOException
Deprecated. This method ignores the term, use list() instead.

Returns the list of files that have been indexed form the index content.

Returns:
the list of files that have been indexed form the index content.
Throws:
IOException - if there was an error getting the reader.

list

public List<File> list()
                throws IOException
Returns the list of files that have been indexed form the index content.

Returns:
the list of files that have been indexed form the index content.
Throws:
IOException

getSuggestions

public SearchResults getSuggestions(List<String> fields,
                                    List<String> texts,
                                    int max,
                                    String predicate)
                             throws IOException,
                                    IndexException
Suggests results for the given fields and text.

Parameters:
fields - The list of fields to use.
texts - The list of term texts to use.
max - The maximum number of suggested results.
predicate - By default, assumes that it is the document type.
Returns:
the suggestions in the form of search results.
Throws:
IOException
IndexException

toQuery

public static Query toQuery(String predicate)
                     throws IndexException
Returns the query for the specified predicate using the Query Parser.

Parameters:
predicate - The predicate to parse
Returns:
the corresponding query object or null.
Throws:
IndexException - should any error occur

grabReader

public IndexReader grabReader()
                       throws IndexException
Return an index reader on the index.

Returns:
The index will need to be released.
Throws:
IndexException - If thrown by index manager.

grabSearcher

public IndexSearcher grabSearcher()
                           throws IndexException
Return an index searcher on the index.

Returns:
The index searcher that will need to be released.
Throws:
IndexException - If thrown by index manager.

releaseSilently

public void releaseSilently(IndexReader reader)
Releases this reader for use by other threads silently (any exception will be ignored).

Provided for convenience when used inside a finally block.

Parameters:
reader - The Lucene index reader to release.

releaseSilently

public void releaseSilently(IndexSearcher searcher)
Releases this searcher for use by other threads silently (any exception will be ignored).

Provided for convenience when used inside a finally block.

Parameters:
searcher - The Lucene index searcher to release.