use of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode in project lucene-solr by apache.
the class RemoveEmptyNonLeafQueryNodeProcessor method setChildrenOrder.
@Override
protected List<QueryNode> setChildrenOrder(List<QueryNode> children) throws QueryNodeException {
try {
for (QueryNode child : children) {
if (!child.isLeaf()) {
List<QueryNode> grandChildren = child.getChildren();
if (grandChildren != null && grandChildren.size() > 0) {
this.childrenBuffer.add(child);
}
} else {
this.childrenBuffer.add(child);
}
}
children.clear();
children.addAll(this.childrenBuffer);
} finally {
this.childrenBuffer.clear();
}
return children;
}
use of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode in project lucene-solr by apache.
the class StandardSyntaxParser method TopLevelQuery.
// This makes sure that there is no garbage after the query string
public final QueryNode TopLevelQuery(CharSequence field) throws ParseException {
QueryNode q;
q = Query(field);
jj_consume_token(0);
{
if (true)
return q;
}
throw new Error("Missing return statement in function");
}
use of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode in project lucene-solr by apache.
the class StandardSyntaxParser method ModClause.
// QueryNode Query(CharSequence field) :
// {
// List clauses = new ArrayList();
// List modifiers = new ArrayList();
// QueryNode q, firstQuery=null;
// ModifierQueryNode.Modifier mods;
// int conj;
// }
// {
// mods=Modifiers() q=Clause(field)
// {
// if (mods == ModifierQueryNode.Modifier.MOD_NONE) firstQuery=q;
//
// // do not create modifier nodes with MOD_NONE
// if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
// q = new ModifierQueryNode(q, mods);
// }
// clauses.add(q);
// }
// (
// conj=Conjunction() mods=Modifiers() q=Clause(field)
// {
// // do not create modifier nodes with MOD_NONE
// if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
// q = new ModifierQueryNode(q, mods);
// }
// clauses.add(q);
// //TODO: figure out what to do with AND and ORs
// }
// )*
// {
// if (clauses.size() == 1 && firstQuery != null)
// return firstQuery;
// else {
// return new BooleanQueryNode(clauses);
// }
// }
// }
public final QueryNode ModClause(CharSequence field) throws ParseException {
QueryNode q;
ModifierQueryNode.Modifier mods;
mods = Modifiers();
q = Clause(field);
if (mods != ModifierQueryNode.Modifier.MOD_NONE) {
q = new ModifierQueryNode(q, mods);
}
{
if (true)
return q;
}
throw new Error("Missing return statement in function");
}
use of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode in project lucene-solr by apache.
the class StandardSyntaxParser method Term.
public final QueryNode Term(CharSequence field) throws ParseException {
Token term, boost = null, fuzzySlop = null, goop1, goop2;
boolean fuzzy = false;
boolean regexp = false;
boolean startInc = false;
boolean endInc = false;
QueryNode q = null;
FieldQueryNode qLower, qUpper;
float defaultMinSimilarity = org.apache.lucene.search.FuzzyQuery.defaultMinSimilarity;
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case TERM:
case REGEXPTERM:
case NUMBER:
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case TERM:
term = jj_consume_token(TERM);
q = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), term.beginColumn, term.endColumn);
break;
case REGEXPTERM:
term = jj_consume_token(REGEXPTERM);
regexp = true;
break;
case NUMBER:
term = jj_consume_token(NUMBER);
break;
default:
jj_la1[13] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case FUZZY_SLOP:
fuzzySlop = jj_consume_token(FUZZY_SLOP);
fuzzy = true;
break;
default:
jj_la1[14] = jj_gen;
;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case CARAT:
jj_consume_token(CARAT);
boost = jj_consume_token(NUMBER);
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case FUZZY_SLOP:
fuzzySlop = jj_consume_token(FUZZY_SLOP);
fuzzy = true;
break;
default:
jj_la1[15] = jj_gen;
;
}
break;
default:
jj_la1[16] = jj_gen;
;
}
if (fuzzy) {
float fms = defaultMinSimilarity;
try {
fms = Float.parseFloat(fuzzySlop.image.substring(1));
} catch (Exception ignored) {
}
if (fms < 0.0f) {
{
if (true)
throw new ParseException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX_FUZZY_LIMITS));
}
} else if (fms >= 1.0f && fms != (int) fms) {
{
if (true)
throw new ParseException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX_FUZZY_EDITS));
}
}
q = new FuzzyQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image), fms, term.beginColumn, term.endColumn);
} else if (regexp) {
String re = term.image.substring(1, term.image.length() - 1);
q = new RegexpQueryNode(field, re, 0, re.length());
}
break;
case RANGEIN_START:
case RANGEEX_START:
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case RANGEIN_START:
jj_consume_token(RANGEIN_START);
startInc = true;
break;
case RANGEEX_START:
jj_consume_token(RANGEEX_START);
break;
default:
jj_la1[17] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case RANGE_GOOP:
goop1 = jj_consume_token(RANGE_GOOP);
break;
case RANGE_QUOTED:
goop1 = jj_consume_token(RANGE_QUOTED);
break;
case RANGE_TO:
goop1 = jj_consume_token(RANGE_TO);
break;
default:
jj_la1[18] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(RANGE_TO);
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case RANGE_GOOP:
goop2 = jj_consume_token(RANGE_GOOP);
break;
case RANGE_QUOTED:
goop2 = jj_consume_token(RANGE_QUOTED);
break;
case RANGE_TO:
goop2 = jj_consume_token(RANGE_TO);
break;
default:
jj_la1[19] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case RANGEIN_END:
jj_consume_token(RANGEIN_END);
endInc = true;
break;
case RANGEEX_END:
jj_consume_token(RANGEEX_END);
break;
default:
jj_la1[20] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case CARAT:
jj_consume_token(CARAT);
boost = jj_consume_token(NUMBER);
break;
default:
jj_la1[21] = jj_gen;
;
}
if (goop1.kind == RANGE_QUOTED) {
goop1.image = goop1.image.substring(1, goop1.image.length() - 1);
}
if (goop2.kind == RANGE_QUOTED) {
goop2.image = goop2.image.substring(1, goop2.image.length() - 1);
}
qLower = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(goop1.image), goop1.beginColumn, goop1.endColumn);
qUpper = new FieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(goop2.image), goop2.beginColumn, goop2.endColumn);
q = new TermRangeQueryNode(qLower, qUpper, startInc ? true : false, endInc ? true : false);
break;
case QUOTED:
term = jj_consume_token(QUOTED);
q = new QuotedFieldQueryNode(field, EscapeQuerySyntaxImpl.discardEscapeChar(term.image.substring(1, term.image.length() - 1)), term.beginColumn + 1, term.endColumn - 1);
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case FUZZY_SLOP:
fuzzySlop = jj_consume_token(FUZZY_SLOP);
break;
default:
jj_la1[22] = jj_gen;
;
}
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case CARAT:
jj_consume_token(CARAT);
boost = jj_consume_token(NUMBER);
break;
default:
jj_la1[23] = jj_gen;
;
}
int phraseSlop = 0;
if (fuzzySlop != null) {
try {
phraseSlop = (int) Float.parseFloat(fuzzySlop.image.substring(1));
q = new SlopQueryNode(q, phraseSlop);
} catch (Exception ignored) {
/* Should this be handled somehow? (defaults to "no PhraseSlop", if
* slop number is invalid)
*/
}
}
break;
default:
jj_la1[24] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
if (boost != null) {
float f = (float) 1.0;
try {
f = Float.parseFloat(boost.image);
// avoid boosting null queries, such as those caused by stop words
if (q != null) {
q = new BoostQueryNode(q, f);
}
} catch (Exception ignored) {
/* Should this be handled somehow? (defaults to "no boost", if
* boost number is invalid)
*/
}
}
{
if (true)
return q;
}
throw new Error("Missing return statement in function");
}
use of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode in project lucene-solr by apache.
the class StandardSyntaxParser method DisjQuery.
public final QueryNode DisjQuery(CharSequence field) throws ParseException {
QueryNode first, c;
Vector<QueryNode> clauses = null;
first = ConjQuery(field);
label_2: while (true) {
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case OR:
;
break;
default:
jj_la1[3] = jj_gen;
break label_2;
}
jj_consume_token(OR);
c = ConjQuery(field);
if (clauses == null) {
clauses = new Vector<QueryNode>();
clauses.addElement(first);
}
clauses.addElement(c);
}
if (clauses != null) {
{
if (true)
return new OrQueryNode(clauses);
}
} else {
{
if (true)
return first;
}
}
throw new Error("Missing return statement in function");
}
Aggregations