Sebastien Lorber
Sebastien Lorber

Reputation: 92130

difference between q=word1 word2 and q="word1 word2" in Solr/Lucene

Can someone please tell me what is the difference between:

q=word1 word2

and

q="word1 word2"

I'm trying to match a keyword "word1 word2" (yes, my keyword can have whitespaces) that is analyzed with KeywordTokenizerFactory and it seems it only works when I add the quotes in the query.

By the way I use Solr extended Dismax, don't know if this matters. The syntax is then:

q="some text"&qf=KeywordField&qf=FrenchtextField

Edit:

The problem I have with quotes is that I have another field that contains fulltexte (analysis is basic and close to FrenchAnalyzer, including a lowercase filter)

I have 'HelloWorld' text indexed, and I can find it back with q=helloWoRLD but not with q="helloWoRLD": this unit test is broken since I added quotes in all my queries. I don't understand what is the difference between q=helloWoRLD and q="helloWoRLD" since it would still be 1 term search right?

Upvotes: 0

Views: 192

Answers (1)

Edd
Edd

Reputation: 8570

Lucene query syntax uses spaces to separate terms so you are performing a search for "word1" in the field "q" and "word2" but with no specified field (I'm not sure how lucene behaves when no field is specified).

  • If you want to search for the string "word1 word2" (consecutive words) in the field q then you will have to use quotes i.e. q="word1 word2"
  • If you want to search for records which contain both of these words (non-consecutive) then you can search for "q=word1 AND q=word2"

I don't quite follow your hello world problem so can't comment on that. Hope this helps

Upvotes: 1

Related Questions