You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Nicolas Lalevée <ni...@anyware-tech.com> on 2007/11/20 13:55:28 UTC
Custom query parser
Hi,
I am willing to have a query parser which is fault tolerant. I have search
over the archive, and I have found this :
http://www.nabble.com/Error-tolerant-query-parsing-tf108987.html#a300382
I also want my parser to have very simple feature : phrase search and field
search. So I need to develop a simple query parser myself : not that hard, a
simple state machine will be the trick.
But here I loose an important feature of the Lucene query parser : creating
queries regarding an analyzer. In fact I loose that very usefull function :
http://lucene.zones.apache.org:8080/hudson/job/Lucene-Nightly/javadoc/org/apache/lucene/queryParser/QueryParser.html#getFieldQuery(java.lang.String,
%20java.lang.String)
So is there any proper way to create a custom query parser without duplicating
the code ?
cheers,
Nicolas
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Custom query parser
Posted by Mike Klaas <mi...@gmail.com>.
On 22-Nov-07, at 8:49 AM, Nicolas Lalevée wrote:
> Le jeudi 22 novembre 2007, Matthijs Bierman a écrit :
>> Hi Nicolas,
>>
>> Why can't you extend the QueryParser and override the methods you
>> want
>> to modify?
>
> Because the query parser I would like to have is a very basic user
> one, ala
> google. The syntax I would like is nothing more than :
> "type:text OR foo -bar"
> I also don't want the user to be popuped with parsing error, and
> further more,
> even with errors, I don't want to drop the failing terms. A search
> for "bla:foo:bar" should fallback to "bla foo bar".
This is usually best handled by preprocessing the query and
validating it yourself.
> So I have the parser, but it seems, unless I have missed something,
> that I
> have to reimplement (copy and paste) the QueryParser#getFieldQuery
You could override it, call the super method, then if the resulting
query is a PhraseQuery, extract the components and replace the query
with a span query of prefix queries, or somesuch.
-Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Custom query parser
Posted by Nicolas Lalevée <ni...@anyware-tech.com>.
Le jeudi 22 novembre 2007, Matthijs Bierman a écrit :
> Hi Nicolas,
>
> Why can't you extend the QueryParser and override the methods you want
> to modify?
Because the query parser I would like to have is a very basic user one, ala
google. The syntax I would like is nothing more than :
"type:text OR foo -bar"
I also don't want the user to be popuped with parsing error, and further more,
even with errors, I don't want to drop the failing terms. A search
for "bla:foo:bar" should fallback to "bla foo bar".
So I have the parser, but it seems, unless I have missed something, that I
have to reimplement (copy and paste) the QueryParser#getFieldQuery
Nicolas
>
> Cheers,
> Matthijs
>
> Nicolas Lalevée wrote:
> > Hi,
> >
> > I am willing to have a query parser which is fault tolerant. I have
> > search over the archive, and I have found this :
> > http://www.nabble.com/Error-tolerant-query-parsing-tf108987.html#a300382
> >
> > I also want my parser to have very simple feature : phrase search and
> > field search. So I need to develop a simple query parser myself : not
> > that hard, a simple state machine will be the trick.
> >
> > But here I loose an important feature of the Lucene query parser :
> > creating queries regarding an analyzer. In fact I loose that very usefull
> > function :
> > http://lucene.zones.apache.org:8080/hudson/job/Lucene-Nightly/javadoc/org
> >/apache/lucene/queryParser/QueryParser.html#getFieldQuery(java.lang.String
> >, %20java.lang.String)
> >
> > So is there any proper way to create a custom query parser without
> > duplicating the code ?
> >
> > cheers,
> > Nicolas
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
--
Nicolas LALEVÉE
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Custom query parser
Posted by Matthijs Bierman <ma...@impressie.nl>.
Hi Nicolas,
Why can't you extend the QueryParser and override the methods you want
to modify?
Cheers,
Matthijs
Nicolas Lalevée wrote:
> Hi,
>
> I am willing to have a query parser which is fault tolerant. I have search
> over the archive, and I have found this :
> http://www.nabble.com/Error-tolerant-query-parsing-tf108987.html#a300382
>
> I also want my parser to have very simple feature : phrase search and field
> search. So I need to develop a simple query parser myself : not that hard, a
> simple state machine will be the trick.
>
> But here I loose an important feature of the Lucene query parser : creating
> queries regarding an analyzer. In fact I loose that very usefull function :
> http://lucene.zones.apache.org:8080/hudson/job/Lucene-Nightly/javadoc/org/apache/lucene/queryParser/QueryParser.html#getFieldQuery(java.lang.String,
> %20java.lang.String)
>
> So is there any proper way to create a custom query parser without duplicating
> the code ?
>
> cheers,
> Nicolas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org