no.sesat.search.query.parser
Class AbstractQueryParser

java.lang.Object
  extended by no.sesat.search.query.parser.AbstractQueryParser
All Implemented Interfaces:
QueryParser
Direct Known Subclasses:
QueryParserImpl

public abstract class AbstractQueryParser
extends Object
implements QueryParser

Abstract helper for implementing a QueryParser Provides default implementation to get the query object.

Version:
$Id: AbstractQueryParser.java 7225 2009-04-09 00:32:20Z ssmiweve $

Nested Class Summary
 
Nested classes/interfaces inherited from interface no.sesat.search.query.parser.QueryParser
QueryParser.Context
 
Field Summary
protected  QueryParser.Context context
          the context this query parser implementation must work against.
protected static String ERR_EMPTY_CONTEXT
          Error message when the parser tries to parse an empty query string.
protected static Logger LOG
          Protected so an .jj file implementing this class can reuse.
static String OPERATOR_REGEX
           
static String SKIP_REGEX
           
 
Fields inherited from interface no.sesat.search.query.parser.QueryParser
OPERATORS, SKIP_CHARACTER_RANGES
 
Constructor Summary
AbstractQueryParser()
           
 
Method Summary
protected  String balance(String query, char leftChar, char rightChar)
          Ensure that for every leftChar there is a matching rightChar.
protected  QueryParser.Context createContext(String input)
          Create a new context the return the argument on any call to its getQueryString() method.
protected  void enterMethod(String method, Token token)
          Debugging method for tracing a method entry.
protected  String even(String query, char c)
          Ensure that there are a even number of c characters in the phrase, otherwise remove all occurences of c.
protected  void exitMethod()
          Debugging method for tracing a method exit.
protected  String fixFloatingHyphon(String query)
          HACK because a floating hyphon is interpretted as a NotClause.
 Query getQuery()
          Get the query object.
protected  String numberNeedsTrailingSpace(String query)
          HACK because phone numbers and organisation numbers need to finish with a space.
abstract  Clause parse()
          do the actual parsing.
protected abstract  void ReInit(Reader reader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SKIP_REGEX

public static final String SKIP_REGEX

OPERATOR_REGEX

public static final String OPERATOR_REGEX

LOG

protected static final Logger LOG
Protected so an .jj file implementing this class can reuse.


ERR_EMPTY_CONTEXT

protected static final String ERR_EMPTY_CONTEXT
Error message when the parser tries to parse an empty query string.

See Also:
Constant Field Values

context

protected transient QueryParser.Context context
the context this query parser implementation must work against.

Constructor Detail

AbstractQueryParser

public AbstractQueryParser()
Method Detail

parse

public abstract Clause parse()
                      throws ParseException
do the actual parsing. This method shouldn't be public but that's the way javacc creates it unfortunately.

Returns:
the clause hierarchy ready to wrap a Query around.
Throws:
ParseException - when parsing the inputted query string.

getQuery

public Query getQuery()
Get the query object. A call to this method initiates the parse() method if the query hasn't already been built.

Specified by:
getQuery in interface QueryParser
Returns:
the Query object, ready to use.

createContext

protected final QueryParser.Context createContext(String input)
Create a new context the return the argument on any call to its getQueryString() method.

Parameters:
input - the query string returned from the created context's getQueryString() method.
Returns:
new content supplying access to query string "input"

enterMethod

protected final void enterMethod(String method,
                                 Token token)
Debugging method for tracing a method entry.

Parameters:
method - the name of the method

exitMethod

protected final void exitMethod()
Debugging method for tracing a method exit.


balance

protected final String balance(String query,
                               char leftChar,
                               char rightChar)
Ensure that for every leftChar there is a matching rightChar. Otherwise remove all occurences of both leftChar and rightChar.

Parameters:
query -
leftChar -
rightChar -
Returns:

even

protected final String even(String query,
                            char c)
Ensure that there are a even number of c characters in the phrase, otherwise remove all occurences of c.

Parameters:
query -
c - the character to ensure has an even occurence count.
Returns:
unchanged or changes string.

numberNeedsTrailingSpace

protected final String numberNeedsTrailingSpace(String query)
HACK because phone numbers and organisation numbers need to finish with a space. SEARCH-672

Parameters:
query -
Returns:

fixFloatingHyphon

protected final String fixFloatingHyphon(String query)
HACK because a floating hyphon is interpretted as a NotClause. Sesam syntax requires the hyphon to be adjacent, without whitespace, to the next term. SEARCH-3390

Parameters:
query -
Returns:

ReInit

protected abstract void ReInit(Reader reader)


Copyright © 2005-2009 Schibsted ASA. All Rights Reserved.