I'd like to suggest a minor change in the QueryParser.jj.  I thought
I'd describe it here and get some feedback before posting a patch.

The issue is that I can't get my hands on some clauses (typically
PhraseQuery instances) in my subclass of MultiFieldQueryParser, which
I'd like to do to implement some tricks.  I could do if I could
usefully subclass "addClause", but that breaks for some very specific
instances.  If you look at the code below (from QueryParser.jj), you
see that in certain cases, any work done by addClause() is ignored.

For instances, if you use the search 'foo:"bar"', addClause will be
called, the clauses vector will be updated, but it will then be
ignored.

I'd like to suggest that the pertinent code be re-written to always
use the contents of the clauses vector.  My rewrite is the second
piece of code I've appended here.  As you can see, the function is
smaller and simpler, but returns the same clauses in the un-subclassed
case.  It also lets us override "addClause()" and use it to examine
and possibly modify each clause that's encountered by the parser.

Comments?

Bill
------------------------------------

Current version (from SVN):

Query Query(String field) :
{
  Vector clauses = new Vector();
  Query q, firstQuery=null;
  int conj, mods;
}
{
  mods=Modifiers() q=Clause(field)
  {
    addClause(clauses, CONJ_NONE, mods, q);
    if (mods == MOD_NONE)
        firstQuery=q;
  }
  (
    conj=Conjunction() mods=Modifiers() q=Clause(field)
    { addClause(clauses, conj, mods, q); }
  )*
    {
      if (clauses.size() == 1 && firstQuery != null)
        return firstQuery;
      else {
  return getBooleanQuery(clauses);
      }
    }
}

-----------------------------------

New version:

Query Query(String field) :
{
  Vector clauses = new Vector();
  Query q;
  int conj, mods;
}
{
  mods=Modifiers() q=Clause(field)
  {
    addClause(clauses, CONJ_NONE, mods, q);
  }
  (
    conj=Conjunction() mods=Modifiers() q=Clause(field)
    { addClause(clauses, conj, mods, q); }
  )*
    {
      if (clauses.size() == 1)
        return (Query) (clauses.get(0));
      else {
  return getBooleanQuery(clauses);
      }
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to