user13674325
user13674325

Reputation: 389

Search documents by multiple words query in Solr

I have the documents

[
  { "id": 1, "title": "next notebook" },
  { "id": 2, "title": "next thing" }
]

The title field type is

<fieldType name="managed_en" positionIncrementGap="100" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.ManagedStopFilterFactory" managed="english" />
    <filter class="solr.ManagedSynonymGraphFilterFactory" managed="english" />
    <filter class="solr.FlattenGraphFilterFactory"/> <!-- required on index analyzers after graph filters -->
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.ManagedStopFilterFactory" managed="english" />
    <filter class="solr.ManagedSynonymGraphFilterFactory" managed="english" />
  </analyzer>
</fieldType>

And I am trying to search next thing, so the request is /select?q=title%20next%20thing

I expect that document with id: 2 will be on top, but the order is same as they were added, and the score is the same 0.3979403

How should be the query to achieve that if more words from query are in the title, than the document shoud be in the top?

Upvotes: 1

Views: 508

Answers (2)

Gibbs
Gibbs

Reputation: 22974

Your query considered as OR on the default field.

q:next thing

As you mentioned in the comment, you have to specify the field. Otherwise you can provide list of default fields where your search terms should be looked for.

q=title:next thing

Both ways are correct. If you have a specific field to search for, you should mention it. Otherwise to search on default field, you can leave the name optional.

Upvotes: 1

d whelan
d whelan

Reputation: 804

this query is searching the default search field (df) for title, next, and thing %20 is a space character.

q=title%20next%20thing

try something like q=next%20thing&df=title

Upvotes: 1

Related Questions