Re: [RavenDB] Multi Map Problem

65 views
Skip to first unread message

Fitzchak Yitzchaki

unread,
Jul 5, 2012, 1:57:57 AM7/5/12
to rav...@googlegroups.com
Why using MultiMap for this?
Search the posts/blogs directly, and than load additional info when you need...

On Thu, Jul 5, 2012 at 8:34 AM, Vinod Kumar Gubbala <vinodt...@gmail.com> wrote:
I have two entities

public class Blog
{
      string BlogId,
      string Title,
      string AuthorName,
      string Description
}

public class Post
{
       string PostId,
       string BlogId, 
       string Title,
       string AuthorName,
       string Content
}


Assuming that i populated those fields
as session.store(blog) and session.store(post)

Now i want to search on combination of those Documents.
Like if search directly on Post, then Post should show up.
Or else if i search on Blog, Blog should turn up then All the List of Posts under blog should turn up.

Kindly someone please help me on this, cause the documention is hardly available on RavenDB

Fitzchak Yitzchaki

unread,
Jul 5, 2012, 4:23:15 AM7/5/12
to rav...@googlegroups.com
I'm not sure that I following you.
Just suggest a blog or a post. Than if the user select a blog, than load its post.
Isn't this what you want?

On Thu, Jul 5, 2012 at 9:09 AM, Vinod Kumar Gubbala <vinod....@campsystems.com> wrote:
I want to do a full text search. Like Suggestions.
When I suggest for post title it should directly show up.
Or else if i go for Blog Title Search,
Then First Blog Hit should turn up and all the Posts (or limit the number of posts). Then second Blog hit and so on.

Oren Eini (Ayende Rahien)

unread,
Jul 5, 2012, 4:34:22 AM7/5/12
to rav...@googlegroups.com

Oren Eini (Ayende Rahien)

unread,
Jul 5, 2012, 6:10:43 AM7/5/12
to rav...@googlegroups.com
See the blog post, it discuss how to do this.

On Thu, Jul 5, 2012 at 1:04 PM, Vinod Kumar Gubbala <vinod....@campsystems.com> wrote:
My result is mixed collection. My search can return a blog or post.
So, if i search for a blog title or post content, the result should be collection of blogs and posts. 


On Thursday, July 5, 2012 2:04:22 PM UTC+5:30, Oren Eini wrote:
I think he is talking about this:

Vinod Kumar Gubbala

unread,
Jul 6, 2012, 4:43:05 AM7/6/12
to rav...@googlegroups.com
I still couldnt make out. Ok i'll give proper example

public class Blog
{
      string BlogId,
      string Title,
      string AuthorName,
      string Description
}

public class Post
{
       string PostId,
       string BlogId, 
       string Title,
       string AuthorName,
       string Content
}

blog1 = {
    BlogId = 1,
    Title = 'RavenDB',
    AuthorName = 'vinod',
    Description='Examples in RavenDB'
};

blog2 = {
    BlogId = 2,
    Title = 'Lucene',
    AuthorName = 'vinod',
    Description='Examples in Lucene'
};


post1 = {
    PostId = 1,
    BlogId = 1, 
    Title = 'Storing a entity',
    AuthorName = 'Kumar',
    Content = 'This is the content having for the example storing an entity'
};

post2 = {
    PostId = 2,
    BlogId = 1, 
    Title = 'Multi Mapping',
    AuthorName = 'Vinod',
    Content = 'This is the content having for the example for multi mapping'
};

post3 = {
    PostId = 3,
    BlogId = 2, 
    Title = 'Adding Document',
    AuthorName = 'Vinod',
    Content = 'This is the content having for the example for adding documents'
};


post4 = {
    PostId = 4,
    BlogId = 2, 
    Title = 'Quering',
    AuthorName = 'Kumar',
    Content = 'This is the content having for the example for Quering Documents'
};


Now
query = Vinod
Results:
blog1
post1
post2
blog2
post3
post4

query = RavenDB
Results:
blog1
post1
post2

query = kumar
Results:
post1
post4

This is my requirement. Can somebody guide me. The like provided cannot search as it can for me!!!
I want to get the posts associated with the blogs as i have paging in my application,
i want to completely make it through search.


Matt Warren

unread,
Jul 6, 2012, 5:22:28 AM7/6/12
to rav...@googlegroups.com
Just to clarify, you want to do the following
  1. Allow searching against the AuthorName, Title and Description fields in either Blog or Post docs
  2. If a search matches a Blog, also return the Post docs associatated with that Blog
  3. If a search just matches a Post, only return the Post
Is this correct? 

Vinod Kumar Gubbala

unread,
Jul 6, 2012, 5:25:15 AM7/6/12
to rav...@googlegroups.com
Exactly...

Matt Warren

unread,
Jul 6, 2012, 5:30:02 AM7/6/12
to rav...@googlegroups.com
Okay, items 1) and 3) are covered by Multi-Map, but to make Item 2) work you'll need to use something like TransformResults (aka Live Projections), see the bottom of this page http://ravendb.net/docs/client-api/querying/handling-document-relationships.

Oren Eini (Ayende Rahien)

