2 category groups include 1 category tree search all children
Hi,
I have build a webshop for a customer of mine, which offers both e-books and normal, paper books (book). I use Low Search to get search in the database. Recently, I added what is called NUR codes to a category-group (http://www.boek.nl/nur). These are essentialy the genres which are available. This category-group has a tree structure (main -> sub -> subsub) categories.
Each (e-)book has multiple category-groups assigned, but I will limit this information here to TYPE and NUR.
My objective is: how can I search on 1 category-group TYPE, and if not empty, the NUR code category?
For example: I search for an e-book width sub nurcode 401. I want to display all the books which are e-books, AND category_id = 401 OR 411 OR 412 OR 413 etc.
Or, If i search on a main category: ebooks AND category_id = 400 OR 401 OR 410 OR 420 OR 421 OR 422 etc.
The NUR codes are displayed in select boxes. If selectbox 1 (main nur) is chosen, select 2 (sub nur) will be shown with all decending categories of the parent etc. etc.
Here is some code which does the searching on (e-books). I am not using encoding of the keywords.
=====
Index search page:
{embed='zoeken/.detail' cat_id='{exp:ebieb:get_cat_id_from_cat_url_title cat_url_title="book"}' parse='inward'}
{embed='zoeken/.detail' cat_id='{exp:ebieb:get_cat_id_from_cat_url_title cat_url_title="ebook"}' parse='inward'}
The function which is executed is a custom function which will get the appropiate category_id for books or e-books.
=====
Embed:
.....
{exp:low_search:results
query="{segment_2}"
status="not closed"
search_mode="all"
category="{embed:cat_id}"
keywords:loose="both"
parse="inward"
}
.......
{/exp:low_search:results}
I am sorry if it is a bit confusing. I hope you get the point.
I need AND and OR at the same time, without a select or dropdown for the TYPE category (AND). The NUR category needs to find itself, and the children en search in those categories (OR), depending on the level chosen.
Hope to hear from anyone if this is possible or not.. And if yes, give me a push in the right direction.
Replies
Low 1 Dec 2015 14:35
You can combine AND and OR categories using Low Search's groups function, part of its Categories filter. The groups are arbitrary and don't have to match an existing category group.
This means you can use parameters like this:
...which means Low Search will return entries that have category (1) AND (5 OR 6 OR 7) assigned to them.
Edwin Van de Pol 1 Dec 2015 15:28
Thanks for your reply!
One question, do I have to get all the children categories myself (nur)? Or can I just give the parent_id, and low search will search in all children categories aswell depending on the parent_id?
Low 1 Dec 2015 15:34
LS (and the native channel:entries tag) will only return entries that actually have those categories assigned. If you only assign a child category to an entry and not its parent, then selecting the parent category will not return entries with only the child category assigned to it.
Of course, this can be remedied by having the 'Auto-assign category parents' option enabled in EE.
Edwin Van de Pol 1 Dec 2015 16:14
Thank again!
Is there a way to auto select it afterwards?
I added the tree later than I imported al the books...
Low 1 Dec 2015 16:16
Not without re-saving each entry, I'm afraid.
Edwin Van de Pol 1 Dec 2015 18:18
I guess that will be custom queries, haha!
Compliments or your reponse time and solution(s)!
Thanks!