我使用Lucene.Net版本3.0.3.0,並試圖找到一種方法來搜索數(整數),並最終取回結果在最近的數更高的分數在列表中。Lucene的:查找最近數
爲了簡單起見,我已經簡化了文件:
private void WriteDocument(IndexWriter writer, string product, int weight)
{
Document document = new Document();
var fieldProduct = new Field("Product", product, Field.Store.YES, Field.Index.NOT_ANALYZED);
document.Add(fieldProduct);
var fieldWeight = new NumericField("Weight", Field.Store.YES, true);
fieldWeight.SetIntValue(weight);
document.Add(fieldWeight);
writer.AddDocument(document);
}
它包括2場:產品和重量。最後一個是數字字段。
出於測試目的,我插了一堆文件:
WriteDocument(writer, "ONORNN", 100);
WriteDocument(writer, "ONORNN", 200);
WriteDocument(writer, "ONORNN", 300);
WriteDocument(writer, "ONORAA", 400);
前3都得到了相同的產品代碼。重量可以是1到999之間的任何值。
我可以看到Lucene.Net
提供了一種使用NumericRangeQuery
來搜索範圍內的數字的方法,但這並不能幫助我,因爲它不允許輸入接近值,只有mix
和max
:
var weightRange = NumericRangeQuery.NewIntRange("Weight", 1, 999, true, true);
是否有任何其他類型的查詢,我可以用它來實現我所期待的?
太好了。非常感謝你。明天我會給它一個回去,並回來一些反饋。乾杯。 – LeftyX
不客氣。不幸的是,你仍然需要做些什麼 – Mysterion
儘管這似乎是可行的。非常感謝你。 – LeftyX