Note that there are some explanatory texts on larger screens.

plurals
  1. POIndexing wish and trade lists in RavenDB
    text
    copied!<p>I've tried many different strategies for indexing my data but can't seem to figure it out by myself.</p> <p>I'm building a database over users and their games. The users can supply the database with games they own and would like to trade as well as a list of games they would like to have:</p> <pre><code>public class Member : EntityBase { public List&lt;Game&gt; TradeList { get; set; } public List&lt;Game&gt; WishList { get; set; } } </code></pre> <p>I'm trying to create and index I can query in the form of "Give me a list of all games (with corresponding members) which have games in their TradeList matching my WishList as well as having games in their WishList matching my TradeList".. and of course, myself excluded.</p> <p>I tried creating a MultiMapIndex:</p> <pre><code>public class TradingIndex : AbstractMultiMapIndexCreationTask&lt;TradingIndex.Result&gt; { public enum ListType { Wishlist, Tradelist } public class Result { public string Game { get; set; } public string Member { get; set; } public ListType List { get; set; } } public TradingIndex() { AddMap&lt;Member&gt;(members =&gt; from member in members from game in member.TradeList select new Result() { Game = game.Id, Member = member.Id, List = ListType.Tradelist }); AddMap&lt;Member&gt;(members =&gt; from member in members from game in member.WishList select new Result() { Game = game.Id, Member = member.Id, List = ListType.Wishlist }); } } </code></pre> <p>And then querying it like this:</p> <pre><code>db.Query&lt;TradingIndex.Result, TradingIndex&gt;() .Where(g =&gt; (g.Game.In(gamesIWant) &amp;&amp; g.List == TradingIndex.ListType.Tradelist) &amp;&amp; (g.Game.In(gamesITrade) &amp;&amp; g.List == TradingIndex.ListType.Wishlist) &amp;&amp; g.Member != me.Id ) </code></pre> <p>But I can't get that to work. I've also looked at Map/Reduce, but the problem I have seem to be getting RavenDB to give me the correct result type.</p> <p>I hope you get what I'm trying to do and can give me some hints on what to look into.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload