【问题标题】:Duplicates when searching by text_general按 text_general 搜索时重复
【发布时间】:2019-09-08 14:59:18
【问题描述】:

我正在使用 Solr 8,并以几乎默认配置运行它。我想搜索几个文本字段,并将它们复制到 _text_general_ 字段中。

这是我的 managed_schema.xml 的一部分:

<field name="id" type="string" stored="true" required="true" />
<field name="p_name" type="string" indexed="true" stored="true" required="true" />
<field name="p_additional_info" type="string" indexed="true" stored="true" />
<field name="p_brand" type="string" indexed="true" stored="true" />
<field name="p_manufacturer" type="string" indexed="true" stored="true" />
<field name="p_image_link" type="string" indexed="false" stored="true" />

<uniqueKey>id</uniqueKey>

<field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
<field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>

<!-- copy this 3 values to basic search field -->
<copyField source="p_name" dest="_text_"/>
<copyField source="p_brand" dest="_text_"/>
<copyField source="p_additional_info" dest="_text_"/>

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="true">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
    <filter class="solr.LowerCaseFilterFactory"/>        
    <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
    <filter class="solr.SynonymGraphFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

当我尝试使用q=*:* 获得结果时,它不会给我任何重复。当我尝试使用q=men 获得结果时,我看到以下内容:

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"men",
      "_":"1555579368807"}},
  "response":{"numFound":9,"start":0,"docs":[
      {
        "p_additional_info":"A creme especially made for men, suitable for face, body and hands.",
        "p_name":"NIVEA MEN CREME",
        "id":"16",
        "_version_":1630705876203470848},
      {
        "p_additional_info":"A creme especially made for men, suitable for face, body and hands.",
        "p_name":"NIVEA MEN CREME",
        "id":"16",
        "_version_":1630702978343108608},
        ...            
]}}

有没有人知道如何解决它?..

UPD 我正在通过 DIH 从 DB 导入我的文档:

<dataConfig>
    <dataSource name="jdbc" driver="org.postgresql.Driver" url="jdbc:postgresql://mydb.rds.amazonaws.com:5432/myapp" user="***" password="***" readOnly="true" />
    <document>
          <entity name="products"
                  query="select id, additional_info, brand, name, image_link, country, manufacturer from products"
                  dataSource="jdbc" pk="id"> 

            <field name="id" column="id" />
            <field name="p_additional_info" column="additional_info" />
            <field name="p_brand" column="brand" />
            <field name="p_name" column="name" />
            <field name="p_country" column="country" />
            <field name="p_manufacturer" column="manufacturer" />
            <field name="p_image_link" column="image_link" />

          </entity>
    </document>
</dataConfig>

【问题讨论】:

  • 这里文档的 version 不同...这表明即使您有一个 uniqueKey 作为 id,它也不会更新现有文档...它添加了另一个使用不同的版本...当前您有字段 id 的字符串类型...尝试将其更改为整数...
  • ...它也没有被索引...首先尝试使索引为true,然后尝试稍后选项
  • 不,这是一个假设! uniqueKey 可以使用“string”类型,对于 field 和 fieldType 定义,indexed 属性的隐式默认值是 "true",只要您的“string” fieldType 没有显式的 indexed="false",@ 987654329@ 应该被索引。还要记住不要对托管模式进行手动编辑,而是使用模式 API。
  • @EricLavault : 是的..good catch...我验证了..indexed 属性对于定义的字段是隐式正确的
  • @MatsLindh 我正在通过 DIH 从我的数据库中导入所有数据。我已经用 DIH 配置更新了这个问题。最奇怪的是,当按文本搜索时,q=*:* 返回 NO 重复项......

标签: search solr full-text-search


【解决方案1】:

当我进行手动更改时,我的 managed_schema 中似乎存在一些错误。在我创建新的并通过架构 API 进行更改后,正如@EricLavault 所假设的那样,一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多