【问题标题】:Solr partial searchSolr 部分搜索
【发布时间】:2019-08-10 18:54:47
【问题描述】:

(这里是 Solr 新手)我设置了一个简单的 solr 实例来索引 html/pdf 文档的集合。它基本上可以工作,但我一直在尝试添加 部分搜索 功能。

到目前为止我尝试了什么: 由于我认为保留默认托管架构更好,因此我尝试使用架构 api 添加带有 ngram 过滤器的字段text_partial,就像这样。

curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field-type":{
    "name":"text_ngram",
    "class":"solr.TextField",
    "positionIncrementGap":"100",
    "indexAnalyzer":{
        "tokenizer":{
        "class":"solr.WhitespaceTokenizerFactory"
        },
        "filters": [
            {"class":"solr.LowerCaseFilterFactory"},
            {
            "class":"solr.NGramTokenizerFactory",
            "maxGramSize":"25",
            "minGramSize":"3",
            }
        ]

    },
    "queryAnalyzer":{
      "tokenizer":{
        "class":"solr.WhitespaceTokenizerFactory"},
      "filters":[
        {"class":"solr.LowerCaseFilterFactory"}]}
},
"add-field":{
    "name": "text_partial",
    "type": "text_ngram",
    "indexed": true,
    "stored": true
}
}' http://127.0.0.1:8983/solr/my_collection/schema

我尝试删除所有文档并重新编制索引,但我看不出与以前有什么不同:全词搜索仍然有效,但对“text_partial:something”的查询没有结果。

然后我意识到我没有对我的 DataImportHandler 进行任何修改,目前就是这样

<dataConfig>  
    <dataSource type="BinFileDataSource" />
        <document>
            <entity name="files" dataSource="null" rootEntity="false"
            processor="FileListEntityProcessor"
            baseDir="C:/xampp/htdocs/tcdocs12" fileName=".*\.(html|pdf)"
            onError="skip"
            recursive="true">
                <field column="fileAbsolutePath" name="id" />
                <field column="fileSize" name="size" />
                <field column="fileLastModified" name="lastModified" />

                <entity
                    name="documentImport"
                    processor="TikaEntityProcessor"
                    url="${files.fileAbsolutePath}"
                    format="text"
                    transformer="TemplateTransformer,RegexTransformer"
                    >
                    <field column="file" name="fileName"/>
                    <field column="Author" name="author" meta="true"/>
                    <field column="title" name="title" meta="true"/>
                    <field column="text" name="text"/>

                    <field column="tempCol" template="${files.fileAbsolutePath}" regex="${dataimporter.request.docs_dir}(.*)" replaceWith="$1"/>

                    <field column="url" regex="\\" replaceWith="/" sourceColName="tempCol"/>
                    <field column="cat" regex="^\/.+?\/(.+?)\/.*" replaceWith="$1" sourceColName="url"/>


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

我是否必须对 DIH 或架构进行任何修改才能在“text_partial”字段中处理和索引“文档文本内容”?

【问题讨论】:

    标签: solr full-text-search


    【解决方案1】:

    内容不会神奇地添加到字段中。如果您已经将内容索引到名为text 的字段中,则可以添加copyField 指令以有效地将相同内容索引到具有不同处理的两个字段中。

    Add a new copy field rule in the Schema API:

    curl -X POST -H 'Content-type:application/json' --data-binary '{
      "add-copy-field":{
         "source":"text",
         "dest":[ "text_partial" ]}
    }' http://localhost:8983/solr/my_collection/schema
    

    添加此规则后,您需要重新索引,因为复制发生在索引时的任何进一步处理之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多