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 tierecke <ni...@gmail.com> on 2007/08/05 02:26:44 UTC

Complex proximity clauses within Lucene QueryParser

Hi,

I got stuck with a complex proximity clause - and would be grateful to get
your help.

Does Lucene allow, and if yes: what is the syntax?

* Proximity between two phrases, for instance a within n1 words from b which
is within n2 words from c?
* subclauses - for instance (a or b) within n words from (b* or c)?
* "a b" within n words from "c d"?

that would help immensely. 

best regards from Amsterdam,
Nir.
-- 
View this message in context: http://www.nabble.com/Complex-proximity-clauses-within-Lucene-QueryParser-tf4218409.html#a12001229
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Complex proximity clauses within Lucene QueryParser

Posted by Mark Miller <ma...@gmail.com>.
Paul Elschot wrote:
> I had a quick look at the sources, and I missed a parser definition file
> in the svn repository. Did I miss it, and when not, could you add it?
>
> As far as qsol syntax goes, here are some suggestions.
> Qsol mostly has binary operators, but with the following
> operators also as prefix a lot more would be possible.
> (Since there is already a prefix form for field searches, a lookahead in the 
> syntax might be needed to avoid ambiguity with such prefix operators.)
>
> Boolean:
> & and | as prefix would allow easier mapping to BooleanQuery,
> and an extra operator for optional clauses (just like ! now) would
> allow all possibilities of BooleanQuery.
>
> Distance:
> operator ~ as prefix would allow multiple arguments to SpanNearQuery,
> and with a single argument this could map to SpanFirstQuery.
>
>
> Actually, with the above additions, qsol seems to be pretty close to
> providing all of lucene in a single query language.
>
> Regards,
> Paul Elschot
>   
http://www.myhardshadow.com/qsolsource/trunk/src/java/com/mhs/qsol/qsol.jtb
It's a jtb file because I am using Java Tree Builder with JavaCC. I left 
out the generated .jj file as it is pretty messy and can be constructed 
with the build script.

I will try and work with your suggestions Paul, thanks for taking a 
look. I had tried some additions like this before without getting too 
far, but certainly worth another shot. I have wanted to get back and 
make some improvements and cleanup anyway. I know the whole parser could 
be a lot better than it is.

Make no mistake, Qsol works great for what I made for (I have some 
personal uses for it), but it could certainly be improved quite a bit. 
It uses a nice infix syntax that I wanted, but overall is not nearly as 
elegant as Surround.

- Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Complex proximity clauses within Lucene QueryParser

Posted by Paul Elschot <pa...@xs4all.nl>.
Nir,

As Erick said, the surround query language does the things requested.
It is in contrib/surround.

Mark,

On Sunday 05 August 2007 06:33, Mark Miller wrote:
> You might check out Qsol: http://myhardshadow.com/qsol.php
> 
> It is my attempt at just such a parser. Some of that logic can be open 
> to a bit of interpretation (spans vs nonspans).

I had a quick look at the sources, and I missed a parser definition file
in the svn repository. Did I miss it, and when not, could you add it?

As far as qsol syntax goes, here are some suggestions.
Qsol mostly has binary operators, but with the following
operators also as prefix a lot more would be possible.
(Since there is already a prefix form for field searches, a lookahead in the 
syntax might be needed to avoid ambiguity with such prefix operators.)

Boolean:
& and | as prefix would allow easier mapping to BooleanQuery,
and an extra operator for optional clauses (just like ! now) would
allow all possibilities of BooleanQuery.

Distance:
operator ~ as prefix would allow multiple arguments to SpanNearQuery,
and with a single argument this could map to SpanFirstQuery.


Actually, with the above additions, qsol seems to be pretty close to
providing all of lucene in a single query language.

Regards,
Paul Elschot


> 
> - Mark
> 
> tierecke wrote:
> > Hi,
> >
> > I got stuck with a complex proximity clause - and would be grateful to get
> > your help.
> >
> > Does Lucene allow, and if yes: what is the syntax?
> >
> > * Proximity between two phrases, for instance a within n1 words from b 
which
> > is within n2 words from c?
> > * subclauses - for instance (a or b) within n words from (b* or c)?
> > * "a b" within n words from "c d"?
> >
> > that would help immensely. 
> >
> > best regards from Amsterdam,
> > Nir.
> >   
> 
> ---------------------------------------------------------------------
> 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


Re: Complex proximity clauses within Lucene QueryParser

Posted by Mark Miller <ma...@gmail.com>.
You might check out Qsol: http://myhardshadow.com/qsol.php

It is my attempt at just such a parser. Some of that logic can be open 
to a bit of interpretation (spans vs nonspans).

- Mark

tierecke wrote:
> Hi,
>
> I got stuck with a complex proximity clause - and would be grateful to get
> your help.
>
> Does Lucene allow, and if yes: what is the syntax?
>
> * Proximity between two phrases, for instance a within n1 words from b which
> is within n2 words from c?
> * subclauses - for instance (a or b) within n words from (b* or c)?
> * "a b" within n words from "c d"?
>
> that would help immensely. 
>
> best regards from Amsterdam,
> Nir.
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Complex proximity clauses within Lucene QueryParser

Posted by Erick Erickson <er...@gmail.com>.
I'm not sure the native syntax supports this idea, but I'm pretty sure
you could construct it yourself with the appropriate SpanQuery
sub-clauses. You'd have to deal with your own parsing of the input
though.

Also, check the SrndQuery class, I'm pretty this will work, but be aware
that it has its own syntax that you have to get accustomed to.

You'll probably need to search the archives for discussions of this. I know
I had a lengthy exchange (see the thread "wildcard and span queries") that
was enlightening.

Best
Erick

On 8/4/07, tierecke <ni...@gmail.com> wrote:
>
>
> Hi,
>
> I got stuck with a complex proximity clause - and would be grateful to get
> your help.
>
> Does Lucene allow, and if yes: what is the syntax?
>
> * Proximity between two phrases, for instance a within n1 words from b
> which
> is within n2 words from c?
> * subclauses - for instance (a or b) within n words from (b* or c)?
> * "a b" within n words from "c d"?
>
> that would help immensely.
>
> best regards from Amsterdam,
> Nir.
> --
> View this message in context:
> http://www.nabble.com/Complex-proximity-clauses-within-Lucene-QueryParser-tf4218409.html#a12001229
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>