过滤 RavenDB 搜索结果 [英] Filter RavenDB Search Results

查看:32
本文介绍了过滤 RavenDB 搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 IRavenQueryable.Search 方法返回有效搜索结果的查询.但是,我想通过 .Where 方法调用进一步过滤这些结果,以便然后过滤搜索结果以仅包括那些具有匹配 ProjectId 的结果.

I have a query that returns valid search results using the IRavenQueryable.Search method. However, I want to further filter those results via a .Where method call such that the search results are then filtered to only include those that have the matching ProjectId.

我的对象结构是一组 Project 实体,每个实体包含一组 Issue 实体.

My object structure is a set of Project entities each containing a collection of Issue entities.

我的索引创建了一个问题搜索结果的投影,如下所示:

My index creates a projection of Issue Search Results that looks like:

{Id、Key、Summary、Description、ProjectId、ProjectKey、Query}

{Id, Key, Summary, Description, ProjectId, ProjectKey, Query}

Query 属性是关键字搜索使用的对象[].

The Query property is an object[] that is used by the keyword search.

当我运行关键字搜索时:

When I run the keyword search:

var results = session.Query().AsProjection().Search(x => x.Query, "some key word");

var results = session.Query().AsProjection().Search(x => x.Query, "some key word");

我得到了正确的结果.但是当我尝试也应用 Where 方法时:

I get the right results back. But when I try to also apply the Where method:

results = results.Where(i => i.ProjectId == SelectedProject.Id);

results = results.Where(i => i.ProjectId == SelectedProject.Id);

它不会过滤结果,而是包含具有匹配项目 ID 的所有其他结果.

It does not filter the results, but instead includes all other results with matching Project Id's.

在这种情况下,强制 Linq 或 RavenDB 的 IRavenQueryable 应用 AND 而不是 OR 的正确方法是什么?

What is the correct way to force Linq or RavenDB's IRavenQueryable to apply an AND instead of an OR in this scenario?

推荐答案

发布这个问题后,我设法在 stackoverflow 的其他地方找到了答案.

After posting this question I managed to find the answer elsewhere on stackoverflow.

解决办法如下:

ravendb 结合搜索和 Where

简而言之,Search 方法提供了一个额外的可选参数 [options],以允许您指定如何将搜索与查询中的其他 where 子句结合起来.它默认为 SearchOptions.Or 因此您需要将其显式设置为 options:SearchOptions.And.

In a nutshell, the Search method provides an extra optional parameter [options] to allow you to specify how the search is combined with other where clauses in the query. It defaults to SearchOptions.Or so you need to explicitly set it to options: SearchOptions.And.

这篇关于过滤 RavenDB 搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