2016-05-25 38 views
3

我想使用Solr在用户搜索(e.g. "skinny jeans" in "blue skinny jeans")的类别中查找精确匹配。我正在使用以下类型定义:Solr瓦在调试查询中不可见

<fieldType name="subphrase" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true"> 
    <analyzer type="index"> 
    <charFilter class="solr.PatternReplaceCharFilterFactory" 
       pattern="\ " 
       replacement="_"/> 
    <tokenizer class="solr.KeywordTokenizerFactory"/> 
    </analyzer> 
    <analyzer type="query"> 
    <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
    <filter class="solr.ShingleFilterFactory" 
      outputUnigrams="true" 
      outputUnigramsIfNoShingles="true" 
      tokenSeparator="_" 
      minShingleSize="2" 
      maxShingleSize="99"/> 
    </analyzer> 
</fieldType> 

该类型将索引类别不进行标记化,只将下划线替换为空白。但它会标记查询并将它们拼凑(带下划线)。

我想要做的是匹配索引类别的查询shingles。在Solr的分析页面,我可以看到,空格/下划线更换工程两个索引和查询,我可以看到,查询被鹅卵石正确的(下图):

Successful whitespace modification on index, and shingle generation on query

我的问题是,在Solr查询页面中,我看不到生成的带状疱疹,因此我认为结果类别“紧身牛仔裤”不匹配,但类别“牛仔裤”匹配:(

这是调试输出:

{ 
    "responseHeader": { 
    "status": 0, 
    "QTime": 1, 
    "params": { 
     "q": "name:(skinny jeans)", 
     "indent": "true", 
     "wt": "json", 
     "debugQuery": "true", 
     "_": "1464170217438" 
    } 
    }, 
    "response": { 
    "numFound": 1, 
    "start": 0, 
    "docs": [ 
     { 
     "id": 33, 
     "name": "jeans", 
     } 
    ] 
    }, 
    "debug": { 
    "rawquerystring": "name:(skinny jeans)", 
    "querystring": "name:(skinny jeans)", 
    "parsedquery": "name:skinny name:jeans", 
    "parsedquery_toString": "name:skinny name:jeans", 
    "explain": { 
     "33": "\n2.2143755 = product of:\n 4.428751 = sum of:\n 4.428751 = weight(name:jeans in 54) [DefaultSimilarity], result of:\n  4.428751 = score(doc=54,freq=1.0), product of:\n  0.6709952 = queryWeight, product of:\n   6.600272 = idf(docFreq=1, maxDocs=541)\n   0.10166174 = queryNorm\n  6.600272 = fieldWeight in 54, product of:\n   1.0 = tf(freq=1.0), with freq of:\n   1.0 = termFreq=1.0\n   6.600272 = idf(docFreq=1, maxDocs=541)\n   1.0 = fieldNorm(doc=54)\n 0.5 = coord(1/2)\n" 
    }, 
    "QParser": "LuceneQParser" 
    } 
} 

很明显,parsedquery参数不显示叠瓦式查询。我需要做什么来完成匹配查询shingles与索引值的过程?我觉得我非常接近解决这个问题。任何建议表示赞赏!

+0

你有没有试过名字:“紧身牛仔裤”? – MatsLindh

+0

是的,没有任何回报,甚至没有“牛仔裤”。这可能与我提出的另一个问题有关@ [link](https://stackoverflow.com/questions/37425263/solr-keywordtokenizerfactory-exact-match-for-multiple-words-not-working) As @ Abhijit Bashetti提到,令牌不会这样工作,它们没有任何内容。另外,我实际上不希望它以这种方式工作,我不想用引号,因为我正在寻找一个子字符串,而这会破坏目的。 – mils

回答

2

这是一个不完整的答案,但它可能足以让你感动。

1:你可能想outputUnigrams="false",这样你就不会在查询“紧身牛仔裤”

2匹配类别“牛仔裤”:实际上您想引号搜索,(短语)或现场韩元看不到一个以上的令牌。

3:好像你正在试图做同样的事情,因为这人是: http://comments.gmane.org/gmane.comp.jakarta.lucene.user/34746

该线程看起来像它导致夹杂物的PositionFilterFactory https://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.PositionFilterFactory

如果”重新使用Solr < 5.0,请尝试在查询时间分析结束时查看它是否有效。

不幸的是,该过滤器工厂在5.0中被删除。这是唯一的评论,我发现做什么,而不是: http://lucene.apache.org/core/4_10_0/analyzers-common/org/apache/lucene/analysis/position/PositionFilter.html

autoGeneratePhraseQueries一点点打,但我还没有找到另一种方法,以防止从Solr的产生MultiPhraseQuery。

+0

有一点:) – mils