我最近假设 Nhibernate.Search 会将我的类上的整数属性索引为数字字段。
[Indexed]
public class Location : Entity
{
[IndexedEmbedded(Depth = 1, Prefix = "Country_")]
public virtual Country Country { get; set; }
[Field(Index.Tokenized)]
public virtual string Name { get; set; }
[Field(Index.Tokenized)]
public virtual string AlternativeNames { get; set; }
[Field(Index.Tokenized)]
public virtual string OriginalNames { get; set; }
[Field(Index.UnTokenized)]
public virtual string LocationType { get; set; }
[Field()]
public virtual int? Population { get; set; }
}
但是当我像这样为查询设置排序时:
var words = query.Split(' ');
var luceneQuery = string.Join(" AND ", words.Select(x => "Name:{0}*".F(x)));
luceneQuery += " AND LocationType:locality";
var results = search.CreateFullTextQuery<Location>(luceneQuery)
.SetSort(new Sort(new SortField("Population", CultureInfo.CurrentCulture, true)))
.SetMaxResults(100)
.List<Location>();
它返回按数字排序的结果,其样式与这样的单词排序相同:
City Country Region Population
New London United States North America 998
Nueva Londres Paraguay South America 971
New London United States North America 967
Londonderry United Kingdom British Islands 92133
London Kiribati Micronesia 921
London United States North America 8122
London United Kingdom British Islands 7869322
New London United States North America 7316
所以我的问题是,由于 Nhibernate.Search 将其视为文本字段,我如何将其更改为数字字段,是否可以转换或者我必须重新索引每条记录。其中 340K。
我开始感觉到 Nhibernate 的便利性。如果不能做到这一点,搜索就会丢失。也许我将不得不重新开始并使用普通的 Lucene.Net?
谢谢你的帮助