更新Solr配置以搜索所有字段

时间:2022-09-01 22:13:26

Can anyone advise me on how to search Solr on all fields?

谁能告诉我如何在所有领域搜索Solr?

This is my current requestHandler called "search" and using solr.SearchHandler.

这是我当前的requestHandler,名为“search”并使用solr.SearchHandler。

<requestHandler name="search" class="solr.SearchHandler" default="true">
  <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
    -->
   <lst name="defaults">
    <str name="echoParams">explicit</str>
    <int name="rows">10</int>
   </lst>
</requestHandler>

It appears that I can search on all textual fields, however I need to search on a field called 's_number' and this is an integer.

我似乎可以搜索所有文本字段,但是我需要搜索一个名为's_number'的字段,这是一个整数。

Do I need to use DisMax to allow for searching on all fields?

我是否需要使用DisMax来搜索所有字段?

Also, do I need to adjust the defaultSearchField in schema.xml? It is currently:

另外,我是否需要调整schema.xml中的defaultSearchField?它目前是:

<defaultSearchField>text</defaultSearchField>

2 个解决方案

#1


0  

To search on non-textual fields you probably don't have to edit the config files. You just need to add the parameter correctly to your solr query.

要搜索非文本字段,您可能不必编辑配置文件。您只需要将参数正确添加到solr查询中。

The basic idea is you can use key/value pairs to search on non-textual fields. See http://wiki.apache.org/solr/SolrQuerySyntax.

基本思想是您可以使用键/值对来搜索非文本字段。请参阅http://wiki.apache.org/solr/SolrQuerySyntax。

To search on just s_number, you'd set up your query to the solr server like this:

要仅搜索s_number,您可以将查询设置为solr服务器,如下所示:

q=s_number:123

This will return only results where s_number is 123, as expected -- and it does it as a regular search, not a post-search filter. I don't know what php solr library you're using, so I can't give you the exact code for how to set up this query parameter in your code. If you tell me what library you are using and/or post the source code that actually does the search, I might be able to give you more precise details.

这将仅返回s_number为123的结果,如预期的那样 - 并且它将作为常规搜索而不是搜索后过滤器。我不知道你正在使用什么php solr库,所以我不能给你如何在你的代码中设置这个查询参数的确切代码。如果您告诉我您正在使用的库和/或发布实际执行搜索的源代码,我可能会为您提供更准确的详细信息。

But talking directly to your solr server, the query would look something like this:

但是直接与你的solr服务器交谈,查询看起来像这样:

http://your-solr-server:8983/solr/select/?q=s_number%3A123

#2


4  

The defaultSearchField parameter you're talking about references this field in your schema.xml:

您正在讨论的defaultSearchField参数在schema.xml中引用此字段:

<!-- catchall field, containing all other searchable text fields (implemented
        via copyField further on in this schema  -->
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

If you look a little further down you should see statements that look like this:

如果你向下看一点,你应该看到如下所示的语句:

<copyField source="name" dest="text"/>
<copyField source="summary" dest="text"/>

What you probably want to do is add a copyfield parameter for your s_number field, like so:

你可能想要做的是为你的s_number字段添加一个copyfield参数,如下所示:

<copyField source="s_number" dest="text"/>

This will copy the number field into your default search field (text). The text field is a "dumping ground" of terms for a default search. The good thing about it is you can control how and what information gets put into default search. The bad thing is that you need to add copyField parameters for each field you want in the default.

这会将数字字段复制到默认搜索字段(文本)中。文本字段是默认搜索的术语“倾销地”。关于它的好处是你可以控制如何以及将什么信息放入默认搜索中。不好的是,您需要为默认情况下所需的每个字段添加copyField参数。

#1


0  

To search on non-textual fields you probably don't have to edit the config files. You just need to add the parameter correctly to your solr query.

要搜索非文本字段,您可能不必编辑配置文件。您只需要将参数正确添加到solr查询中。

The basic idea is you can use key/value pairs to search on non-textual fields. See http://wiki.apache.org/solr/SolrQuerySyntax.

基本思想是您可以使用键/值对来搜索非文本字段。请参阅http://wiki.apache.org/solr/SolrQuerySyntax。

To search on just s_number, you'd set up your query to the solr server like this:

要仅搜索s_number,您可以将查询设置为solr服务器,如下所示:

q=s_number:123

This will return only results where s_number is 123, as expected -- and it does it as a regular search, not a post-search filter. I don't know what php solr library you're using, so I can't give you the exact code for how to set up this query parameter in your code. If you tell me what library you are using and/or post the source code that actually does the search, I might be able to give you more precise details.

这将仅返回s_number为123的结果,如预期的那样 - 并且它将作为常规搜索而不是搜索后过滤器。我不知道你正在使用什么php solr库,所以我不能给你如何在你的代码中设置这个查询参数的确切代码。如果您告诉我您正在使用的库和/或发布实际执行搜索的源代码,我可能会为您提供更准确的详细信息。

But talking directly to your solr server, the query would look something like this:

但是直接与你的solr服务器交谈,查询看起来像这样:

http://your-solr-server:8983/solr/select/?q=s_number%3A123

#2


4  

The defaultSearchField parameter you're talking about references this field in your schema.xml:

您正在讨论的defaultSearchField参数在schema.xml中引用此字段:

<!-- catchall field, containing all other searchable text fields (implemented
        via copyField further on in this schema  -->
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

If you look a little further down you should see statements that look like this:

如果你向下看一点,你应该看到如下所示的语句:

<copyField source="name" dest="text"/>
<copyField source="summary" dest="text"/>

What you probably want to do is add a copyfield parameter for your s_number field, like so:

你可能想要做的是为你的s_number字段添加一个copyfield参数,如下所示:

<copyField source="s_number" dest="text"/>

This will copy the number field into your default search field (text). The text field is a "dumping ground" of terms for a default search. The good thing about it is you can control how and what information gets put into default search. The bad thing is that you need to add copyField parameters for each field you want in the default.

这会将数字字段复制到默认搜索字段(文本)中。文本字段是默认搜索的术语“倾销地”。关于它的好处是你可以控制如何以及将什么信息放入默认搜索中。不好的是,您需要为默认情况下所需的每个字段添加copyField参数。