仅返回在所有字段中匹配的搜索结果

时间:2017-08-14 11:55:18

标签: solr lucene requesthandler dismax

我有名称和尺寸的字段。字段为:NamedimensionLengthdimensionWidthdimensionHeight

我希望查询productX 10x20仅返回包含这两个维度的匹配项。因此,上面的查询可以返回productX 10x20x30productX 10x30x20,但不应该返回productX 10x30x40

第一个结果很好,但我得到了许多其他不相关的匹配。任何想法如何避免这些不相关的结果?

澄清一下,字段是:

 <field indexed="true" multiValued="true" name="Height_mm_Copy" stored="false" type="dimension"/>
 <field indexed="true" multiValued="true" name="Outside_diameter_mm_Copy" stored="false" type="dimension"/>
 <field indexed="true" multiValued="true" name="Inside_diameter_mm_Copy" stored="false" type="dimension"/>
 <field indexed="true" name="name" stored="true" type="title"/>

尺寸的字段类型:

 <fieldType class="solr.TextField" name="dimension" omitNorms="true" positionIncrementGap="100">
 <analyzer type="index">
 <tokenizer class="solr.WhitespaceTokenizerFactory"/>
 <filter class="solr.PatternReplaceFilterFactory" pattern="(\d+)+([.][0])" replacement="$1"/>
 <filter class="solr.TrimFilterFactory"/> 
 <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
 </analyzer>

 <analyzer type="query">
 <tokenizer class="solr.WhitespaceTokenizerFactory"/>
 <filter class="solr.PatternReplaceFilterFactory" pattern="," replace="all" replacement="."/>
 <filter class="solr.TrimFilterFactory"/>
 <filter class="solr.PatternReplaceFilterFactory" pattern="(\d+)+([.][0])" replacement="$1"/>
 <filter catenateAll="0" catenateNumbers="0" catenateWords="0" class="solr.WordDelimiterFilterFactory" generateNumberParts="1" generateWordParts="0" preserveOriginal="1" splitOnCaseChange="0" splitOnNumerics="1" types="wdfftypes.txt"/>
 <filter class="solr.ASCIIFoldingFilterFactory"/>
 <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
 </analyzer>

requestHandler:

  <requestHandler name="dismax" class="solr.SearchHandler" >
<lst name="defaults">
 <str name="defType">dismax</str>
 <str name="echoParams">explicit</str>
 <float name="tie">0.3</float>

 <str name="qf">
    supplierArticleId_Prefix
 </str>     
 <str name="fl">
    UUID,score
 </str>
 <str name="mm">
    3&lt;-1 5&lt;-2 6&lt;90%
 </str>
 <int name="ps">100</int>
 <str name="q.alt">*:*</str>
</lst>
<arr name="last-components">
   <str>spellcheck</str>
</arr>
</requestHandler>

1 个答案:

答案 0 :(得分:0)

通过制作&#34; name&#34;的副本字段来解决它。通过使用 此字段的fieldType中为<filter class="solr.PatternCaptureGroupFilterFactory" pattern="(\d+/*[xX]\d+)" preserve_original="false"/>。所以来自string&#34;产品10x20x30&#34;只有&#34; 10x20&#34;仍然在此字段中编入索引。