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 Vincenzo D'Amore <v....@gmail.com> on 2017/11/04 17:12:41 UTC
match in order
Hi,
I have a field field1 where there are only pairs of terms, for example the
documents
doc1 { field1 : "A B", title : "Hello title 1" }
doc2 { field1 : "A C", title : "Hello title 2" }
doc3 { field1 : "A D", title : "Hello title 3" }
doc4 { field1 : "B D", title : "Hello title 4" }
I have to boost the documents where there is a pair terms in the same order
used in the query:
To be clear, if I the user search four terms: X A B Y
I have to check they are in a field:
X near A, A near B, B near Y:
I've implemented this problem using complexphrase:
bq={!complexphrase inOrder=true df=field1}("X A" OR "A B" OR "B Y")^10
What do you think of this solution? Is there another solution, may be using
a different query parser?
Trying another way, I've also used with surround query parser, but I think,
I was unable to write the query correctly, never matches.
bq={!surround}field1:(W(X, A) OR W(A,B) OR W(B, Y))^10
Not sure if this is the correct syntax, I've also not found enough
documentation that explaining.
Best regards,
Vincenzo
Re: match in order
Posted by Emir Arnautović <em...@sematext.com>.
Hi Vincenco,
Since it is about boosting, you might also take a look at edismax and pf2 and pf3 fields. It also supports slop (ps2 and ps3).
HTH,
Emir
--
Monitoring - Log Management - Alerting - Anomaly Detection
Solr & Elasticsearch Consulting Support Training - http://sematext.com/
> On 5 Nov 2017, at 01:01, Erick Erickson <er...@gmail.com> wrote:
>
> This _particular_ use case might be a good candidate for shingles.
> That filter pairs up tuples into tokens, so your docs would have
> A_B
> A_C
> A_C
> B_D
>
> and the search would be broken up (assuming the appropriate parameters
> to ShingleFilterFacotry) to
> X_A A_B B_Y
> thus would match the specified doc only, assuming default operator of OR.
>
> This wouldn't generalize for slop at all though.
>
> Best,
> Erick
>
> On Sat, Nov 4, 2017 at 12:05 PM, Vincenzo D'Amore <v....@gmail.com> wrote:
>> Thanks Erick.
>>
>> Right, if there is no slop specified it is like have an "exact match". So I can simplify the query in:
>>
>> bq=field1:("X A" OR "A B" OR "B Y")^10
>>
>> I'm struggling to understand if there is any way to split the user query in pairs directly with solr.
>>
>>> On Sat, Nov 4, 2017 at 6:32 PM, Erick Erickson <er...@gmail.com> wrote:
>>> Looks good to me. The only thing I'd mention is that in the example
>>> given, complexprhase query is unnecessary, but only because there's no
>>> "slop" specified. If by "near" you can also mean "within 3 words" or
>>> some such, then you need complexPhraseQuery..
>>>
>>> FWIW,
>>> Erick
>>>
>>> On Sat, Nov 4, 2017 at 10:12 AM, Vincenzo D'Amore <v....@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have a field field1 where there are only pairs of terms, for example the
>>>> documents
>>>>
>>>> doc1 { field1 : "A B", title : "Hello title 1" }
>>>> doc2 { field1 : "A C", title : "Hello title 2" }
>>>> doc3 { field1 : "A D", title : "Hello title 3" }
>>>> doc4 { field1 : "B D", title : "Hello title 4" }
>>>>
>>>> I have to boost the documents where there is a pair terms in the same order
>>>> used in the query:
>>>>
>>>> To be clear, if I the user search four terms: X A B Y
>>>>
>>>> I have to check they are in a field:
>>>>
>>>> X near A, A near B, B near Y:
>>>>
>>>> I've implemented this problem using complexphrase:
>>>>
>>>> bq={!complexphrase inOrder=true df=field1}("X A" OR "A B" OR "B Y")^10
>>>>
>>>> What do you think of this solution? Is there another solution, may be using
>>>> a different query parser?
>>>>
>>>> Trying another way, I've also used with surround query parser, but I think,
>>>> I was unable to write the query correctly, never matches.
>>>>
>>>> bq={!surround}field1:(W(X, A) OR W(A,B) OR W(B, Y))^10
>>>>
>>>> Not sure if this is the correct syntax, I've also not found enough
>>>> documentation that explaining.
>>>>
>>>> Best regards,
>>>> Vincenzo
>>
>>
>>
>> --
>> Vincenzo D'Amore
>> email: v.damore@gmail.com
>> skype: free.dev
>> mobile: +39 349 8513251
Re: match in order
Posted by Erick Erickson <er...@gmail.com>.
This _particular_ use case might be a good candidate for shingles.
That filter pairs up tuples into tokens, so your docs would have
A_B
A_C
A_C
B_D
and the search would be broken up (assuming the appropriate parameters
to ShingleFilterFacotry) to
X_A A_B B_Y
thus would match the specified doc only, assuming default operator of OR.
This wouldn't generalize for slop at all though.
Best,
Erick
On Sat, Nov 4, 2017 at 12:05 PM, Vincenzo D'Amore <v....@gmail.com> wrote:
> Thanks Erick.
>
> Right, if there is no slop specified it is like have an "exact match". So I can simplify the query in:
>
> bq=field1:("X A" OR "A B" OR "B Y")^10
>
> I'm struggling to understand if there is any way to split the user query in pairs directly with solr.
>
>> On Sat, Nov 4, 2017 at 6:32 PM, Erick Erickson <er...@gmail.com> wrote:
>> Looks good to me. The only thing I'd mention is that in the example
>> given, complexprhase query is unnecessary, but only because there's no
>> "slop" specified. If by "near" you can also mean "within 3 words" or
>> some such, then you need complexPhraseQuery..
>>
>> FWIW,
>> Erick
>>
>> On Sat, Nov 4, 2017 at 10:12 AM, Vincenzo D'Amore <v....@gmail.com> wrote:
>> > Hi,
>> >
>> > I have a field field1 where there are only pairs of terms, for example the
>> > documents
>> >
>> > doc1 { field1 : "A B", title : "Hello title 1" }
>> > doc2 { field1 : "A C", title : "Hello title 2" }
>> > doc3 { field1 : "A D", title : "Hello title 3" }
>> > doc4 { field1 : "B D", title : "Hello title 4" }
>> >
>> > I have to boost the documents where there is a pair terms in the same order
>> > used in the query:
>> >
>> > To be clear, if I the user search four terms: X A B Y
>> >
>> > I have to check they are in a field:
>> >
>> > X near A, A near B, B near Y:
>> >
>> > I've implemented this problem using complexphrase:
>> >
>> > bq={!complexphrase inOrder=true df=field1}("X A" OR "A B" OR "B Y")^10
>> >
>> > What do you think of this solution? Is there another solution, may be using
>> > a different query parser?
>> >
>> > Trying another way, I've also used with surround query parser, but I think,
>> > I was unable to write the query correctly, never matches.
>> >
>> > bq={!surround}field1:(W(X, A) OR W(A,B) OR W(B, Y))^10
>> >
>> > Not sure if this is the correct syntax, I've also not found enough
>> > documentation that explaining.
>> >
>> > Best regards,
>> > Vincenzo
>
>
>
> --
> Vincenzo D'Amore
> email: v.damore@gmail.com
> skype: free.dev
> mobile: +39 349 8513251
Re: match in order
Posted by Vincenzo D'Amore <v....@gmail.com>.
Thanks Erick.
Right, if there is no slop specified it is like have an "exact match". So I can simplify the query in:
bq=field1:("X A" OR "A B" OR "B Y")^10
I'm struggling to understand if there is any way to split the user query in pairs directly with solr.
> On Sat, Nov 4, 2017 at 6:32 PM, Erick Erickson <er...@gmail.com> wrote:
> Looks good to me. The only thing I'd mention is that in the example
> given, complexprhase query is unnecessary, but only because there's no
> "slop" specified. If by "near" you can also mean "within 3 words" or
> some such, then you need complexPhraseQuery..
>
> FWIW,
> Erick
>
> On Sat, Nov 4, 2017 at 10:12 AM, Vincenzo D'Amore <v....@gmail.com> wrote:
> > Hi,
> >
> > I have a field field1 where there are only pairs of terms, for example the
> > documents
> >
> > doc1 { field1 : "A B", title : "Hello title 1" }
> > doc2 { field1 : "A C", title : "Hello title 2" }
> > doc3 { field1 : "A D", title : "Hello title 3" }
> > doc4 { field1 : "B D", title : "Hello title 4" }
> >
> > I have to boost the documents where there is a pair terms in the same order
> > used in the query:
> >
> > To be clear, if I the user search four terms: X A B Y
> >
> > I have to check they are in a field:
> >
> > X near A, A near B, B near Y:
> >
> > I've implemented this problem using complexphrase:
> >
> > bq={!complexphrase inOrder=true df=field1}("X A" OR "A B" OR "B Y")^10
> >
> > What do you think of this solution? Is there another solution, may be using
> > a different query parser?
> >
> > Trying another way, I've also used with surround query parser, but I think,
> > I was unable to write the query correctly, never matches.
> >
> > bq={!surround}field1:(W(X, A) OR W(A,B) OR W(B, Y))^10
> >
> > Not sure if this is the correct syntax, I've also not found enough
> > documentation that explaining.
> >
> > Best regards,
> > Vincenzo
--
Vincenzo D'Amore
email: v.damore@gmail.com
skype: free.dev
mobile: +39 349 8513251
Re: match in order
Posted by Erick Erickson <er...@gmail.com>.
Looks good to me. The only thing I'd mention is that in the example
given, complexprhase query is unnecessary, but only because there's no
"slop" specified. If by "near" you can also mean "within 3 words" or
some such, then you need complexPhraseQuery..
FWIW,
Erick
On Sat, Nov 4, 2017 at 10:12 AM, Vincenzo D'Amore <v....@gmail.com> wrote:
> Hi,
>
> I have a field field1 where there are only pairs of terms, for example the
> documents
>
> doc1 { field1 : "A B", title : "Hello title 1" }
> doc2 { field1 : "A C", title : "Hello title 2" }
> doc3 { field1 : "A D", title : "Hello title 3" }
> doc4 { field1 : "B D", title : "Hello title 4" }
>
> I have to boost the documents where there is a pair terms in the same order
> used in the query:
>
> To be clear, if I the user search four terms: X A B Y
>
> I have to check they are in a field:
>
> X near A, A near B, B near Y:
>
> I've implemented this problem using complexphrase:
>
> bq={!complexphrase inOrder=true df=field1}("X A" OR "A B" OR "B Y")^10
>
> What do you think of this solution? Is there another solution, may be using
> a different query parser?
>
> Trying another way, I've also used with surround query parser, but I think,
> I was unable to write the query correctly, never matches.
>
> bq={!surround}field1:(W(X, A) OR W(A,B) OR W(B, Y))^10
>
> Not sure if this is the correct syntax, I've also not found enough
> documentation that explaining.
>
> Best regards,
> Vincenzo