| *** QueryParser.jj.org Mon Dec 22 11:47:30 2003 |
| --- QueryParser.jj Mon Dec 22 13:20:57 2003 |
| *************** |
| *** 233,255 **** |
| |
| protected void addClause(Vector clauses, int conj, int mods, Query q) { |
| boolean required, prohibited; |
| ! |
| ! // If this term is introduced by AND, make the preceding term required, |
| // unless it's already prohibited |
| if (conj == CONJ_AND) { |
| ! BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1); |
| ! if (!c.prohibited) |
| ! c.required = true; |
| ! } |
| ! |
| ! if (operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) { |
| ! // If this term is introduced by OR, make the preceding term optional, |
| ! // unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b) |
| ! // notice if the input is a OR b, first term is parsed as required; without |
| ! // this modification a OR b would parsed as +a OR b |
| ! BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1); |
| ! if (!c.prohibited) |
| ! c.required = false; |
| } |
| |
| // We might have been passed a null query; the term might have been |
| --- 233,249 ---- |
| |
| protected void addClause(Vector clauses, int conj, int mods, Query q) { |
| boolean required, prohibited; |
| ! // System.out.println(conj+ " " + mods + " " + q.toString("text")); |
| ! // If this term is introduced by AND, check if the previous term is the |
| ! // first term in this or-group and make that term required, |
| // unless it's already prohibited |
| if (conj == CONJ_AND) { |
| ! Vector clauses2 = (Vector)clauses.elementAt(clauses.size()-1); |
| ! //if ( clauses2.size() == 1 ) { |
| ! BooleanClause c = (BooleanClause) clauses2.elementAt(clauses2.size()-1); |
| ! if (!c.prohibited) |
| ! c.required = true; |
| ! //} |
| } |
| |
| // We might have been passed a null query; the term might have been |
| *************** |
| *** 257,277 **** |
| if (q == null) |
| return; |
| |
| if (operator == DEFAULT_OPERATOR_OR) { |
| - // We set REQUIRED if we're introduced by AND or +; PROHIBITED if |
| // introduced by NOT or -; make sure not to set both. |
| prohibited = (mods == MOD_NOT); |
| ! required = (mods == MOD_REQ); |
| ! if (conj == CONJ_AND && !prohibited) { |
| ! required = true; |
| ! } |
| ! } else { |
| ! // We set PROHIBITED if we're introduced by NOT or -; We set REQUIRED |
| ! // if not PROHIBITED and not introduced by OR |
| prohibited = (mods == MOD_NOT); |
| ! required = (!prohibited && conj != CONJ_OR); |
| } |
| ! clauses.addElement(new BooleanClause(q, required, prohibited)); |
| } |
| |
| /** |
| --- 251,279 ---- |
| if (q == null) |
| return; |
| |
| + // start new or-group if there's an explit or |
| + if ( conj == CONJ_OR ) { |
| + clauses.addElement(new Vector()); |
| + } |
| + |
| if (operator == DEFAULT_OPERATOR_OR) { |
| // introduced by NOT or -; make sure not to set both. |
| prohibited = (mods == MOD_NOT); |
| ! // for explizit conjunctions: set required to true |
| ! if ( conj == CONJ_AND ) { |
| ! required = true; |
| ! } |
| ! else { |
| ! // default OR -> required only when requested |
| ! required = (mods == MOD_REQ); |
| ! } |
| ! } else { // operator == DEFAULT_OPERATOR_AND |
| ! // We set PROHIBITED if we're introduced by NOT or - |
| prohibited = (mods == MOD_NOT); |
| ! // always REQUIRED unless PROHIBITED |
| ! required = (!prohibited); |
| } |
| ! ((Vector)clauses.elementAt(clauses.size()-1)).addElement(new BooleanClause(q, required, prohibited)); |
| } |
| |
| /** |
| *************** |
| *** 359,369 **** |
| */ |
| protected Query getBooleanQuery(Vector clauses) throws ParseException |
| { |
| ! BooleanQuery query = new BooleanQuery(); |
| ! for (int i = 0; i < clauses.size(); i++) { |
| ! query.add((BooleanClause)clauses.elementAt(i)); |
| ! } |
| ! return query; |
| } |
| |
| /** |
| --- 361,389 ---- |
| */ |
| protected Query getBooleanQuery(Vector clauses) throws ParseException |
| { |
| ! BooleanQuery query = new BooleanQuery(); |
| ! if ( clauses.size() == 1 ) { |
| ! clauses = (Vector)clauses.elementAt(0); |
| ! for (int i = 0; i < clauses.size(); i++) { |
| ! query.add((BooleanClause)clauses.elementAt(i)); |
| ! } |
| ! } |
| ! else { |
| ! for ( int i = 0; i < clauses.size(); i++ ) { |
| ! Vector clauses2 = (Vector)clauses.elementAt(i); |
| ! if ( clauses2.size() == 1 && ((BooleanClause)clauses2.elementAt(0)).prohibited == false ) { |
| ! query.add(new BooleanClause(((BooleanClause)clauses2.elementAt(0)).query, false, false)); |
| ! } |
| ! else if ( clauses2.size() >= 1 ) { |
| ! BooleanQuery query2 = new BooleanQuery(); |
| ! for ( int j = 0; j < clauses2.size(); j++ ) { |
| ! query2.add((BooleanClause)clauses2.elementAt(j)); |
| ! } |
| ! query.add(new BooleanClause(query2, false, false)); |
| ! } |
| ! } |
| ! } |
| ! return query; |
| } |
| |
| /** |
| *************** |
| *** 551,556 **** |
| --- 571,577 ---- |
| Query Query(String field) : |
| { |
| Vector clauses = new Vector(); |
| + clauses.addElement(new Vector()); |
| Query q, firstQuery=null; |
| int conj, mods; |
| } |
| *************** |
| *** 566,572 **** |
| { addClause(clauses, conj, mods, q); } |
| )* |
| { |
| ! if (clauses.size() == 1 && firstQuery != null) |
| return firstQuery; |
| else { |
| return getBooleanQuery(clauses); |
| --- 587,593 ---- |
| { addClause(clauses, conj, mods, q); } |
| )* |
| { |
| ! if (clauses.size() == 1 && ((Vector)clauses.elementAt(0)).size() == 1 && firstQuery != null) |
| return firstQuery; |
| else { |
| return getBooleanQuery(clauses); |