/* (non-Javadoc)
* @see org.apache.jetspeed.search.SearchEngine#search(java.lang.String)
*/
public SearchResults search(String queryString)
{
Searcher searcher = null;
Hits hits = null;
try
{
searcher = new IndexSearcher(rootIndexDir.getPath());
}
catch (IOException e)
{
//logger.error("Failed to create index search using path " + rootDir.getPath());
return null;
}
Analyzer analyzer = newAnalyzer();
String[] searchFields = {ParsedObject.FIELDNAME_CONTENT, ParsedObject.FIELDNAME_DESCRIPTION, ParsedObject.FIELDNAME_FIELDS,
ParsedObject.FIELDNAME_KEY, ParsedObject.FIELDNAME_KEYWORDS, ParsedObject.FIELDNAME_LANGUAGE,
ParsedObject.FIELDNAME_SCORE, ParsedObject.FIELDNAME_TITLE, ParsedObject.FIELDNAME_TYPE,
ParsedObject.FIELDNAME_URL, ParsedObject.FIELDNAME_CLASSNAME};
Query query= null;
try
{
String s[] = new String[searchFields.length];
for(int i=0;i<s.length;i++)
s[i] = queryString;
query = MultiFieldQueryParser.parse(s, searchFields, analyzer);
// Query query = QueryParser.parse(searchString, ParsedObject.FIELDNAME_CONTENT, analyzer);
}
catch (ParseException e)
{
List<ParsedObject> resultList = new ArrayList<ParsedObject>();
SearchResults results = new SearchResultsImpl(resultList);
return results;
}
try
{
hits = searcher.search(query);
}
catch (IOException e)
{
List<ParsedObject> resultList = new ArrayList<ParsedObject>();
SearchResults results = new SearchResultsImpl(resultList);
return results;
}
int hitNum = hits.length();
List<ParsedObject> resultList = new ArrayList<ParsedObject>(hitNum);
for(int i=0; i<hitNum; i++)
{
ParsedObject result = new BaseParsedObject();
try
{
Document doc = hits.doc(i);
addFieldsToParsedObject(doc, result);
result.setScore(hits.score(i));
Field type = doc.getField(ParsedObject.FIELDNAME_TYPE);
if(type != null)
{
result.setType(type.stringValue());
}
Field key = doc.getField(ParsedObject.FIELDNAME_KEY);
if(key != null)
{
result.setKey(key.stringValue());
}
Field description = doc.getField(ParsedObject.FIELDNAME_DESCRIPTION);
if(description != null)
{
result.setDescription(description.stringValue());
}
Field title = doc.getField(ParsedObject.FIELDNAME_TITLE);
if(title != null)
{
result.setTitle(title.stringValue());
}
Field content = doc.getField(ParsedObject.FIELDNAME_CONTENT);
if(content != null)
{
result.setContent(content.stringValue());
}
Field language = doc.getField(ParsedObject.FIELDNAME_LANGUAGE);
if (language != null)
{
result.setLanguage(language.stringValue());
}
Field classname = doc.getField(ParsedObject.FIELDNAME_CLASSNAME);
if (classname != null)
{
result.setClassName(classname.stringValue());
}
Field url = doc.getField(ParsedObject.FIELDNAME_URL);
if (url != null)
{
result.setURL(new URL(url.stringValue()));
}
Field[] keywords = doc.getFields(ParsedObject.FIELDNAME_KEYWORDS);
if(keywords != null)
{
String[] keywordArray = new String[keywords.length];
for(int j=0; j<keywords.length; j++)
{
Field keyword = keywords[j];
keywordArray[j] = keyword.stringValue();
}
result.setKeywords(keywordArray);
}
resultList.add(i, result);
}
catch(IOException e)
{
//logger
}
}
if (searcher != null)
{
try
{
searcher.close();
}
catch (IOException ioe)
{
//logger.error("Closing Searcher", ioe);
}