如何查询索引为 IndexEmbedded(nhibernate.search 中的 FullText) 的数据
如何查询添加为 IndexEmbedded 的数据?
我有一个实体类
[Indexed]
public class Something
{
[Field(Index.Tokenized, Store = Store.Yes)]
public virtual string Description { get; set; }
[IndexedEmbedded]
public virtual Category Category { get; set; }
[IndexedEmbedded]
public virtual Location Location { get; set; }
}
位置,因为
[Indexed]
public class Location
{
/// </summary>
[Field(Index.Tokenized, Store = Store.Yes)]
public virtual string Address
{
}
数据被添加到索引(包括普通属性和 IndexEmbedded),我可以使用 Luke 看到它们。
但是,当我使用全文查询时,我仅获得普通属性的有效结果,而不是 IndexedEmbedded
例如“示例描述”=> 1 个结果, " 帕洛阿尔托" => 0 个结果(都在索引中) 这是我的查询
using (IFullTextSession s = Search.CreateFullTextSession(NHibernateSession.GetSession())) {
MultiFieldQuerParser qp = new MultiFieldQueryParser(new[] {
“Description”,“Title”,”Name”
}, new StandardAnalyzer());
IQuery NHQuery = s.CreateFullTextQuery(qp.Parse(query), typeof(Something));
result = NHQuery.List();
我做错了什么或遗漏了什么吗?
How do I query for data added as IndexEmbedded?
I have an entity class
[Indexed]
public class Something
{
[Field(Index.Tokenized, Store = Store.Yes)]
public virtual string Description { get; set; }
[IndexedEmbedded]
public virtual Category Category { get; set; }
[IndexedEmbedded]
public virtual Location Location { get; set; }
}
Location as
[Indexed]
public class Location
{
/// </summary>
[Field(Index.Tokenized, Store = Store.Yes)]
public virtual string Address
{
}
Data gets added(both for normal properties and IndexEmbedded) to the index and I can see them using Luke.
However when I query using Fulltext I get valid results only for the normal properties and not for IndexedEmbedded
e.g. "sample description" => 1 result, " Palo Alto" => 0 results(both of them are in the index)
This is my query
using (IFullTextSession s = Search.CreateFullTextSession(NHibernateSession.GetSession())) {
MultiFieldQuerParser qp = new MultiFieldQueryParser(new[] {
“Description”,“Title”,”Name”
}, new StandardAnalyzer());
IQuery NHQuery = s.CreateFullTextQuery(qp.Parse(query), typeof(Something));
result = NHQuery.List();
Am I doing something wrong or missing anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您没有引用 IndexedEmbedded 集合的字段。 您应该在 MultiFieldQueryParser 中添加以下字段。
这些字段的正确名称应该在 Luke 中可见,并以您应用了 IndexedEmbedded 属性的属性名称为前缀。
编辑:如果默认前缀不符合您的喜好,您可以使用 IndexedEmbedded 属性的前缀参数进行更改
From what i see, you're not referencing the fields for the IndexedEmbedded collections. You should add the following fields in your MultiFieldQueryParser
The correct names for the fields should be visible in Luke, prefixed with the property name you applied the IndexedEmbedded attribute to.
edit: If the default prefixing is not to your liking, you can change it with the prefix argument of the IndexedEmbedded attribute