我正在尝试使用NHibernate.Search通过预测来获得Lucene.NET的分数。
我的域对象实现了一个接口IScorableEntity
public interface IScorableEntity
{
float Score { get; set; }
}..。
IFullTextSession session = Search.CreateFullTextSession(database.Session);
IFullTextQuery textQuery = session.CreateFullTextQuery(query, typeof(Book));
textQuery.SetProjection(ProjectionConstants.SCORE);
var books = textQuery.List<Book>();如果没有分数的预测,一切都是可行的,但有了这样的例外:
InvalidCastException :源数组中至少有一个元素无法转换为目标数组类型.
发布于 2010-03-05 08:00:05
找到了我自己,我需要用2个投影来做这个
textQuery.SetProjection(ProjectionConstants.SCORE, ProjectionConstants.THIS);
var list = textQuery.List();
var books = new List<Book>();
foreach(object[] o in list)
{
var book= o[1] as Book;
if (book!= null)
{
book.Score = (float)o[0];
}
books.Add(book);
}
return books;https://stackoverflow.com/questions/2385255
复制相似问题