Filter RavenDB Search Results

2019-07-27 14:27发布

问题:

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.



标签: ravendb