通过text_general搜索时重复

时间:2019-04-18 09:37:23

标签: search solr full-text-search

我正在使用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从数据库导入文档:

<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>

1 个答案:

答案 0 :(得分:0)

当我进行手动更改时,好像我的managed_schema中存在一些错误。创建新文件并通过模式API进行更改后,就像@EricLavault所假定的那样,一切正常。