org.openanzo.indexer.lucene
Class LuceneSearch

java.lang.Object
  extended by org.openanzo.indexer.lucene.LuceneSearch
All Implemented Interfaces:
ISearch

public class LuceneSearch
extends java.lang.Object
implements ISearch

Search implementation based on Lucene.

Author:
Wing Yung ( wingyung@us.ibm.com )

Constructor Summary
LuceneSearch()
           
 
Method Summary
 int executeQuery(IQuery query)
          Executes the given query, returning the number of hits.
 java.util.List<IResult> getAllResults()
          Gets all results.
 java.util.List<IResult> getNextResults()
          Gets the next results, at most pageSize results.
 int getNumHits()
          Returns the number of hits for the current search after it has been executed.
 int getPageSize()
          Gets the pageSize for getNextResults().
 java.util.List<IResult> getSpecifiedResults(int startIndex, int numResults)
          Gets the specified range of results.
 boolean hasMoreResults()
          Determine if there are more results.
 void initialize(java.util.Properties properties)
          Initializes the Lucene index.
 void initialize(java.lang.String location)
          Initializes the Lucene index.
 void postQuery()
          Should be called when all results have been obtained.
 void preQuery()
          Should be called before a query is executed.
 void setPageSize(int pageSize)
          Sets the pageSize for getNextResults().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LuceneSearch

public LuceneSearch()
Method Detail

initialize

public void initialize(java.util.Properties properties)
                throws IndexerException
Initializes the Lucene index. Reads the index directory location out of the properties object. The properties object is expected to contain the location of the directory containing the index (org.openanzo.indexer.lucene.indexLocation).

Specified by:
initialize in interface ISearch
Parameters:
properties - configuration properties for this search object
Throws:
IndexerException

initialize

public void initialize(java.lang.String location)
                throws IndexerException
Initializes the Lucene index.

Parameters:
location - the location of the directory containing the index
Throws:
IndexerException

setPageSize

public void setPageSize(int pageSize)
Description copied from interface: ISearch
Sets the pageSize for getNextResults().

Specified by:
setPageSize in interface ISearch
Parameters:
pageSize - maximum number of results returned when getNextResults() is called

getPageSize

public int getPageSize()
Description copied from interface: ISearch
Gets the pageSize for getNextResults().

Specified by:
getPageSize in interface ISearch
Returns:
the pageSize for getNextResults().

getNumHits

public int getNumHits()
Description copied from interface: ISearch
Returns the number of hits for the current search after it has been executed.

Specified by:
getNumHits in interface ISearch
Returns:
the number of hits for the current search

executeQuery

public int executeQuery(IQuery query)
                 throws IndexerException
Description copied from interface: ISearch
Executes the given query, returning the number of hits. Extract the results with getNextResults() or getAllResults().

Specified by:
executeQuery in interface ISearch
Parameters:
query - text of query to run
Returns:
the number of hits in the results
Throws:
IndexerException

hasMoreResults

public boolean hasMoreResults()
Description copied from interface: ISearch
Determine if there are more results.

Specified by:
hasMoreResults in interface ISearch
Returns:
true if there are more results, false otherwise. Fetch additional results with getMoreResults().

getNextResults

public java.util.List<IResult> getNextResults()
                                       throws IndexerException
Description copied from interface: ISearch
Gets the next results, at most pageSize results.

Specified by:
getNextResults in interface ISearch
Returns:
the next results
Throws:
IndexerException

getAllResults

public java.util.List<IResult> getAllResults()
                                      throws IndexerException
Description copied from interface: ISearch
Gets all results.

Specified by:
getAllResults in interface ISearch
Returns:
list of all results.
Throws:
IndexerException

preQuery

public void preQuery()
              throws IndexerException
Description copied from interface: ISearch
Should be called before a query is executed.

Specified by:
preQuery in interface ISearch
Throws:
IndexerException

postQuery

public void postQuery()
               throws IndexerException
Description copied from interface: ISearch
Should be called when all results have been obtained.

Specified by:
postQuery in interface ISearch
Throws:
IndexerException

getSpecifiedResults

public java.util.List<IResult> getSpecifiedResults(int startIndex,
                                                   int numResults)
                                            throws IndexerException
Description copied from interface: ISearch
Gets the specified range of results.

Specified by:
getSpecifiedResults in interface ISearch
Parameters:
startIndex - Index of the first result to fetch
numResults - Number of results to return
Returns:
the specified range of results
Throws:
IndexerException


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.