【发布时间】:2012-10-29 10:03:06
【问题描述】:
我最近误以为 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?
感谢您的帮助
【问题讨论】:
标签: nhibernate lucene.net nhibernate.search