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 superjim <ma...@tevel.info> on 2015/11/17 15:26:26 UTC

search for documents where all words of field present in the query

How would I form a query where all of the words in a field must be present in
the query (but possibly more). For example, if I have the following words in
a text field: "John Smith"

A query for "John" should return no results

A query for "Smith" should return no results

A query for "John Smith" should return that one result

A query for "banana John Smith purple monkey dishwasher" should return that
one result





--
View this message in context: http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: search for documents where all words of field present in the query

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Are you sure your original description is not a reverse of your
use-case? Now, it seems like you just want mm=100 which means
"samsung" will match all entries, but "samsung 32G" will only match 3
of them.

https://wiki.apache.org/solr/DisMaxQParserPlugin#mm_.28Minimum_.27Should.27_Match.29
----
Solr Analyzers, Tokenizers, Filters, URPs and even a newsletter:
http://www.solr-start.com/


On 17 November 2015 at 10:28, superjim <ma...@tevel.info> wrote:
> Thank you so match for answer!
>
> I'm check Luwak solution.
>
> By business case is very common and simple.
>
> 1) user search for products.
> sample real query: smartphone samsung s3 black 32G
>
> 2) i have really big database of products.
> I want return to user all products from my database:
> "Samsung s3 32g BLACK"
> "Samsung s3 BLACK"
> "Samsung s3 32G"
>
> I also have products like (must not be in result!):
> "Smartphone Samsung s5"
> "Samsung s6 black"
> "Samsung s6 32G black"
>
> so i want: ALL PRODUCTS HAS ALL WORDS IN USER QUERY
>
> Are you sure that this is not impossible to do with SOLR?
> I am already using solr for suggestions and it works perfect!
>
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564p4240569.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: search for documents where all words of field present in the query

Posted by superjim <ma...@tevel.info>.
Thank you so match for answer!

I'm check Luwak solution.

By business case is very common and simple.

1) user search for products.
sample real query: smartphone samsung s3 black 32G

2) i have really big database of products.
I want return to user all products from my database:
"Samsung s3 32g BLACK"
"Samsung s3 BLACK"
"Samsung s3 32G"

I also have products like (must not be in result!):
"Smartphone Samsung s5"
"Samsung s6 black"
"Samsung s6 32G black"

so i want: ALL PRODUCTS HAS ALL WORDS IN USER QUERY

Are you sure that this is not impossible to do with SOLR?
I am already using solr for suggestions and it works perfect!





--
View this message in context: http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564p4240569.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: search for documents where all words of field present in the query

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
This sounds more like a use case for https://github.com/flaxsearch/luwak

Or a variation of Ted Sullivan's work:
http://lucidworks.com/blog/author/tedsullivan/

I do not think this can be done in Solr directly. If your matched
fields were always 2-tokens, you could do complex mm param. If the
words in the query always appear in the same order as in the field,
you probably do some sort of auto-phrasing or n-gram matching. But
just as you described - it is unlikely.

Can you explain your business case, maybe there are different ways to
index the data to match the requirements.

Regards,
   Alex.
----
Solr Analyzers, Tokenizers, Filters, URPs and even a newsletter:
http://www.solr-start.com/


On 17 November 2015 at 09:46, superjim <ma...@tevel.info> wrote:
> There the same questions I've found in google:
>
> Solr query must match all words/tokens in a field
> http://stackoverflow.com/questions/10508078/solr-query-must-match-all-words-tokens-in-a-field
>
> Syntax for query where all words in field must be present in query
> http://stackoverflow.com/questions/18390892/syntax-for-query-where-all-words-in-field-must-be-present-in-query
>
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564p4240565.html
> Sent from the Solr - User mailing list archive at Nabble.com.

Re: search for documents where all words of field present in the query

Posted by superjim <ma...@tevel.info>.
There the same questions I've found in google:

Solr query must match all words/tokens in a field
http://stackoverflow.com/questions/10508078/solr-query-must-match-all-words-tokens-in-a-field

Syntax for query where all words in field must be present in query
http://stackoverflow.com/questions/18390892/syntax-for-query-where-all-words-in-field-must-be-present-in-query





--
View this message in context: http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564p4240565.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: search for documents where all words of field present in the query

Posted by Alessandro Benedetti <ab...@apache.org>.
Assuming this is the only, specific kind of search you want, what about
using shingles of tokens at query time and keyword tokenizer at indexing
time ?

Ideally you don't tokenise at indexing time.
At query time you build your shingles ( apparently you need not only
adiacent token shingles, so play a little bit with it and possibly
customise it) .

If you give us more information, maybe we can design a better solution.

Cheers


On 18 November 2015 at 09:02, Ahmet Arslan <io...@yahoo.com.invalid>
wrote:

>
>
> Hi Jim,
>
> I think you could do some magic with function queries.
> https://cwiki.apache.org/confluence/display/solr/Function+Queries
>
>
> Index number of unique words in the product title e.g.
> title = john smith
> length = 2
>
> return products if the number of matching terms equals to the number of
> words in the title.
>
> Perhaps there is a better way but something like below should work in
> theory.
>
> termfreq(title,'john')
> termfreq(title,'smith')
>
> fq={!frange l=0 u=0} sub(length, sum(termfreq(title,'smith'),
> termfreq(title,'smith')))
> Ahmet
>
>
> On Tuesday, November 17, 2015 4:31 PM, superjim <ma...@tevel.info> wrote:
>
>
>
> How would I form a query where all of the words in a field must be present
> in
> the query (but possibly more). For example, if I have the following words
> in
> a text field: "John Smith"
>
> A query for "John" should return no results
>
> A query for "Smith" should return no results
>
> A query for "John Smith" should return that one result
>
> A query for "banana John Smith purple monkey dishwasher" should return that
> one result
>
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>



-- 
--------------------------

Benedetti Alessandro
Visiting card : http://about.me/alessandro_benedetti

"Tyger, tyger burning bright
In the forests of the night,
What immortal hand or eye
Could frame thy fearful symmetry?"

William Blake - Songs of Experience -1794 England

Re: search for documents where all words of field present in the query

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

Hi Jim,

I think you could do some magic with function queries.
https://cwiki.apache.org/confluence/display/solr/Function+Queries


Index number of unique words in the product title e.g.
title = john smith
length = 2

return products if the number of matching terms equals to the number of words in the title.

Perhaps there is a better way but something like below should work in theory.

termfreq(title,'john') 
termfreq(title,'smith')

fq={!frange l=0 u=0} sub(length, sum(termfreq(title,'smith'), termfreq(title,'smith')))
Ahmet


On Tuesday, November 17, 2015 4:31 PM, superjim <ma...@tevel.info> wrote:



How would I form a query where all of the words in a field must be present in
the query (but possibly more). For example, if I have the following words in
a text field: "John Smith"

A query for "John" should return no results

A query for "Smith" should return no results

A query for "John Smith" should return that one result

A query for "banana John Smith purple monkey dishwasher" should return that
one result





--
View this message in context: http://lucene.472066.n3.nabble.com/search-for-documents-where-all-words-of-field-present-in-the-query-tp4240564.html
Sent from the Solr - User mailing list archive at Nabble.com.