首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用相邻查询关键字的Solr更好的搜索结果

使用相邻查询关键字的Solr更好的搜索结果
EN

Stack Overflow用户
提问于 2016-11-25 12:01:34
回答 1查看 560关注 0票数 0

我已经为我的电子商务应用程序配置了solr (它主要包含书籍数据)。搜索结果似乎没有返回我所期望的。

以下是配置。

schema.xml `

代码语言:javascript
复制
    <field name="namespace" type="string" indexed="true" stored="false" />
    <field name="id" type="string" indexed="true" stored="true" />
    <field name="productId" type="long" indexed="true" stored="true" />
    <field name="skuId" type="long" indexed="true" stored="true" />
    <field name="category" type="long" indexed="true" stored="false" multiValued="true" />
    <field name="explicitCategory" type="long" indexed="true" stored="false" multiValued="true" />
    <field name="searchable" type="text_general" indexed="true" stored="false" />

    <dynamicField name="*_searchable" type="text_general" indexed="true" stored="false" />
    <dynamicField name="*_i" type="int" indexed="true" stored="false" />
    <dynamicField name="*_is" type="int" indexed="true" stored="false" multiValued="true" />
    <dynamicField name="*_s" type="string" indexed="true" stored="false" />
    <dynamicField name="*_ss" type="string" indexed="true" stored="false" multiValued="true" />
    <dynamicField name="*_l" type="long" indexed="true" stored="false" />
    <dynamicField name="*_ls" type="long" indexed="true" stored="false" multiValued="true" />
    <dynamicField name="*_t" type="text_general" indexed="true" stored="false" />
    <dynamicField name="*_txt" type="text_general" indexed="true" stored="false" multiValued="true" />
    <dynamicField name="*_b" type="boolean" indexed="true" stored="false" />
    <dynamicField name="*_bs" type="boolean" indexed="true" stored="false" multiValued="true" />
    <dynamicField name="*_d" type="double" indexed="true" stored="false" />
    <dynamicField name="*_ds" type="double" indexed="true" stored="false" multiValued="true" />
    <dynamicField name="*_p" type="double" indexed="true" stored="false" />

    <dynamicField name="*_dt" type="date" indexed="true" stored="false" />
    <dynamicField name="*_dts" type="date" indexed="true" stored="false" multiValued="true" />

    <!-- some trie-coded dynamic fields for faster range queries -->
    <dynamicField name="*_ti" type="tint" indexed="true" stored="false" />
    <dynamicField name="*_tl" type="tlong" indexed="true" stored="false" />
    <dynamicField name="*_td" type="tdouble" indexed="true" stored="false" />
    <dynamicField name="*_tdt" type="tdate" indexed="true" stored="false" />

    <!-- Both field types required for geolocation searches. First stores the
        lat and lon components for the "coordinate" FieldType. Second stores
        the coordinate. -->
    <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/>
    <dynamicField name="*_c"  type="coordinate" indexed="true" stored="false"/> 
</fields>

<uniqueKey>id</uniqueKey>

<types>
    <!-- The StrField type is not analyzed, but indexed/stored verbatim. -->
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" />

    <!-- boolean type: "true" or "false" -->
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" />

    <!-- Default numeric field types. For faster range queries, consider the 
        tint/tlong/tdouble types. -->
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0" />
    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0" />

    <!-- Numeric field types that index each value at various levels of precision 
        to accelerate range queries when the number of values between the range endpoints 
        is large. See the javadoc for NumericRangeQuery for internal implementation 
        details. Smaller precisionStep values (specified in bits) will lead to more 
        tokens indexed per value, slightly larger index size, and faster range queries. 
        A precisionStep of 0 disables indexing at different precision levels. -->
    <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0" />
    <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0" />
    <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0" />

    <!-- The format for this date field is of the form 1995-12-31T23:59:59Z, 
        and is a more restricted form of the canonical representation of dateTime 
        http://www.w3.org/TR/xmlschema-2/#dateTime The trailing "Z" designates UTC 
        time and is mandatory. Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z 
        All other components are mandatory. Expressions can also be used to denote 
        calculations that should be performed relative to "NOW" to determine the 
        value, ie... NOW/HOUR ... Round to the start of the current hour NOW-1DAY 
        ... Exactly 1 day prior to now NOW/DAY+6MONTHS+3DAYS ... 6 months and 3 days 
        in the future from the start of the current day Consult the DateField javadocs 
        for more information. Note: For faster range queries, consider the tdate 
        type -->
    <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0" />

    <!-- A Trie based date field for faster date range queries and date faceting. -->
    <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" />

    <!-- A general text field that has reasonable, generic cross-language defaults: 
        it tokenizes with StandardTokenizer and down cases. -->
    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
        <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory" />
            <filter class="solr.LowerCaseFilterFactory" />
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory" />
            <filter class="solr.LowerCaseFilterFactory" />
        </analyzer>
    </fieldType>

    <!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->
    <fieldType name="coordinate" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

</types>

`

solrconfig.xml

代码语言:javascript
复制
    <?xml version="1.0" encoding="UTF-8" ?>
<config>
<luceneMatchVersion>4.10.3</luceneMatchVersion>
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}" />
<updateHandler class="solr.DirectUpdateHandler2" />

<query>
    <maxBooleanClauses>1024</maxBooleanClauses>

    <filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0" />
    <queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
    <documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
    <cache name="perSegFilter" class="solr.search.LRUCache" size="10" initialSize="0" autowarmCount="10" 
            regenerator="solr.NoOpRegenerator" />

    <enableLazyFieldLoading>true</enableLazyFieldLoading>

    <queryResultWindowSize>20</queryResultWindowSize>
    <queryResultMaxDocsCached>200</queryResultMaxDocsCached>

    <listener event="newSearcher" class="solr.QuerySenderListener" />
    <listener event="firstSearcher" class="solr.QuerySenderListener">
        <arr name="queries">
            <lst>
                <str name="q">static firstSearcher warming in solrconfig.xml</str>
            </lst>
        </arr>
    </listener>

    <useColdSearcher>false</useColdSearcher>
    <maxWarmingSearchers>2</maxWarmingSearchers>
</query>

<requestDispatcher handleSelect="false">
    <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048000" formdataUploadLimitInKB="2048"
                addHttpRequestToContext="false"/>
    <httpCaching never304="true" />
</requestDispatcher>

<requestHandler name="/select" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="echoParams">explicit</str>
        <int name="rowsa">10</int>
        <str name="df">name_t</str>
    </lst>
</requestHandler>

<queryResponseWriter name="json" class="solr.JSONResponseWriter">
    <str name="content-type">text/plain; charset=UTF-8</str>
</queryResponseWriter>

例如,当我搜索两个状态时,它给了我很多随机结果,甚至在标题中不包含两个状态。

然而,当我在短语“两个国家”中搜索两个州时,我确实得到了相关的结果。

我不想限制每个搜索引号,因为用户可能会搜索一些组合,如“图书作者”,这肯定会给出0的结果,如果搜索的短语,因为它不符合确切的短语。

我如何改进我的搜索,以便我可以列出最相关的结果在顶部。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-25 15:46:44

您可以在pf2处理程序中使用edismaxpf3参数来增强文档,在这些文档中,可以在字段中找到术语的两个(pf2)或三个(pf3)。

代码语言:javascript
复制
defType=edismax&pf2=title^4

对于常规的dismax处理程序,您也有pf参数,但这是建立在假设所有的术语都是紧密相连的基础上的。这可能会有所帮助,但pf2pf3听起来更适合您的需要。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40804620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档