Combining Relationship Field Filters
Hi Low,
We have the following task/issue at hand:
- We are using the Search add-on to search inside two content channels (one is called Blog and the other one is called Long Form).
- The entries in these channels will have multiple authors in some cases. We have a people channel which holds all authors.
- We are using a relationship field inside each content channel to select the authors of a given content entry.
- In our search form we are planning to have a filter/dropdown which allows the user to narrow down their results by author.
We were planning to use the Relationship filter described in the documentation for Low Search and output the author entry IDs using a channel entries loop/tag. The problem is that to define the filter in the Search form we have to do something like: name="child:cf_blog_authors"
If we do this (the way that I understand it) we would only be filtering by the children of entries from the Blog channel... when we need to filter by children of the entries of both the Blog and Long Form channels.
What is the solution? We are happy to write some custom CI code if that's needed and you direct us a little bit.
We created very similar functionality on another site last year, but in that case there was no requirement for multiple authors, so we used Zoo Visitor to output the "filter by Author" functionality part of the Search (and to glue authors and content altogether).
Thanks,
St
Replies
Low 2 Aug 2014 07:00
OK, so by selecting an author, you want to limit the results by entries that author wrote, spanning 2 channels?
I think a custom filter would be needed for that, since you're basically combining 2 Relationship filters with OR. The filter could take an entry ID (of the author), look up the associated entry IDs for the 2 channels, and return those.
There are no docs for custom filters at the moment (although that's on the list to do), but you can probably find out if you're a bit savvy with programming and look at the /filters/ folder in the Low Search package. For example, the Categories filter, which is the shortest of them all. In short:
- you receive entry IDs
- check for the parameters you need
- perform query (optionally limited by entry IDs given)
- return the filtered entry IDs
The custom filter can live in a /filters/ dir in any 3rd party add-on since the latest Low Search.
If need be, I can also write the filter for you, for a fee. Drop me an email if you're interested in that.
Stoyan Vasilev 7 Aug 2014 23:23
Hey,
We wrote the following filter and it seems to work. Can you have a look and let us know if we are performing any exorcisms?
http://pastie.org/private/ksbqewobosi...
Thanks,
St
Low 8 Aug 2014 09:21
Looks OK, but I don't think you'd need to query the index table. Instead, you could get the channels based on the collections and combine that into a single query to get the results. But that's just optimizing. No exorcisms here.