SOLR中基于排名的排名

时间:2020-05-21 09:50:18

标签: solr lucene

我需要根据搜索查询的位置对SOLR搜索结果进行排序。例如,我有4个文档

1。sol-lucene的演示

2.lucene主要致力于文本索引

3。使用示例解释lucene

4.lucene是开源

当我将使用查询文本 lucene 搜索时,我需要按以下顺序搜索结果

2.lucene主要致力于文本索引

4.lucene是开源

3。使用示例解释lucene

1。sol-lucene的演示

即将搜索查询的排名提高到第一和第二位置

下面是我需要基于位置排序的字段定义

*<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="true">
    <analyzer type="index">
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
        <filter class="solr.WordDelimiterGraphFilterFactory" catenateNumbers="1" generateNumberParts="1" protected="protwords.txt" splitOnCaseChange="1" generateWordParts="0" preserveOriginal="1" catenateAll="0" catenateWords="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>        
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
        <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
        <filter class="solr.WordDelimiterGraphFilterFactory" catenateNumbers="1" generateNumberParts="1" protected="protwords.txt" splitOnCaseChange="1" generateWordParts="0" preserveOriginal="1" catenateAll="0" catenateWords="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
   <similarity class="CustomSimilarity" />
</fieldType>*

为此,我尝试通过在solr中添加customSimilarity类来禁用termfrequency,但是我却收到了错误消息

[schema.xml] fieldType的插件初始化失败:加载类错误

以下是CustomSimilarity类的类定义

import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.schema.SimilarityFactory;
import org.apache.solr.search.similarities.SchemaSimilarityFactory;


public class CustomSimilarity extends SchemaSimilarityFactory{

    public float tf(float freq) {
        return 1.0f;
    }

}

solrconfig中的jar文件路径

  <lib dir="${solr.install.dir:../../../..}/dist/"  regex=".*.jar" /> 

任何帮助都会被申请

1 个答案:

答案 0 :(得分:0)

有两件事。

1)您忘了写@Override,以免您对tf的定义。

2)在指定jar路径时,正则表达式必须为“。*。jar”

import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.schema.SimilarityFactory;
import org.apache.solr.search.similarities.SchemaSimilarityFactory;


public class CustomSimilarity extends SchemaSimilarityFactory{

    @Override
    public float tf(float freq) {
        return 1.0f;
    }

}

正则表达式:

<lib dir="${solr.install.dir:../../../..}/dist/"  regex=".*\.jar" />