2017-01-12 33 views
0

我在Lucene的查询6.2.0是这样:得分的文件6.2.0

query query = new PhraseQuery.Builder() 
         .add(new Term("country","russia")) 
         .setSlop(1) 
         .build(); 

基本上我的所有文件它们之中:

{ 
    "_id" : ObjectId("586b723b4b9a835db416fa26"), 
    "name" : "test", 
    "countries" : { 
     "country" : [ 
      { 
       "name" : "russia" 
      }, 
      { 
       "name" : "USA china" 
      } 
     ] 
    } 
} 
{ 
    "_id" : ObjectId("586b73f24b9a835fefb10ca5"), 
    "name" : "nitika jain", 
    "countries" : { 
     "country" : [ 
      { 
       "name" : "russia and denmrk" 
      }, 
      { 
       "name" : "USA china" 
      } 
     ] 
    } 
} 
{ 
    "_id" : ObjectId("586b744f4b9a835fefb10ca7"), 
    "name" : "arjun", 
    "countries" : { 
     "country" : [ 
      { 
       "name" : "russia pakistan" 
      }, 
      { 
       "name" : "india iraq" 
      } 
     ] 
    } 
} 

我想其中有一个文件只有russia。理想情况下,应该是一个得分最高,而是我得到类似"Found 3 hits."

Document<stored,indexed,tokenized<id:586b723b4b9a835db416fa26> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name:test> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<countries:{ "country" : [ { "name" : "russia"} , { "name" : "USA china"}]}> stored,indexed,tokenized<country:russia> stored,indexed,tokenized<country:USA china>>**0.12874341** 

Document<stored,indexed,tokenized<id:586b73f24b9a835fefb10ca5> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name:nitika jain> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<countries:{ "country" : [ { "name" : "russia and denmrk"} , { "name" : "USA china"}]}> stored,indexed,tokenized<country:russia and denmrk> stored,indexed,tokenized<country:USA china>>**0.12874341** 

Document<stored,indexed,tokenized<id:586b744f4b9a835fefb10ca7> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name:arjun> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<countries:{ "country" : [ { "name" : "russia pakistan"} , { "name" : "india iraq"}]}> stored,indexed,tokenized<country:russia pakistan> stored,indexed,tokenized<country:india iraq>>**0.12874341** 

所有3个结果是同样打进。我怎样才能得到文件只有russia得分最高?

回答

0

在短语查询中,缺省值为零,需要精确匹配。这意味着如果你以这种方式修改你的查询:

query query = new PhraseQuery.Builder() 
         .add(new Term("country","russia")) 
         .build(); 

你会得到你要找的。

+0

其实它的工作,如果在索引时我将字段保留为stringFeild而不是文本字段,并进行普通查询而不是短语查询,但我需要该字段为TextFeild。 –