【问题标题】:Search most common phrases by part of phrase按词组的一部分搜索最常用的词组
【发布时间】:2015-02-03 15:58:57
【问题描述】:

我没有琐碎的任务,想了解 Sphinx 或 Solr 是否是解决它的正确工具。简化示例:我的网站上有搜索字段,用于按产品描述进行搜索。以及 mysql db 中的下一个描述:

Id  Desc
1   this is my test document number one. also checking search within phrases.
2   this is my test document number two
3   this is another group
4   this is first group
5   this is first test
6   this is your test

当用户在搜索字段中输入一些文本时。 “是”他应该得到下一个结果(包含“是”的前三个短语): “这是”、“是我的”、“是第一个”。

有人知道如何做到这一点吗?也许你现在有更好的搜索引擎可以满足我的需求?

<fieldType class="solr.TextField" name="text_auto">
<analyzer type="index"> 
    <tokenizer class="solr.StandardTokenizerFactory"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    <filter class="solr.ShingleFilterFactory" maxShingleSize="4" outputUnigrams="true" outputUnigramsIfNoShingles="false" /> 
</analyzer> 
<analyzer type="query"> 
    <tokenizer class="solr.StandardTokenizerFactory"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    <filter class="solr.StandardFilterFactory"/> 
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> 
</analyzer>
</fieldType>

<field name="title" type="text_auto" indexed="true" stored="true"/> 
<field name="content_autosuggest" type="text_auto" indexed="true" stored="true" multiValued="false"/>

<copyField source="title" dest="content_autosuggest"/>

【问题讨论】:

    标签: solr elasticsearch search-engine sphinx


    【解决方案1】:

    您可以尝试使用ShingleFilter。如 wiki 上的示例所示,如果您将 maxShingleSize 和 mixShingleSize 都设置为 2,您会得到:

    this is my test document => this is, is my, my test, test document
    

    (如果需要,请确保在 shingle 过滤器之前使用适当的标记器和其他分析器。)

    然后你可以在这个字段上做这样的正则表达式搜索:

    shingle_field:/(is .*)|(.* is)/
    

    应该返回所有文件。 (我相信这应该可行,因为 wiki 声明:它将令牌组合创建为单个令牌。)

    使用facet query 获取计数:

    shingle_field:/(is .*)|(.* is)/&facet=true&facet.field=shingle_field
    

    (添加rows=0,如果您不关心文档并且只需要方面。)

    【讨论】:

    • 谢谢阿伦。会试试这个过滤器
    • 看起来像只按前缀的方面查询搜索。前任。当我尝试查找“is”时,它不会返回“this is”。
    • 使用您定义的字段的 fieldType 更新您的 qn。
    • “使用 fieldType 更新您的 qn”是什么意思?你能举个简单的例子吗?
    • 您用来进行查询和分面的字段的 fieldType 定义是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-25
    • 2019-11-24
    • 1970-01-01
    • 2019-02-12
    相关资源
    最近更新 更多