简体   繁体   English

Solr中的多词查询搜索文档

[英]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 title字段类型是

<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我正在尝试搜索next thing ,所以请求是/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我希望具有id: 2的文档位于顶部,但顺序与添加的顺序相同,分数相同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?查询应该如何实现,如果来自查询的更多单词在标题中,而不是文档应该在顶部?

this query is searching the default search field (df) for title, next, and thing %20 is a space character.此查询正在搜索标题、下一个的默认搜索字段 (df),而事物 %20 是一个空格字符。

q=title%20next%20thing q=title%20next%20thing

try something like q=next%20thing&df=title尝试类似 q=next%20thing&df=title

Your query considered as OR on the default field.您的查询在默认字段上被视为OR

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.否则,要搜索默认字段,您可以将名称保留为可选。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM