Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Complex tire query involving nested models #794

Closed
rahul opened this issue Jul 14, 2013 · 2 comments
Closed

Complex tire query involving nested models #794

rahul opened this issue Jul 14, 2013 · 2 comments

Comments

@rahul
Copy link

rahul commented Jul 14, 2013

Hi guys,

I posted an issue in stackoverflow but it wasn't of any help.

Please take a look at http://stackoverflow.com/questions/17591034/complex-tire-query-involving-nested-models.

The original problem was to figure out how to search for authors having specific tags and who have written certain kind of books having specific tags.

I asked this question in IRC and @xeago suggested that nested mapping is the way to go. I looked up the nested mapping example in the tire repo.

Unfortunately my data isn't as simple as the models given in the example (posts, comments) - or maybe it actually is - I don't know because somewhere I am messing up the tire dsl

I tried something like this,

#inside author.rb
mapping do
  indexes :name, :type => 'string',
  indexes :tags, :properties => { :name { :type => 'string' } },
  indexes :books, :properties => { :type => 'nested', 
                           :book_type => { :type => 'string' }, 
                           :tags => { :name => { :type => 'string' }
                           }
end

# this is to build the datastructure for author
def to_indexed_json
  { :books => books.map(&to_document),
    :tags   => tags.map{ |t| { :name => t.name } },
    :name => name
  }.to_json
end


#inside book.rb
def to_document
   { :book_type => book_type,
     :tags   => tags.map{ |t| { :name => t.name } }
   }
end

What's happening is that the 'nested' property of books as defined in the mapping isn't being respected once Author.import is called and the data is indexed.

I have been stuck at this for 3 days :|

Thank you,
Rahul

@phoet
Copy link
Contributor

phoet commented Jul 15, 2013

@rahul did you have a look at issue #56 ? is that similar to your problem?

@rahul
Copy link
Author

rahul commented Jul 16, 2013

@phoet I came across that issue before and should have paid more attention to it then. I sat down with it today and got it to work. Thank you for your suggestion.

@rahul rahul closed this as completed Jul 16, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants