Regain 2.1.0-STABLE API

net.sf.regain.search.results
Class SearchResultsImpl

java.lang.Object
  extended by net.sf.regain.search.results.SearchResultsImpl
All Implemented Interfaces:
SearchResults

public class SearchResultsImpl
extends Object
implements SearchResults

Holds the results of a search on a single or multiple indexes. The class uses the new Lucene API (2.9 and later).

Author:
Thomas Tesche: www.thtesche.com

Field Summary
private  org.apache.lucene.search.ScoreDoc[] hitScoreDocs
          The hits of this search.
private  List lazyHitList
          held the transformed hits.
private  org.apache.lucene.analysis.Analyzer mAnalyzer
          The current analyzer
private static java.util.regex.Pattern mimetypeFieldPattern
           
private  IndexConfig mIndexConfig
          The current config.
private  String mIndexName
          The index name.
private  org.apache.lucene.search.IndexSearcher mIndexSearcher
          The searcher (single or multi).
private static org.apache.log4j.Logger mLog
          The logger for this class
private  org.apache.lucene.index.MultiReader mMultiReader
          The reader (multi).
private  org.apache.regexp.RE mOpenInNewWindowRegex
          Der Reguläre Ausdruck, zu dem eine URL passen muss, damit sie in einem neuen Fenster geöffnet wird.
private  org.apache.lucene.search.BooleanQuery mQuery
          The boolean query used while searching and highlighting
private  String mQueryText
          The Query text.
private  int mSearchTime
          The time the search took.
private static java.util.regex.Pattern negativeMimetypeFieldPattern
           
private  org.apache.lucene.search.TopDocsCollector<org.apache.lucene.search.FieldValueHitQueue.Entry> topDocsCollector
          The DocCollector.
 
Constructor Summary
SearchResultsImpl(IndexConfig[] indexConfigs, PageRequest request)
          Creates an instanz of SearchResults.
 
Method Summary
private  org.apache.lucene.search.BooleanQuery getAtomicMimeTypeQuery(String mimeTypeFieldText)
          Helper method for removeMimetypeQuery
 int getDocumentCount()
          Gets the number of documents in the in index.
 int getHitCount()
          Gets the number of hits the search had.
 org.apache.lucene.document.Document getHitDocument(int index)
          Gets the document of one hit.
 String getHitIndexName(int index)
          Gets the name of the index a hit comes from.
 float getHitScore(int index)
          Gets the score of one hit.
 String getHitUrl(int index)
          Gets the url from a hit and rewrites it according to the rewrite rules specified in the index config.
 boolean getOpenHitInNewWindow(int index)
          Gets whether a hit should be opened in a new window.
 String getQueryText()
          Gets the query text of the search.
 int getSearchTime()
          Gets the time the search took in milliseconds.
 boolean getShouldHighlight(int index)
          Gets whether the search terms should be highlighted
 boolean getUseFileToHttpBridgeForHit(int index)
          Gets whether the file-to-http-bridge should be used for a certain hit.
 void highlightHitDocument(int index)
          Highlights fields in the document.
private  String removeMimetypeQuery(String queryText, org.apache.lucene.search.BooleanQuery mainQuery)
          Create a Query from mime type terms and remove them from the query text
private  void setHitDocument(int index, org.apache.lucene.document.Document document)
          Writes a changed document back to the list.
 void shortenSummary(int index)
          Shortens the summary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mIndexSearcher

private org.apache.lucene.search.IndexSearcher mIndexSearcher
The searcher (single or multi).


mMultiReader

private org.apache.lucene.index.MultiReader mMultiReader
The reader (multi).


mQueryText

private String mQueryText
The Query text.


mSearchTime

private int mSearchTime
The time the search took.


mIndexName

private String mIndexName
The index name. In case of an single index it's exactly this name and 'multiindex' in other case.


hitScoreDocs

private org.apache.lucene.search.ScoreDoc[] hitScoreDocs
The hits of this search.


topDocsCollector

private org.apache.lucene.search.TopDocsCollector<org.apache.lucene.search.FieldValueHitQueue.Entry> topDocsCollector
The DocCollector.


mimetypeFieldPattern

private static java.util.regex.Pattern mimetypeFieldPattern

negativeMimetypeFieldPattern

private static java.util.regex.Pattern negativeMimetypeFieldPattern

mOpenInNewWindowRegex

private org.apache.regexp.RE mOpenInNewWindowRegex
Der Reguläre Ausdruck, zu dem eine URL passen muss, damit sie in einem neuen Fenster geöffnet wird.


mQuery

private org.apache.lucene.search.BooleanQuery mQuery
The boolean query used while searching and highlighting


mAnalyzer

private org.apache.lucene.analysis.Analyzer mAnalyzer
The current analyzer


mIndexConfig

private IndexConfig mIndexConfig
The current config.


mLog

private static org.apache.log4j.Logger mLog
The logger for this class


lazyHitList

private List lazyHitList
held the transformed hits.

Constructor Detail

SearchResultsImpl

