lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tatu Saloranta <>
Subject Re: Keyword search with space and wildcard
Date Wed, 03 Sep 2003 03:02:40 GMT
On Tuesday 02 September 2003 09:04, Brian Campbell wrote:
> Great.  Is there an example anywhere on how I might be able to build such a
> Query?  QueryParser isn't really all that simple since it's built with
> JavaCC.

Well, like Eric mentioned, if you can just ignore JavaCC syntax and look
at embedded Java code, it's not all that complicated (especially you have
done something with yacc/bison, to know how parser generators generally
work)... but granted at first looks bit alien. :-)

Now, I haven't tested this, but I would think that just building single Query 
that searches wild card phrase "some th*" in field "my_field", you'd just do:

Query q = new WildcardQuery(new Term("my_field", "some th*"));

and feed that to whichever search object you need. In this particular case you 
could also use PrefixQuery instead; if so, you need strip out the trailing 
"*" (since that's implied when constructing PrefixQuery).

> What might be ideal for me is if I can continue to use the highlevel
> interface to build the main query (ie use it to parse my query string and
> return me some kind of Query - BooleanQuery, TermQuery, etc) and then build
> a WildcardQuery by hand and "combine" the two together?  For example, is it
> as simple as calling Query.combine() to combine the two?  Is there a better
> way?  Is there a documented example like this?  Thanks!

Eric described the method of combining queries that should work as far as I 
could see. If you do not want to rely on QueryParer to return BooleanQuery, 
you can also just build your your BooleanQuery, and wrap sub-queries as 
BooleanClauses. That's bit more work but should work as well.

Good luck and let us know if that works,

-+ Tatu +-

View raw message