public class LuceneSearcher
extends java.lang.Object
implements java.io.Serializable
Note: The routines provided by this class are shared by the Search3 and CD search functions. Any changes made to this class should be tested with both functions.
Note: Because this class is used by the CD search function, it must be included in the cdsearch.jar file that is deployed with each CD batch.
Note: This class should not reference any Flash classes that are not accessible by the CD search function (i.e. not in cdsearch.jar).
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String[] |
cvIndexed_Desc_Fields
Array to hold index field names used in the description query build.
|
protected org.apache.lucene.search.IndexSearcher |
ivIdxSearcher
A reference to the index searcher used to find matching hits.
|
protected java.lang.String |
ivIndexDir
The search index directory.
|
protected boolean |
ivPrefixSearch
Determines if a multi-word search is considered as individual words for
prefix searchs or a phrase search.
|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
LuceneSearcher(java.lang.String indexdir,
boolean prefixSearch)
Constructs a
LuceneSearcher using the specified search index
directory path. |
Modifier and Type | Method and Description |
---|---|
void |
closeSearcher()
Closes the index searcher that was used to find hits for a search.
|
protected java.lang.String[] |
getParsedString(java.lang.String input)
Parses a given
String into an array of strings based on a
space delimiter. |
protected java.lang.String |
getQuerySafeString(java.lang.String s)
Returns a string that has all the Lucene "query unsafe" characters (such
as plus, minus, tilde and double quote) removed from the given string.
|
org.apache.lucene.search.IndexSearcher |
getSearcher()
Returns the current searcher.
|
protected org.apache.lucene.search.Query |
getSearchQuery(java.lang.String searchText,
java.util.ArrayList<java.lang.String[]> searchAttr)
Returns the search query object for the user's entered search criteria.
|
protected org.apache.lucene.search.Query |
getSearchQueryAttr(org.apache.lucene.search.BooleanQuery searchQ,
java.util.ArrayList<java.lang.String[]> searchAttr)
Returns the search query object for the attribute portion of the search.
|
protected boolean |
getSearchQueryAttrJoin(java.util.ArrayList<java.lang.String[]> searchAttr)
Determines how the product attributes are to be joined with the rest of
the search.
|
protected boolean |
getSearchQueryAttrJoin(java.lang.String[] selAttr)
Determines how a selected product attribute is to be joined with the rest
of the search.
|
protected org.apache.lucene.search.Query |
getSearchQueryCode(java.lang.String searchText)
Returns the search query object for the product code portion of the search.
|
protected org.apache.lucene.search.Query |
getSearchQueryDesc(java.lang.String searchText)
Returns the search query object for the description portion of the search.
|
protected org.apache.lucene.search.Query |
getSearchQueryDesc1(java.lang.String word)
Returns the search query object for the description portion of the search
when the entered search string is a single word search.
|
protected org.apache.lucene.search.Query |
getSearchQueryDesc2_Phrase(java.lang.String[] words)
Returns the search query object for the description portion of the search
when the entered search string is a multiple word search and the words
are assumed to be a phrase.
|
protected org.apache.lucene.search.Query |
getSearchQueryDesc2_Prefix(java.lang.String[] words)
Returns the search query object for the description portion of the search
when the entered search string is a multiple word search where each word
is searched as a prefix (i.e.
|
protected org.apache.lucene.search.Query |
getSearchQueryDesc2(java.lang.String[] words)
Returns the search query object for the description portion of the search
when the entered search string is a multiple word search.
|
void |
openSearcher()
Opens the index searcher that is used to find hits for a search.
|
protected java.lang.String |
preprocessIndexData(java.lang.String s)
Looks for and adjusts special situations before a string is indexed.
|
org.apache.lucene.search.TopDocs |
search(java.lang.String searchText,
java.util.ArrayList<java.lang.String[]> searchAttr,
java.lang.String topMostCat,
int maxHits)
Returns the set of hits for the products that match the given set of
search criteria.
|
private static final long serialVersionUID
protected static java.lang.String[] cvIndexed_Desc_Fields
protected java.lang.String ivIndexDir
protected org.apache.lucene.search.IndexSearcher ivIdxSearcher
protected boolean ivPrefixSearch
public LuceneSearcher(java.lang.String indexdir, boolean prefixSearch)
LuceneSearcher
using the specified search index
directory path.indexdir
- (String) The full path to the search index directory.prefixSearch
- (boolean) True if words should be considered a
for prefix searching.public void closeSearcher()
public void openSearcher() throws java.lang.Exception
java.lang.Exception
- - if an error occurs while opening the
search index reader.public org.apache.lucene.search.IndexSearcher getSearcher()
public org.apache.lucene.search.TopDocs search(java.lang.String searchText, java.util.ArrayList<java.lang.String[]> searchAttr, java.lang.String topMostCat, int maxHits) throws java.lang.Exception
searchText
- (String) The entered search string.searchAttr
- (ArrayList) The selected product attributes.maxHits
- (int) The maximum number of matches that should be
returned.java.lang.Exception
- - if an error occurs while performing
the search.protected java.lang.String[] getParsedString(java.lang.String input)
String
into an array of strings based on a
space delimiter.input
- (String) The String
to be parsed.String
array containing the parsed
results.protected java.lang.String getQuerySafeString(java.lang.String s)
s
- (String) The String
to be processed.String
containing the processed results.protected org.apache.lucene.search.Query getSearchQuery(java.lang.String searchText, java.util.ArrayList<java.lang.String[]> searchAttr) throws java.lang.Exception
searchText
- (String) The entered search string.searchAttr
- (ArrayList) The selected product attributes.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryCode(java.lang.String searchText) throws java.lang.Exception
searchText
- (String) The entered search string.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryDesc(java.lang.String searchText) throws java.lang.Exception
searchText
- (String) The entered search string.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryDesc1(java.lang.String word) throws java.lang.Exception
word
- (String) The search word.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryDesc2(java.lang.String[] words) throws java.lang.Exception
words
- (String[]) The search words.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryDesc2_Phrase(java.lang.String[] words) throws java.lang.Exception
words
- (String[]) The search words.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryDesc2_Prefix(java.lang.String[] words) throws java.lang.Exception
words
- (String[]) The search words.java.lang.Exception
- - if an error occurs while creating the
search query object.protected org.apache.lucene.search.Query getSearchQueryAttr(org.apache.lucene.search.BooleanQuery searchQ, java.util.ArrayList<java.lang.String[]> searchAttr) throws java.lang.Exception
searchQ
- (BooleanQuery) The query to which the attribute
portion is to be added.searchAttr
- (ArrayList) The selected product attributes.java.lang.Exception
- - if an error occurs while creating the
search query object.protected boolean getSearchQueryAttrJoin(java.util.ArrayList<java.lang.String[]> searchAttr) throws java.lang.Exception
searchAttr
- (ArrayList) The selected product attributes.true
if the attribute join is "AND",
false
if the attribute join is "OR".java.lang.Exception
- - if an error occurs while determining
the join.protected boolean getSearchQueryAttrJoin(java.lang.String[] selAttr) throws java.lang.Exception
selAttr
- (String[]) A selected product attribute.true
if the attribute join is "AND",
false
if the attribute join is "OR".java.lang.Exception
- - if an error occurs while determining
the join.protected java.lang.String preprocessIndexData(java.lang.String s)
s
- (String) The characters to process.