public SearchResultsImpl(IndexConfig[] indexConfigs,
                         PageRequest request)
                  throws RegainException
Creates an instanz of SearchResults. This class can search over a single or multiple indexes.

Parameters:
indexConfigs - The array of index configs
request - The request parameters
Throws:
RegainException - If searching failed.
Method Detail

removeMimetypeQuery

private String removeMimetypeQuery(String queryText,
                                   org.apache.lucene.search.BooleanQuery mainQuery)
Create a Query from mime type terms and remove them from the query text

Parameters:
queryText - Original query text
mainQuery - MIME clauses that were extracted from the query
Returns:
New query text (old query without the mime clauses)

getAtomicMimeTypeQuery

private org.apache.lucene.search.BooleanQuery getAtomicMimeTypeQuery(String mimeTypeFieldText)
Helper method for removeMimetypeQuery

Parameters:
mimeTypeFieldText - The value of a mime Type
Returns:
The corresponding query

getQueryText

public String getQueryText()
Gets the query text of the search.

Returns:
The query text.

getHitCount

public int getHitCount()
Gets the number of hits the search had.

Specified by:
getHitCount in interface SearchResults
Returns:
the number of hits the search had.

getDocumentCount

public int getDocumentCount()
Gets the number of documents in the in index.

Specified by:
getDocumentCount in interface SearchResults
Returns:
the number of indexed documents.

getHitDocument

public org.apache.lucene.document.Document getHitDocument(int index)
                                                   throws RegainException
Gets the document of one hit. For holding the transformed documents we use a lazy list.

Specified by:
getHitDocument in interface SearchResults
Parameters:
index - The index of the hit.
Returns:
the document of one hit.
Throws:
RegainException - If getting the document failed.
See Also:
Document

setHitDocument

private void setHitDocument(int index,
                            org.apache.lucene.document.Document document)
                     throws RegainException
Writes a changed document back to the list.

Parameters:
index -
document -
Throws:
RegainException

getHitScore

public float getHitScore(int index)
                  throws RegainException
Gets the score of one hit.

Specified by:
getHitScore in interface SearchResults
Parameters:
index - The index of the hit.
Returns:
the score of one hit.
Throws:
RegainException - If getting the score failed.
See Also:
Hits#score(int)

getSearchTime

public int getSearchTime()
Gets the time the search took in milliseconds.

Specified by:
getSearchTime in interface SearchResults
Returns:
The search time.

getOpenHitInNewWindow

public boolean getOpenHitInNewWindow(int index)
                              throws RegainException
Gets whether a hit should be opened in a new window.

Specified by:
getOpenHitInNewWindow in interface SearchResults
Parameters:
index - The index of the hit.
Returns:
Whether the hit should be opened in a new window.
Throws:
RegainException - If getting the URL failed.

getUseFileToHttpBridgeForHit

public boolean getUseFileToHttpBridgeForHit(int index)
Gets whether the file-to-http-bridge should be used for a certain hit.

Mozilla browsers have a security mechanism that blocks loading file-URLs from pages loaded via http. To be able to load files from the search results, regain offers the file-to-http-bridge that provides all files that are listed in the index via http.

Specified by:
getUseFileToHttpBridgeForHit in interface SearchResults
Parameters:
index - The index of the hit.
Returns:
Whether the file-to-http-bridge should be used.

getHitUrl

public String getHitUrl(int index)
                 throws RegainException
Gets the url from a hit and rewrites it according to the rewrite rules specified in the index config.

Specified by:
getHitUrl in interface SearchResults
Parameters:
index - The index of the hit to get the URL for.
Returns:
The url of the wanted hit.
Throws:
RegainException - If getting the hit document failed.

getHitIndexName

public String getHitIndexName(int index)
                       throws RegainException
Gets the name of the index a hit comes from.

Specified by:
getHitIndexName in interface SearchResults
Parameters:
index - The index of the hit to get the index name for.
Returns:
The name of the index a hit comes from.
Throws:
RegainException - If getting the index name failed.

shortenSummary

public void shortenSummary(int index)
                    throws RegainException
Shortens the summary.

Specified by:
shortenSummary in interface SearchResults
Parameters:
index - The index of the hit.
Throws:
RegainException - if shorten fails.

highlightHitDocument

public void highlightHitDocument(int index)
                          throws RegainException
Highlights fields in the document. Fields for highlighting will be: - summary - title

Specified by:
highlightHitDocument in interface SearchResults
Parameters:
index - The index of the hit.
Throws:
RegainException - If highlighting failed.
See Also:
Document

getShouldHighlight

public boolean getShouldHighlight(int index)
                           throws RegainException
Gets whether the search terms should be highlighted

Specified by:
getShouldHighlight in interface SearchResults
Returns:
whether to highlight
Throws:
RegainException - If the value could not read from config

Regain 2.1.0-STABLE API

Regain 2.1.0-STABLE, Copyright (C) 2004-2010 Til Schneider, www.murfman.de, Thomas Tesche, www.clustersystems.info