|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectQueryRequestParser
public class QueryRequestParser
Processes URL parameters into a Lucene query, using a stylesheet to perform the heavy lifting.
Nested Class Summary | |
---|---|
private static class |
QueryRequestParser.QueryEntry
Keeps track of all the queries for a given field |
class |
QueryRequestParser.QueryFormatError
Exception class used to report errors from the query generator. |
Field Summary | |
---|---|
private File |
baseDir
Keeps track of the servlet base directory, used to map relative file paths. |
private Configuration |
config
Configuration object used when building trees (only created if necessary.) |
private static int |
DEFAULT_MAX_SNIPPETS
Default value for maxSnippets, so we can recognize difference between the default and a user-specified value. |
private Vector |
groupSpecs
Accumulated list of grouping specifications |
private QueryRequest |
req
Partially parsed request in progress |
private HashSet |
specifiedGlobalAttrs
Global attributes that were actually specified in the query |
private NodeInfo |
topNode
The top-level source node |
Constructor Summary | |
---|---|
QueryRequestParser()
|
Method Summary | |
---|---|
private Query |
createMultiFieldQuery(EasyNode parent,
String[] fields,
float[] boosts,
SpanQuery[] spanQueries,
Vector<Query> notVec,
int slop,
int maxMetaSnippets,
int maxTextSnippets)
Does the work of creating the guts of a keyword query. |
static Query |
deChunk(Query q)
Ensures that the given query, if it is a span query on the "text" field, is wrapped by a de-chunking query. |
private void |
error(String message)
Convenience function to throw a QueryGenException with the
given message. |
File |
getBaseDir()
Get the base directory from which relative paths are resolved |
Source |
getSource()
Get an XML source suitable for re-creating this query |
private String |
getText(EasyNode el)
Ensures that the element has only a single child node (ignoring attributes), and that it's a text node. |
private boolean |
isWildcardTerm(Term term)
Determines if the term contains a wildcard character ('*' or '?') |
(package private) Query |
makeProxQuery(EasyNode parent,
int slop,
String field,
int maxSnippets)
Generate a proximity query on a field. |
private int |
onceOnlyAttrib(int oldVal,
EasyNode el,
String attribName)
Like parseIntAttrib(), but adds additional processing to ensure that global parameters are only specified once (or if multiple times, that the same value is used each time.) |
private String |
onceOnlyAttrib(String oldVal,
EasyNode el,
String attribName)
Like parseStringAttrib(), but adds additional processing to ensure that global parameters are only specified once (or if multiple times, that the same value is used each time.) |
private String |
onceOnlyPath(String oldVal,
EasyNode el,
String attribName)
Like onceOnlyAttrib(), but also ensures that the given file can actually be resolved as a path that can be read. |
private boolean |
parseBooleanAttrib(EasyNode el,
String attribName)
Locate the named attribute and retrieve its value as an boolean. |
private boolean |
parseBooleanAttrib(EasyNode el,
String attribName,
boolean defaultVal)
Locate the named attribute and retrieve its value as an boolean. |
private boolean |
parseBooleanAttrib(EasyNode el,
String attribName,
boolean useDefault,
boolean defaultVal)
Locate the named attribute and retrieve its value as an boolean. |
(package private) void |
parseFacetSpec(EasyNode el)
Parses a 'facet' element and adds a FacetSpec to the query. |
private String |
parseField(EasyNode el,
String parentField)
If the given element has a 'field' attribute, return its value; otherwise return 'parentField'. |
private float[] |
parseFieldBoosts(EasyNode parent,
String attrName)
Parse a list of field boosts. |
private String[] |
parseFieldNames(EasyNode parent,
String attrName)
Parse a list of field names. |
private float |
parseFloatAttrib(EasyNode el,
String attribName)
Locate the named attribute and retrieve its value as a float. |
private float |
parseFloatAttrib(EasyNode el,
String attribName,
boolean useDefault,
float defaultVal)
Locate the named attribute and retrieve its value as a float. |
private float |
parseFloatAttrib(EasyNode el,
String attribName,
float defaultVal)
Locate the named attribute and retrieve its value as a float. |
private int |
parseIntAttrib(EasyNode el,
String attribName)
Locate the named attribute and retrieve its value as an integer. |
private int |
parseIntAttrib(EasyNode el,
String attribName,
boolean useDefault,
int defaultVal)
Locate the named attribute and retrieve its value as an integer. |
private int |
parseIntAttrib(EasyNode el,
String attribName,
int defaultVal)
Locate the named attribute and retrieve its value as an integer. |
(package private) void |
parseMainAttrib(EasyNode el,
String attrName,
String val)
Parse an attribute on the main query element (or, for backward compatability, on its immediate children.) |
private Query |
parseMoreLike(EasyNode parent,
String field,
int maxSnippets)
Parses a "more like this" query. |
private Query |
parseMultiFieldQuery(EasyNode parent,
String field,
int maxSnippets)
Parse a 'keyword' query, known internally as a multi-field AND. |
private void |
parseOutput(EasyNode main)
Processes the main query node, turning it into a Lucene query. |
private void |
parseOutputTop(EasyNode output)
Processes the output of the generator stylesheet, turning it into a Lucene query. |
private Query |
parseQuery(EasyNode parent,
String field,
int maxSnippets)
Recursively parse a query. |
private Query |
parseQuery2(EasyNode parent,
String name,
String field,
int maxSnippets)
Main work of recursively parsing a query. |
private Query |
parseRange(EasyNode parent,
String field,
int maxSnippets)
Parse a range query. |
QueryRequest |
parseRequest(Source queryDoc,
File baseDir)
Produce a Lucene query from the intermediate format that is normally produced by the formatting stylesheet. |
QueryRequest |
parseRequest(Source queryDoc,
File baseDir,
String defaultIndexPath)
Produce a Lucene query from the intermediate format that is normally produced by the formatting stylesheet. |
private SpanQuery |
parseSectionType(EasyNode parent,
String field,
int maxSnippets)
Parse a 'sectionType' query element, if one is present. |
(package private) void |
parseSpellcheck(EasyNode el)
Parses a 'spellcheck' element and adds a SpellcheckParams to the query. |
private String |
parseStringAttrib(EasyNode el,
String attribName)
Locate the named attribute and retrieve its value as a string. |
private String |
parseStringAttrib(EasyNode el,
String attribName,
boolean useDefault,
String defaultVal)
Locate the named attribute and retrieve its value as a string. |
private String |
parseStringAttrib(EasyNode el,
String attribName,
String defaultVal)
Locate the named attribute and retrieve its value as a string. |
private Term |
parseTerm(EasyNode parent,
String field,
String expectedName)
Parses a 'term' element. |
private SpanQuery |
processSpanJoin(String name,
Vector subVec,
Vector notVec,
int maxSnippets)
Joins a number of span queries together using a span query. |
(package private) SpanQuery |
processSpanNots(SpanQuery query,
Vector notClauses,
int maxSnippets)
If any 'not' clauses are present, this builds a query that filters them out of the main query. |
private Query |
simplifyBooleanQuery(BooleanQuery bq)
Simplify a BooleanQuery that contains other BooleanQuery/ies with the same type of clauses. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private QueryRequest req
private File baseDir
private Configuration config
private NodeInfo topNode
private HashSet specifiedGlobalAttrs
private Vector groupSpecs
private static final int DEFAULT_MAX_SNIPPETS
Constructor Detail |
---|
public QueryRequestParser()
Method Detail |
---|
public QueryRequest parseRequest(Source queryDoc, File baseDir, String defaultIndexPath) throws QueryGenException, QueryRequestParser.QueryFormatError
queryDoc
- A document containing the query.
QueryGenException
QueryRequestParser.QueryFormatError
public QueryRequest parseRequest(Source queryDoc, File baseDir) throws QueryGenException, QueryRequestParser.QueryFormatError
queryDoc
- A document containing the query.
QueryGenException
QueryRequestParser.QueryFormatError
public Source getSource()
public File getBaseDir()
private void error(String message) throws QueryGenException
QueryGenException
with the
given message.
QueryGenException
private void parseOutputTop(EasyNode output) throws QueryGenException, QueryRequestParser.QueryFormatError
output
- The stylesheet output, whose first (and only) child
should be a 'query' element.
QueryGenException
QueryRequestParser.QueryFormatError
private void parseOutput(EasyNode main)
main
- The 'query' elementvoid parseFacetSpec(EasyNode el)
el
- The 'facet' element to parsevoid parseSpellcheck(EasyNode el)
el
- The 'spellcheck' element to parseprivate Query parseQuery(EasyNode parent, String field, int maxSnippets) throws QueryGenException
QueryGenException
private Query parseQuery2(EasyNode parent, String name, String field, int maxSnippets) throws QueryGenException
QueryGenException
private Query parseMultiFieldQuery(EasyNode parent, String field, int maxSnippets)
private Query createMultiFieldQuery(EasyNode parent, String[] fields, float[] boosts, SpanQuery[] spanQueries, Vector<Query> notVec, int slop, int maxMetaSnippets, int maxTextSnippets)
private Query simplifyBooleanQuery(BooleanQuery bq)
void parseMainAttrib(EasyNode el, String attrName, String val)
private SpanQuery parseSectionType(EasyNode parent, String field, int maxSnippets) throws QueryGenException
QueryGenException
private String parseField(EasyNode el, String parentField) throws QueryGenException
QueryGenException
private SpanQuery processSpanJoin(String name, Vector subVec, Vector notVec, int maxSnippets)
name
- 'and', 'or', 'near', etc.subVec
- Vector of sub-clausesnotVec
- Vector of not clauses (may be empty)
public static Query deChunk(Query q)
private boolean isWildcardTerm(Term term)
private Query parseRange(EasyNode parent, String field, int maxSnippets) throws QueryGenException
QueryGenException
SpanQuery processSpanNots(SpanQuery query, Vector notClauses, int maxSnippets)
Query makeProxQuery(EasyNode parent, int slop, String field, int maxSnippets) throws QueryGenException
parent
- The element containing the field name and terms.
QueryGenException
private Query parseMoreLike(EasyNode parent, String field, int maxSnippets)
private String[] parseFieldNames(EasyNode parent, String attrName)
parent
- Node to look atattrName
- Attribute to get the list from
private float[] parseFieldBoosts(EasyNode parent, String attrName)
parent
- Node to look atattrName
- Attribute to get the list from
private Term parseTerm(EasyNode parent, String field, String expectedName) throws QueryGenException
parent
- The element to parse
QueryGenException
private String getText(EasyNode el) throws QueryGenException
el
- The element to get the text of
QueryGenException
private int onceOnlyAttrib(int oldVal, EasyNode el, String attribName)
oldVal
- Current value of the global parameterel
- Element to get the attribute fromattribName
- Name of the attribute
private String onceOnlyAttrib(String oldVal, EasyNode el, String attribName)
oldVal
- Current value of the global parameterel
- Element to get the attribute fromattribName
- Name of the attribute
private String onceOnlyPath(String oldVal, EasyNode el, String attribName)
oldVal
- Current value of the global parameterel
- Element to get the attribute fromattribName
- Name of the attribute
private int parseIntAttrib(EasyNode el, String attribName) throws QueryGenException
el
- Element to searchattribName
- Attribute to find
QueryGenException
private int parseIntAttrib(EasyNode el, String attribName, int defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finddefaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
private int parseIntAttrib(EasyNode el, String attribName, boolean useDefault, int defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finduseDefault
- true to supply a default value if none found,
false to throw an exception if not found.defaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
private float parseFloatAttrib(EasyNode el, String attribName) throws QueryGenException
el
- Element to searchattribName
- Attribute to find
QueryGenException
private float parseFloatAttrib(EasyNode el, String attribName, float defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finddefaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
private float parseFloatAttrib(EasyNode el, String attribName, boolean useDefault, float defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finduseDefault
- true to supply a default value if none found,
false to throw an exception if not found.defaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
private boolean parseBooleanAttrib(EasyNode el, String attribName) throws QueryGenException
el
- Element to searchattribName
- Attribute to find
QueryGenException
private boolean parseBooleanAttrib(EasyNode el, String attribName, boolean defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finddefaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
private boolean parseBooleanAttrib(EasyNode el, String attribName, boolean useDefault, boolean defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finduseDefault
- true to supply a default value if none found,
false to throw an exception if not found.defaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
private String parseStringAttrib(EasyNode el, String attribName) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to find
QueryGenException
private String parseStringAttrib(EasyNode el, String attribName, String defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finddefaultVal
- If not found, return this value.
QueryGenException
private String parseStringAttrib(EasyNode el, String attribName, boolean useDefault, String defaultVal) throws QueryGenException
el
- EasyNode to searchattribName
- Attribute to finduseDefault
- true to supply a default value if none found,
false to throw an exception if not found.defaultVal
- If not found and useDefault is true, return this
value.
QueryGenException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |