DLESE Tools
v1.6.0

org.dlese.dpc.schemedit
Class SearchHelper

java.lang.Object
  extended by org.dlese.dpc.schemedit.SearchHelper

public class SearchHelper
extends Object

Class to perform searches and cache the results as well as the query and sort information. Used to provide access to search results from different JSP pages (e.g., search, view).

Author:
Jonathan Ostwald

Constructor Summary
SearchHelper(SimpleLuceneIndex index)
          Constructor for the SearchHelper object
 
Method Summary
 int getCachedRecIndex()
          Gets the cachedRecIndex attribute of the SearchHelper object
 String getCurrentRecId()
          gets the Cached current record id
 int getCurrentRecIndex()
          Return the index of the current record in the searchResults
 List getHits()
          Returns all the searchResults
 List getHits(int start, int length)
          Returns a range of searchResults
 int getIndexOf(String recId)
          gets the index in the searchResults for the record having provided id.
 boolean getIsEmpty()
          Convienence caller of isEmpty for jsp pages.
 int getNumHits()
          Gets the number of searchResult items
 String getRecId(int recIndex)
          Gets the id of the result at specifiec index of search results.
 ResultDoc getResultDoc(String id)
          Gets the ResultDoc for given record id from the index, returning null if a result is not found.
 ResultDocList getResults()
          Returns the current searchResults, doing a fresh search and sort if the index has changed since the searchResults were calculated.
 boolean isEmpty()
          Returns true if there are no searchResults
 ResultDocList search(org.apache.lucene.search.Query query)
          Return the results of search with the provided query, performing new search only if a new query string is provided or if the index has changed since the last search.
 ResultDocList search(org.apache.lucene.search.Query query, Object sortObj)
          Description of the Method
 void setCachedRecIndex(int i)
          Sets the cachedRecIndex attribute of the SearchHelper object
 void setCurrentRecId(String id)
          Sets the currentRecId attribute of the RecordList object
 void setResults(ResultDoc resultDoc)
          Sets the results to the single resultDoc provided
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchHelper

public SearchHelper(SimpleLuceneIndex index)
Constructor for the SearchHelper object

Parameters:
index - NOT YET DOCUMENTED
Method Detail

getResults

public ResultDocList getResults()
Returns the current searchResults, doing a fresh search and sort if the index has changed since the searchResults were calculated.

When do we FORCE a new search?? - during sort (where the sort may have changed, but the index has not, so search would not have otherwise have been performed. NOTE: we could also force search by reseting the lastIndexMod to -1!

RETHINK this logic. why cache anything? why not just return the searchResults or an empty list??

Returns:
The results value

search

public ResultDocList search(org.apache.lucene.search.Query query)
Return the results of search with the provided query, performing new search only if a new query string is provided or if the index has changed since the last search.

Parameters:
query - the lucene Query
Returns:
search results

search

public ResultDocList search(org.apache.lucene.search.Query query,
                            Object sortObj)
Description of the Method

Parameters:
query - Description of the Parameter
sortObj - Description of the Parameter
Returns:
Description of the Return Value

getHits

public List getHits()
Returns all the searchResults

Returns:
The hits value

getHits

public List getHits(int start,
                    int length)
Returns a range of searchResults

Parameters:
start - beginning index
length - length of range
Returns:
List of records from specified starting index

getIndexOf

public int getIndexOf(String recId)
gets the index in the searchResults for the record having provided id.

Parameters:
recId - a record id
Returns:
the index, or -1 if no record is found

isEmpty

public boolean isEmpty()
Returns true if there are no searchResults

Returns:
The empty value

getIsEmpty

public boolean getIsEmpty()
Convienence caller of isEmpty for jsp pages.

Returns:
returns true if there are no search results.

getNumHits

public int getNumHits()
Gets the number of searchResult items

Returns:
The numHits value

getCurrentRecId

public String getCurrentRecId()
gets the Cached current record id

Returns:
The currentRecId value

setCurrentRecId

public void setCurrentRecId(String id)
Sets the currentRecId attribute of the RecordList object

Parameters:
id - The new currentRecId value

getRecId

public String getRecId(int recIndex)
Gets the id of the result at specifiec index of search results.

Parameters:
recIndex - index into search results
Returns:
the id or null if not found

getCurrentRecIndex

public int getCurrentRecIndex()
Return the index of the current record in the searchResults

Returns:
The currentRecIndex value

getCachedRecIndex

public int getCachedRecIndex()
Gets the cachedRecIndex attribute of the SearchHelper object

Returns:
The cachedRecIndex value

setCachedRecIndex

public void setCachedRecIndex(int i)
Sets the cachedRecIndex attribute of the SearchHelper object

Parameters:
i - The new cachedRecIndex value

setResults

public void setResults(ResultDoc resultDoc)
Sets the results to the single resultDoc provided

Parameters:
resultDoc - The new results value

getResultDoc

public ResultDoc getResultDoc(String id)
Gets the ResultDoc for given record id from the index, returning null if a result is not found.

If more than one result is found (this should not happen), print a message and return the first result.

Parameters:
id - record ID
Returns:
The resultDoc value or null if resultDoc is not found.

DLESE Tools
v1.6.0