Reverse Search on string[] with RavenDB

68 views
Skip to first unread message

Stacey

unread,
Feb 27, 2012, 1:55:44 PM2/27/12
to rav...@googlegroups.com

Given a very simple string[], I am trying to accomplish the following in a simple LINQ syntax withRavenDB.

public class Item {
   public string[] Tags { get; set; }
}
var list = new List<Item> {
  new Item { Tags = new string[] { "one", "two", "three" } },
  new Item { Tags = new string[] { "one", "two" } },
  new Item { Tags = new string[] { "one" } }
};

And then I can easily query this, like so;

var items = session.Query<Item>().Search( n => n.Tags, "one" ).Take(3).ToList();

This lets me easily get all of the items with a tag in their string[] that I want, but I want to do the opposite (obviously, for my use case the scenario is a lot more complicated, I am condensing it for this example).

I want to write a LINQ query that will work with Raven that will give me all of the objects that do not have a given tag. Like an 'inverted' search.

Contains() was removed from RavenDB, so I cannot use an inverse boolean on it. Until now, I just have to do a query, then use another LINQ command on the result, which I feel is highly inefficient. Does anyone know how to accomplish this?

I am also posting this on Stackoverflow as well. 

Oren Eini (Ayende Rahien)

unread,
Feb 27, 2012, 3:46:07 PM2/27/12
to rav...@googlegroups.com
See the answer in stack overflow.

Where(x=> !x.Tags.Any(tag => tag == "one") )

Stacey Thornton

unread,
Feb 28, 2012, 11:11:16 AM2/28/12
to rav...@googlegroups.com

Is it possible to do this with the Search feature?

Oren Eini (Ayende Rahien)

unread,
Feb 28, 2012, 11:15:17 AM2/28/12
to rav...@googlegroups.com
Starting with the next build, it will be:

.Search(x=>x.Tags, "one", options: SearchOptions.Not)

Stacey Thornton

unread,
Feb 28, 2012, 11:17:25 AM2/28/12
to rav...@googlegroups.com

This is fantastic!

Stacey Thornton

unread,
Feb 28, 2012, 1:38:27 PM2/28/12
to rav...@googlegroups.com

This is very exciting stuff. Is there any estimate when the next stable build will be?

Oren Eini (Ayende Rahien)

unread,
Feb 28, 2012, 1:42:09 PM2/28/12
to rav...@googlegroups.com
Gimme an hour or so.
Reply all
Reply to author
Forward
0 new messages