我有两个分片,并且正在尝试通过对分片进行分布式搜索来实现建议程序(使用solr 4.10.1)。似乎建议者遍历每个分片并加入结果集,从而留下重复项。在我的solrconfig.xml文件中,我具有以下内容:

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
      <str name="name">titleSuggester</str>
      <str name="lookupimpl">AnalyzingLookupFactory</str>
      <str name="lookupimpl">FreeTextSuggesterFactory</str>
      <str name="dictionaryimpl">DocumentDictionaryFactory</str>
      <str name="field">title_sug</str>
      <str name="weightField">rank</str>
      <str name="suggestAnalyzerFieldType">shingleSuggest</str>
      <str name="buildOnCommit">true</str>
    </lst>
</searchComponent>`


<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
  <lst name="defaults">
    <str name="suggest">true</str>
    <str name="suggest.count">10</str>
  </lst>
  <arr name="components">
    <str>suggest</str>
  </arr>
</requestHandler>
http://localhost:8983/solr/collection1/suggest?suggest.dictionary=titleSuggester&shards.qt=/suggest&shards=shard1,shard2&suggest.q=an&wt=json&indent=true结果为:
{   "responseHeader":{
    "status":0,
    "QTime":12},   "suggest":{"titleSuggester":{
      "an":{
        "numFound":10,
        "suggestions":[{
            "term":"an",
            "weight":149,
            "payload":""},
          {
            "term":"an",
            "weight":142,
            "payload":""},
          {
            "term":"an american",
            "weight":6,
            "payload":""},
          {
            "term":"an affair",
            "weight":4,
            "payload":""},
          {
            "term":"an 18th century",
            "weight":2,
            "payload":""},
          {
            "term":"an 18th",
            "weight":2,
            "payload":""},
          {
            "term":"an american hymn",
            "weight":2,
            "payload":""},
          {
            "term":"an 18th century drawing room",
            "weight":2,
            "payload":""},
          {
            "term":"an 18th century drawing",
            "weight":2,
            "payload":""},
          {
            "term":"an american hymn (main",
            "weight":2,
            "payload":""}]}}}}

从上面可以看出,结果项“an”返回两次,每个分片一次。如果我使用distrib = false(http://localhost:8983/solr/collection1/suggest?suggest.dictionary=titleSuggester&distrib=false&suggest.q=an&wt=json&indent=true),我没有得到任何重复,这可能是预期的:
{ "responseHeader":{
    "status":0,
    "QTime":1},
  "suggest":{"titleSuggester":{
      "an":{
        "numFound":10,
        "suggestions":[{
            "term":"an",
            "weight":149,
            "payload":""},
          {
            "term":"an 18th",
            "weight":2,
            "payload":""},
          {
            "term":"an 18th century",
            "weight":2,
            "payload":""},
          {
            "term":"an 18th century drawing",
            "weight":2,
            "payload":""},
          {
            "term":"an 18th century drawing room",
            "weight":2,
            "payload":""},
          {
            "term":"an absolution take",
            "weight":1,
            "payload":""},
          {
            "term":"an absolution take her",
            "weight":1,
            "payload":""},
          {
            "term":"an absolution take her to",
            "weight":1,
            "payload":""},
          {
            "term":"an absolution take her to sea,",
            "weight":1,
            "payload":""},
          {
            "term":"an affair",
            "weight":4,
            "payload":""}]}}}}

有什么办法可以删除重复的结果?

最佳答案

您可以使用Solr的分组功能;添加到您的查询:

&group = true&group.field = term&group.main = true

每个相同的术语将仅返回一个文档,并且将以与常规查询相同的格式返回它们(group.main = true)。

有关更多信息,请参见http://wiki.apache.org/solr/FieldCollapsing

07-26 01:13