lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Janssen <jans...@parc.com>
Subject exposing addClause in the query parser?
Date Fri, 27 Oct 2006 15:17:42 GMT
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 a certain common case (one search term without modifiers),
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: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message