gpt4 book ai didi

c# - NHibernate.Search 预测

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:00 24 4
gpt4 key购买 nike

我正在尝试使用 NHibernate.Search 通过投影获得 Lucene.NET 分数。

我的领域对象实现了一个接口(interface) 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>();

没有分数投影一切正常,但有一个异常(exception):

InvalidCastException : At least one element in the source array could not be cast down to the destination array type.

最佳答案

发现自己,我需要为此使用 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;

关于c# - NHibernate.Search 预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2385255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com