Filter RavenDB Search Results

自作多情 提交于 2019-12-13 02:55:23

问题


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.

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}

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");

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

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

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

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


回答1:


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

Here is the solution:

ravendb combining Search with Where

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.



来源:https://stackoverflow.com/questions/12011519/filter-ravendb-search-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!