You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Gastone Penzo <ga...@gmail.com> on 2011/03/24 14:58:39 UTC

invert terms in search with exact match

Hi,
is it possible with standard query search (not dismax) to have
exact matches that allow any terms order?

for example:

if i search "my love" i would solr gives to me docs with

- my love
- love my

it's easy: q=title:(my AND love)

the problem is it returns also docs with

"my love is my dog"

i don't want this. i want only docs with title formed by these 2 terms: my
and love.

is it possible??

thanx

-- 
Gastone Penzo
*www.solr-italia.it*
*The first italian blog about Apache Solr*

Re: invert terms in search with exact match

Posted by Jonathan Rochkind <ro...@jhu.edu>.
You can use query slop as others have said to find documents with "my" 
and "love" right next to each other, in any order. And I think query 
slop can probably work for three or more words too to do that.

But it won't find files with ONLY those words in it. For instance "my 
love"~2 will still match:

love my something else
something my love else
other love my

etc.

Solr isn't so good at doing "exact" matches in general, although there 
are some techniques to set up your index and queries to do actual 
"exact" (entire field) matches -- mostly putting fake tokens like 
"$BEGIN" and "$END" at the beginning and end of your indexed values, and 
then doing a phrase search which puts those tokens at begin and end too.

But I'm not sure if you can extend that technique to find exactly the 
words in _any_ order, instead of just the exact exact phrase. Maybe 
somehow using phrase slop?  It gets confusing to think about, I'm not sure.

On 3/24/2011 10:52 AM, Gastone Penzo wrote:
> no beacuse i don't know the words i want to ignore.. and i don't want use
> dismax.
> i have to use standard handler.
>
> the problem is very simple. i want to recive only documents that have in
> title field ONLY the words i search,
> in any order.
>
> if i search "my love darling", i want solr returns me these possilbe titles:
>
> title1: my love darling
> title2: my darling love
> title3: darling my love
> title4: love my darling
> .....
>
> all the combinations of these 3 words. others words have to be ignored
>
> thanx
>
>
> 2011/3/24 Bill Bell<bi...@gmail.com>
>
>> Yes create qt with dismax and qf on field that has query stopwords for the
>> words you want to ignore.
>>
>> Bill Bell
>> Sent from mobile
>>
>>
>> On Mar 24, 2011, at 7:58 AM, Gastone Penzo<ga...@gmail.com>
>> wrote:
>>
>>> Hi,
>>> is it possible with standard query search (not dismax) to have
>>> exact matches that allow any terms order?
>>>
>>> for example:
>>>
>>> if i search "my love" i would solr gives to me docs with
>>>
>>> - my love
>>> - love my
>>>
>>> it's easy: q=title:(my AND love)
>>>
>>> the problem is it returns also docs with
>>>
>>> "my love is my dog"
>>>
>>> i don't want this. i want only docs with title formed by these 2 terms:
>> my
>>> and love.
>>>
>>> is it possible??
>>>
>>> thanx
>>>
>>> --
>>> Gastone Penzo
>>> *www.solr-italia.it*
>>> *The first italian blog about Apache Solr*
>
>

Re: invert terms in search with exact match

Posted by Ahmet Arslan <io...@yahoo.com>.
Then you need to write some custom code for that. Lucene in Action Book (second edition, section 6.3.4) has an example for Translating PhraseQuery to SpanNearQuery. 

Just use false for the third parameter in SpanNearQuery's ctor.


You can plug https://issues.apache.org/jira/browse/SOLR-1604 too.


