edu.mayo.informatics.indexer.api.generators
Class QueryGenerator

java.lang.Object
  extended by edu.mayo.informatics.indexer.api.generators.QueryGenerator

public class QueryGenerator
extends java.lang.Object

This class will generate a query for you to use in searching.

Author:
Dan Armbrust

Constructor Summary
QueryGenerator()
          Constructs a default QueryGenerator, it will use a StandardAnalyzer.
QueryGenerator(org.apache.lucene.analysis.Analyzer analyzer)
          Constructs a QueryGenerator using the given analyzer.
 
Method Summary
 org.apache.lucene.search.Query createQuery(java.lang.String searchString, java.lang.String[] fields)
           
static java.lang.String removeExtraWhiteSpaceCharacters(java.lang.String searchString, java.util.Set whiteSpaceCharsFromAnalyzer)
          Lucene's Query Parser has the following special characters: + - && || !
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Change the analyzer of an index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryGenerator

public QueryGenerator()
Constructs a default QueryGenerator, it will use a StandardAnalyzer.


QueryGenerator

public QueryGenerator(org.apache.lucene.analysis.Analyzer analyzer)
Constructs a QueryGenerator using the given analyzer. If your Analyzer is setup to remove certain characters (like the WhiteSpaceLowerCaseAnalyzer does) or break on additional characters then it will "do the right thing" with the analyzer and the QueryParser for the remove and white space characters.

Parameters:
analyzer - The analyzer to use in construction of the index
Method Detail

createQuery

public org.apache.lucene.search.Query createQuery(java.lang.String searchString,
                                                  java.lang.String[] fields)
                                           throws org.apache.lucene.queryParser.ParseException,
                                                  org.apache.lucene.queryParser.TokenMgrError
Parameters:
searchString - The string to search for. See http://jakarta.apache.org/lucene/docs/queryparsersyntax.html for details on what can be parsed.
fields - What fields of the index to search for this string.
Returns:
An indexer ready query.
Throws:
org.apache.lucene.queryParser.ParseException
org.apache.lucene.queryParser.TokenMgrError

removeExtraWhiteSpaceCharacters

public static java.lang.String removeExtraWhiteSpaceCharacters(java.lang.String searchString,
                                                               java.util.Set whiteSpaceCharsFromAnalyzer)
Lucene's Query Parser has the following special characters: + - && || ! ( ) { } [ ] ^ " ~ * ? : \ If you want to write a query that contains any of these characters, you must escape them (prefix with \) My analyzers also give you the ability to remove characters. If you ask the analyzer to treat characters like ',' as white space, then you should use this method on the search string, to make sure that user queries that contain ',' also treat ',' as white space. If you remove a character like '-' which is also special to the QueryParser, then you need to ensure that the user query has the escape character in front of the '-'. This method will then turn the escape character and the '-' into white space.

Parameters:
searchString - Search string to modify.
whiteSpaceCharsFromAnalyzer - Set of Character objects to remove. Same as used in your Analyzer.

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Change the analyzer of an index. You MUST call this method if you constructed the index with an analyzer of your own. You always must use the same Analyzer as you constructed the index with.

Parameters:
analyzer -

Copyright: (c) 2004-2006 Mayo Foundation for Medical Education and Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the triple-shield Mayo logo are trademarks and service marks of MFMER.