unread,
Jul 6, 2012, 2:41:21 PM7/6/12
to rav...@googlegroups.com
Or just issue two queries.

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 5:00:26 AM7/10/12
to rav...@googlegroups.com
@Matt: I'm not looking for TransforrnResults. As you can see I want the results as entites.
Means i want to have blog and post entities directly than a wrapped entity. As i understood transformresult will wrap our result.
But what i want is when i index Post like
AddMap<Post>(posts => from post in posts
                                         select new
                                         {
                                             Query = new[]
                                             {
                                                 post.Title,
                                                  post.Content,
                                                  post.AuthorName
                                             }
                                         });
i want to add some more information in index as
AddMap<Post>(posts => from post in posts
                                        join blog in blogs on blog.BlogId equals post.BlogId
                                         select new
                                         {
                                             Query = new[]
                                             {
                                                 post.Title,
                                                  post.Content,
                                                  post.AuthorName,
                                                  blog.Title,
                                                  blog.AuthorName, 
                                                  blog.Description
                                             }
                                         });

Hopefully some you understood my point...
Maybe my understanding is bad, but an example code in my context would help me out.

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 5:04:49 AM7/10/12
to rav...@googlegroups.com
What is it that you are trying to _do_ ?

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 5:44:27 AM7/10/12
to rav...@googlegroups.com
I want to create an index. AbstractMultiMapIndexCreationTask<SomeType>

AddMap<Blog>(blogs => from blog in blogs
                                             Query = new[]
                                             {
                                                 post.Title,
                                                  post.Content,
                                                  post.AuthorName,
                                                  blog.Title,
                                                  blog.AuthorName, 
                                                  blog.Description
                                             }
                      });


AddMap<Post>(posts => from post in posts
                                        join blog in blogs on blog.BlogId equals post.BlogId
                                         select new
                                         {
                                             Query = new[]
                                             {
                                                 post.Title,
                                                  post.Content,
                                                  post.AuthorName,
                                                  blog.Title,
                                                  blog.AuthorName, 
                                                  blog.Description
                                             }
                                         });

The underline part is the one i'm missing to achieve...... :-(

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 5:46:48 AM7/10/12
to rav...@googlegroups.com
So that when i do session.Advanced.LuceneQuery<object, IndexingTask>()
                                .Search("Query", queryText);
The result as specified earlier should turn up.
I mean query = Vinod
Results:
blog1
post1
post2
blog2
post3
post4

query = RavenDB
Results:
blog1
post1
post2

query = kumar
Results:
post1
post4

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 5:56:23 AM7/10/12
to rav...@googlegroups.com
No, you are focusing on the actual technical solution.
What is the business problem you want to resolve?

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 6:07:09 AM7/10/12
to rav...@googlegroups.com
If i search on Blog Details 
then Blog and corresponding posts should come up.

If i search on Post details
then posts should turn up

The textbox is single and it has pagination.

So i cannot go for search on blog and get all the posts as pagination wont work

So when i do a search on RavenDB it should get me the results of mixed entites.

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 6:16:15 AM7/10/12
to rav...@googlegroups.com
Did you see this post?

You will make two queries.
If you got a blog, you'll issue a query for the relevant posts.
If you got a post, you'll show the post

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 6:28:47 AM7/10/12
to rav...@googlegroups.com
Yeah i read that.. But i've paging. issueing a query to get relevant posts would kill it 
like if my page size is 10 and if i get 10 blogs for the hit and if each blog has more than 10 posts in it,
then there would be too many queries.

Now, the bad thing about this is that this won’t allow me to query for cross entity values, so it would be hard for me to query for the cars in Hadera owned by Ayende. But in most cases, that isn’t really a requirement. We just want to be able to search by eitherone of those, not all of them. 

But i want the part you thought are not required.....

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 6:30:11 AM7/10/12
to rav...@googlegroups.com
I can't follow your reasoning.

Assume that I search for "blog", all the blogs matches this query.

What would be the output (page size 10, all blogs have 6 posts)

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 6:34:05 AM7/10/12
to rav...@googlegroups.com
PAGE1
blog1
post1-1
post1-2
post1-3
post1-4
post1-5
post1-6
blog2
post2-1
post2-2

PAGE2
post2-3
post2-4
post2-5
post2-6
blog3
post3-1
post3-2
post3-3
post3-4
post3-5

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 6:44:50 AM7/10/12
to rav...@googlegroups.com
Do the two queries method, and use a notion of Skipped Results, like we do in the indexes, to know where in the query you are.

Vinod Kumar Gubbala

unread,
Jul 10, 2012, 7:02:30 AM7/10/12
to rav...@googlegroups.com
How can we skip results if we dont know the number of results read earlier through search and also without knowing the last entry was a blog or post.
Two much of logic should incorportated to come with the solution. And also we have another data to save all the last read etc to achieve that.

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 7:08:50 AM7/10/12
to rav...@googlegroups.com
You do it like this:

 
 
foreach(Var item in ExecuteQuery(queryState.QueryPos, queryState.Take))
{
  if(item is Post)
  {
    queryState.BlogPos =0;
    queryState.QueryPos+=1;
    results.Add(item);
  }
  else // blog
  {
    results.Add(blog);
    var posts = ExecuteQuery(blog,queryState.Take - results.Count);
    
    results.AddRange(posts);
     queryState.BlogPos +=posts.Count;
    if(result.Count >= queryState.Take)
      return results
    
    queryState.QueryPos+=1;
  }
}

return results;
Reply all
Reply to author
Forward
0 new messages