使用相邻查询关键字更好地搜索结果

时间:2016-11-25 12:01:34

标签: search solr lucene broadleaf-commerce

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

以下是配置。

schema.xml中 `                            

    <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中

    <?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>

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

enter image description here

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

enter image description here

我不想将每个搜索限制为引号,因为用户可能会搜索某些组合,例如“作者书”,如果在短语中搜索,肯定会得到0个结果,因为它不会与确切的短语匹配。

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

1 个答案:

答案 0 :(得分:3)

您可以使用pf2处理程序中的pf3edismax参数来提升两个(pf2)或三个(pf3)的文档您的条款是在现场相互发现的。

defType=edismax&pf2=title^4

你也有常规dismax处理程序的pf参数,但这是基于所有术语都很接近的假设。这可能有所帮助,但pf2pf3听起来更适合您的需求。