Search for a word NOT followed by another on a Solr query

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Search for a word NOT followed by another on a Solr query

ivan
What i'm trying to do is to only get results for "Leonardo" when is not
followed by "da vinci".
If i have "Leonardo da vinci" in my result is fine as long as i have another
"Leonardo" without "da vinci".

Examples:
"Leonardo foo bar"  OK
"Leonardo da vinci foo bar" KO
"Leonardo foo bar Leonardo da vinci"  OK

I can't seem to find any way to do this using solr queries, because if i do
something like -"Leonardo da vinci" i lose all results where i have both
"Leonardo" and "Leonardo da vinci". I tried using various combinations of
boolean logic but can't get it to work.

Any help?
Thanks



--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Reply | Threaded
Open this post in threaded view
|

RE: Search for a word NOT followed by another on a Solr query

Markus Jelsma-2
You can abuse phrase query for that, q=leonardo AND -"leonardo da vinci" (asuming you have a proper default field set).

Markus

 
 
-----Original message-----

> From:ivan <[hidden email]>
> Sent: Monday 12th February 2018 12:54
> To: [hidden email]
> Subject: Search for a word NOT followed by another on a Solr query
>
> What i'm trying to do is to only get results for "Leonardo" when is not
> followed by "da vinci".
> If i have "Leonardo da vinci" in my result is fine as long as i have another
> "Leonardo" without "da vinci".
>
> Examples:
> "Leonardo foo bar"  OK
> "Leonardo da vinci foo bar" KO
> "Leonardo foo bar Leonardo da vinci"  OK
>
> I can't seem to find any way to do this using solr queries, because if i do
> something like -"Leonardo da vinci" i lose all results where i have both
> "Leonardo" and "Leonardo da vinci". I tried using various combinations of
> boolean logic but can't get it to work.
>
> Any help?
> Thanks
>
>
>
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
>
Reply | Threaded
Open this post in threaded view
|

RE: Search for a word NOT followed by another on a Solr query

ivan
Markus Jelsma-2 wrote
> You can abuse phrase query for that, q=leonardo AND -"leonardo da vinci"
> (asuming you have a proper default field set).
>
> Markus

This way i'm losing results where i have both "Leonardo" and "Leonardo da
vinci in the same field, see example number 3 "Leonardo foo bar Leonardo da
vinci".
I want this case to match and with your query i'm not getting it.



--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Reply | Threaded
Open this post in threaded view
|

Re: Search for a word NOT followed by another on a Solr query

Emir Arnautović
Hi Ivan,
You might be able to use complexphrase query parser to get what you need, you can test something like this:

{!complexphrase df=my_field}”Leonardo -(da Vinci)”

HTH,
Emir
--
Monitoring - Log Management - Alerting - Anomaly Detection
Solr & Elasticsearch Consulting Support Training - http://sematext.com/



> On 12 Feb 2018, at 14:29, ivan <[hidden email]> wrote:
>
> Markus Jelsma-2 wrote
>> You can abuse phrase query for that, q=leonardo AND -"leonardo da vinci"
>> (asuming you have a proper default field set).
>>
>> Markus
>
> This way i'm losing results where i have both "Leonardo" and "Leonardo da
> vinci in the same field, see example number 3 "Leonardo foo bar Leonardo da
> vinci".
> I want this case to match and with your query i'm not getting it.
>
>
>
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html