【问题标题】:Apache Solr - wrong count words in termfreq functionApache Solr - termfreq 函数中的单词计数错误
【发布时间】:2020-08-07 13:08:14
【问题描述】:

是否有任何解决方案,使用 termfreq 来表达,而不是一个词(一个词工作正确),如:termfreq(field,"test value") - 工作失败:

schema.xml:

<fieldType name="text_books_index" class="solr.TextField">
        <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.MorfologikFilterFactory"/>
            <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" />
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.MorfologikFilterFactory"/>
        </analyzer>
    </fieldType>

【问题讨论】:

  • 问题没有说清楚...您能否详细说明问题?
  • 是的,例如:在文档中,在字段文本中有一个句子:“这是一个例句”,如果 termfreq(text,"example") = 1 - 这是正确的,但如果 termfreq( text,"例句") = 0,失败
  • 我建议在您的字段类型中尝试使用 ShingleFilterFactory ..
  • 我试过了,但不行:(
  • 仅在索引分析器中尝试...还有为什么要使用 edgengramfilter ....如果您正在寻找词组匹配...您不应该使用它

标签: solr solrcloud


【解决方案1】:

所以,新的 schema.xml 字段类型:

<fieldType name="text_books_index" class="solr.TextField">
        <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.MorfologikFilterFactory"/>
            <filter class="solr.ShingleFilterFactory" minShingleSize="2" maxShingleSize="4"/>
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.MorfologikFilterFactory"/>
        </analyzer>
    </fieldType>

和字段声明:

<field name="bookIndex" type="text_books_index" multiValued="false" indexed="true" required="true" stored="true"/>

和查询:

{
"responseHeader": {
"zkConnected": true,
"status": 0,
"QTime": 1,
"params": {
"q": "bookIndex:\"search phraze\"~3 ",
"fl": "id,termfreq(bookIndex,\"search phraze\"),termfreq(title,\"search phraze\"),termfreq(author,\"search phraze\"),termfreq(isbn,\"search phraze\"),termfreq(notes,\"search phraze\"),termfreq(tableOfContent,\"search phraze\"),termfreq(descriptionBook,\"search phraze\")",
"start": "0",
"sort": "",
"fq": "",
"rows": "10"
}
},
"response": {
"numFound": 1,
"start": 0,
"docs": [
{
"id": "000",
"termfreq(bookIndex,\"search phraze\")": 0,
"termfreq(title,\"search phraze\")": 0,
"termfreq(author,\"search phraze\")": 0,
"termfreq(isbn,\"search phraze\")": 0,
"termfreq(notes,\"search phraze\")": 0,
"termfreq(tableOfContent,\"search phraze\")": 0,
"termfreq(descriptionBook,\"search phraze\")": 0
}
]
}
}

而且不工作:(

【讨论】:

  • 请将这些详细信息添加到您的问题中,而不是作为答案 - 并查看在“分析”下为内容编制索引时的输出 - 它会告诉您正在生成哪些令牌。另外,请记住在更改字段类型后重新索引您的内容。
猜你喜欢
  • 1970-01-01
  • 2015-04-07
  • 1970-01-01
  • 1970-01-01
  • 2021-09-14
  • 2017-12-19
  • 2020-06-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多