gernotkogler/xapian_db

Indexing many-to-many association

Closed this issue · 1 comments

I have two models. One called Person and the other one called Role. There is a many-to-many association between persons and roles, meaning persons can have multiple roles.

Let's say, we have a person 'Jack' with two roles. I'm just concerned about the ids of the roles, so let's say that Jack has roles 1 and 3. I defined a method in the class Person that retrieves the role ids as an array of numbers. The blueprint to the person index looks as follows:

XapianDb::DocumentBlueprint.setup Person do |person|
  # some attributes
  person.attribute :role_ids
  # more attributes
end

My goal is to do a facted search on persons. I'm calling Person.facets :role_ids, 'Jack'. What I get is the following hash:
{[1,3] => 1}

This means that there is 1 person who has the roles 1 and 3. Unfortunately that's not what I wanted. I don't care about the combination of roles, I care about the single roles. What I want as a result is "there is 1 person with the role 1 and 1 person with the role 3". Or in hash form:
{1 => 1, 3 => 1}

Is there any way to retrieve such a result?