> yes sorry i made  a mistake
> 
> title(my AND love AND darling)
> 
> all three words have to match. the problem is always i
> don't want results
> with other words.
> 
> 
> 2011/3/24 Dario Rigolin <da...@comperio.it>
> 
> > On Thursday, March 24, 2011 03:52:31 pm Gastone Penzo
> wrote:
> >
> > >
> > > title1: my love darling
> > > title2: my darling love
> > > title3: darling my love
> > > title4: love my darling
> >
> > Sorry but simply search for:
> >
> >
> >  title:( my OR love OR darling)
> > If you have default operator OR you don't need to put
> OR on the query
> >
> > Best regards.
> > Dario Rigolin
> > Comperio srl (Italy)
> >
> 
> 
> 
> -- 
> Gastone Penzo
> *www.solr-italia.it*
> *The first italian blog about Apache Solr*
> 


      

Re: invert terms in search with exact match

Posted by Gastone Penzo <ga...@gmail.com>.
yes sorry i made  a mistake

title(my AND love AND darling)

all three words have to match. the problem is always i don't want results
with other words.


2011/3/24 Dario Rigolin <da...@comperio.it>

> On Thursday, March 24, 2011 03:52:31 pm Gastone Penzo wrote:
>
> >
> > title1: my love darling
> > title2: my darling love
> > title3: darling my love
> > title4: love my darling
>
> Sorry but simply search for:
>
>
>  title:( my OR love OR darling)
> If you have default operator OR you don't need to put OR on the query
>
> Best regards.
> Dario Rigolin
> Comperio srl (Italy)
>



-- 
Gastone Penzo
*www.solr-italia.it*
*The first italian blog about Apache Solr*

Re: invert terms in search with exact match

Posted by Dario Rigolin <da...@comperio.it>.
On Thursday, March 24, 2011 03:52:31 pm Gastone Penzo wrote:

> 
> title1: my love darling
> title2: my darling love
> title3: darling my love
> title4: love my darling

Sorry but simply search for:


 title:( my OR love OR darling) 
If you have default operator OR you don't need to put OR on the query

Best regards.
Dario Rigolin
Comperio srl (Italy)

Re: invert terms in search with exact match

Posted by Gastone Penzo <ga...@gmail.com>.
no beacuse i don't know the words i want to ignore.. and i don't want use
dismax.
i have to use standard handler.

the problem is very simple. i want to recive only documents that have in
title field ONLY the words i search,
in any order.

if i search "my love darling", i want solr returns me these possilbe titles:

title1: my love darling
title2: my darling love
title3: darling my love
title4: love my darling
.....

all the combinations of these 3 words. others words have to be ignored

thanx


2011/3/24 Bill Bell <bi...@gmail.com>

> Yes create qt with dismax and qf on field that has query stopwords for the
> words you want to ignore.
>
> Bill Bell
> Sent from mobile
>
>
> On Mar 24, 2011, at 7:58 AM, Gastone Penzo <ga...@gmail.com>
> wrote:
>
> > Hi,
> > is it possible with standard query search (not dismax) to have
> > exact matches that allow any terms order?
> >
> > for example:
> >
> > if i search "my love" i would solr gives to me docs with
> >
> > - my love
> > - love my
> >
> > it's easy: q=title:(my AND love)
> >
> > the problem is it returns also docs with
> >
> > "my love is my dog"
> >
> > i don't want this. i want only docs with title formed by these 2 terms:
> my
> > and love.
> >
> > is it possible??
> >
> > thanx
> >
> > --
> > Gastone Penzo
> > *www.solr-italia.it*
> > *The first italian blog about Apache Solr*
>



-- 
Gastone Penzo
*www.solr-italia.it*
*The first italian blog about Apache Solr*

Re: invert terms in search with exact match

Posted by Bill Bell <bi...@gmail.com>.
Yes create qt with dismax and qf on field that has query stopwords for the words you want to ignore.

Bill Bell
Sent from mobile


On Mar 24, 2011, at 7:58 AM, Gastone Penzo <ga...@gmail.com> wrote:

> Hi,
> is it possible with standard query search (not dismax) to have
> exact matches that allow any terms order?
> 
> for example:
> 
> if i search "my love" i would solr gives to me docs with
> 
> - my love
> - love my
> 
> it's easy: q=title:(my AND love)
> 
> the problem is it returns also docs with
> 
> "my love is my dog"
> 
> i don't want this. i want only docs with title formed by these 2 terms: my
> and love.
> 
> is it possible??
> 
> thanx
> 
> -- 
> Gastone Penzo
> *www.solr-italia.it*
> *The first italian blog about Apache Solr*

Re: invert terms in search with exact match

Posted by Gastone Penzo <ga...@gmail.com>.
Hi Tommaso,
thank you for the answer but the problem in your solution is that solr
returns to me
also docs with other words. For example:

my love is the world

i want to exclude the other words.
it must give to me only docs with my love or love my. stop

Thank you

2011/3/24 Tommaso Teofili <to...@gmail.com>

> Hi Gastone,
> I think you should use proximity search as described here in Lucene query
> syntax page [1].
> So searching for "my love"~2 should work for your use case.
> Cheers,
> Tommaso
>
> [1] : http://lucene.apache.org/java/2_9_3/queryparsersyntax.html#ProximitySearches
>
> 2011/3/24 Gastone Penzo <ga...@gmail.com>
>
>> Hi,
>> is it possible with standard query search (not dismax) to have
>> exact matches that allow any terms order?
>>
>> for example:
>>
>> if i search "my love" i would solr gives to me docs with
>>
>> - my love
>> - love my
>>
>> it's easy: q=title:(my AND love)
>>
>> the problem is it returns also docs with
>>
>> "my love is my dog"
>>
>> i don't want this. i want only docs with title formed by these 2 terms: my
>> and love.
>>
>> is it possible??
>>
>> thanx
>>
>> --
>> Gastone Penzo
>> *www.solr-italia.it*
>> *The first italian blog about Apache Solr*
>>
>
>


-- 
Gastone Penzo
*www.solr-italia.it*
*The first italian blog about Apache Solr*

Re: invert terms in search with exact match

Posted by Tommaso Teofili <to...@gmail.com>.
Hi Gastone,
I think you should use proximity search as described here in Lucene query
syntax page [1].
So searching for "my love"~2 should work for your use case.
Cheers,
Tommaso

[1] : http://lucene.apache.org/java/2_9_3/queryparsersyntax.html#ProximitySearches

2011/3/24 Gastone Penzo <ga...@gmail.com>

> Hi,
> is it possible with standard query search (not dismax) to have
> exact matches that allow any terms order?
>
> for example:
>
> if i search "my love" i would solr gives to me docs with
>
> - my love
> - love my
>
> it's easy: q=title:(my AND love)
>
> the problem is it returns also docs with
>
> "my love is my dog"
>
> i don't want this. i want only docs with title formed by these 2 terms: my
> and love.
>
> is it possible??
>
> thanx
>
> --
> Gastone Penzo
> *www.solr-italia.it*
> *The first italian blog about Apache Solr*
>

Re: invert terms in search with exact match

Posted by Ahmet Arslan <io...@yahoo.com>.

--- On Thu, 3/24/11, Gastone Penzo <ga...@gmail.com> wrote:

> From: Gastone Penzo <ga...@gmail.com>
> Subject: invert terms in search with exact match
> To: solr-user@lucene.apache.org
> Date: Thursday, March 24, 2011, 3:58 PM
> Hi,
> is it possible with standard query search (not dismax) to
> have
> exact matches that allow any terms order?
> 
> for example:
> 
> if i search "my love" i would solr gives to me docs with
> 
> - my love
> - love my
> 
> it's easy: q=title:(my AND love)
> 
> the problem is it returns also docs with
> 
> "my love is my dog"
> 
> i don't want this. i want only docs with title formed by
> these 2 terms: my
> and love.

PhraseQuery has an interesting property. If you don't use slop value (means zero) it is ordered phrase query. However starting from 1, it is un-ordered.

"my love"~1 will somehow satisfy you.  If really want "my love" to be unordered you can try solr-1604.