Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Category/term logic AND inconsistent and OR seemingly not working › Reply To: Category/term logic AND inconsistent and OR seemingly not working
Thanks for the detailed description of you ticket. I will try to explain everything in as much details as possible.
I've actually found a bug in the OR logic, there was a wrong database prefix used, it should be working now. I will still explain a few things if you don't mind 🙂
First thing you need to understand that on the database level, terms (such as product categories) are treated (stored) equivalently regardless of their taxonomy or level. Thus parent and child relations are non-existent until a certain point in the application – but not on database level.
Imagine a big list of ids and names, where one column determines the parent-child relations to each other, another a relation to a certain taxonomy ID, but no other difference.
Explanation of the logics
The logics were build based on the post points of view.
AND – displays posts or custom post types of which the exluded terms are not matching. Excluded terms in this case mean unchecked checkboxes, or excluded categories/taxonomies. More clearly – from the post/product point of view the post terms must be an exact sub-set of the selected terms, and not match any of excluded. If the post doesnt have a related terms, it's displayed.
OR – displays posts or custom post types of which at least one remaining term is matching. Remaining terms are Available terms – Excluded terms – Unchecked terms. From the posts/product point of view it has to match at lease one of the selected terms.
1 – 2. As I explained in the previous section, from the posts point of view the results are correct, because all of them are exact sub-sets of the available terms.
You might ask, why is this logic called AND then? Well, it's definitely not an OR, but not a fully restrictive AND from the users point of view. Let me give you a better example why is it preferred this way:
Imagine a webshop with 3 parent categories: t-shirts, toys, book. All of these categories have 5 sub-categories. Let's assume every product in this shop belongs to a parent and at least one sub-category.
The user want's to search specific items from the t-shirts category, so he selects t-shirts and some sub categories and gets some results. Then he also wants to show some books, so he selects books and some of the book sub-categories. And here is a dilemma. The OR logic is definitely off the table, as it would show everything from t-shirts to books, and the sub-categories are meaningless. The AND logic you described is no useful either, since no product is a t-shirt and a book, so nothing is displayed. However the implemented AND logic will check posts against the whole set of the selected categories – and each matching product must have all their categories in the selected sub-set.
Therefore it will display books and t-shirts matching the selected sub-categories.
3-4. I believe it should work as expected now that I've corrected the typing mistake within the code. I'm also fixing this for the upcoming update.
I find your insight very useful, and I believe I should make a correction and expansion on this part of the plugin. I decided to implement the more restrictive and logic you just described in the upcoming release, because others might find it useful as well. I'm going to re-name the logics to something more intuitive, and an extra chapter of documentation with explanations is incoming.
Let me know if you find anything strange!Best,
If you like my products, don't forget to rate them on codecanyon :)