Category/term logic AND inconsistent and OR seemingly not working

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Category/term logic AND inconsistent and OR seemingly not working

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6443
    divabanana
    divabanana
    Participant

    The issue: Category/term AND logic not consistent and category/term OR logic not returning any results. Or I’m just very much confused!

    The search is set up to search custom post type Product with only search in title on as it is a woocommerce store and I only want to be able to search for products by title (ie product name).

    Filtering is set by taxonomy of ‘product – Product Categories’ and only shows parent categories – of which the products are direct members.
    E.g. peccatte superior rosin is a product member of the subcategory ‘violin rosin’ but also the parent category of ‘violin’ in order for the filter by parent category to work.

    The reason I need category filtering is due to the nature of the stock which has quite a few items which are of the same name but available for different categories.
    Also, a large number of items (most in fact) are items that are members of multiple parent categories.
    E.g. dominant is the name of seperate products in violin, viola and cello categories, and peccatte superior rosin is a single product that is a member of the categories ‘violin’, ‘viola’ and ‘cello’.
    I need a customer to be able to search for a product and have results returned within the chosen category/categories… as simple as that!

    (Show exact matches is OFF and Keyword logic is set to OR.)

    Consistency of category/term logic when set to AND:
    1) With category/term logic set to AND and search for product ‘dominant’ which has seperate products in violin, viola, cello and double bass categories.
    With violin only selected I get products with ‘dominant’ in the title in the violin category.
    With viola only selected I get products with ‘dominant’ in the title in the viola category.
    With violin AND viola selected I get products with ‘dominant’ in the title from the violin category plus products with ‘dominant’ in the title from the viola category.
    So it’s returning ‘dominant’ in violin OR viola.
    Shouldn’t it only be returning ‘dominant’ items which are in violin AND viola categories.
    There is no item with dominant in the title which is in both violin AND viola categories…
    (see attached screenshot searchANDunexpected)

    2) With category/term logic set to AND and search for product ‘peccatte’ which is one single product that is in multiple categories (violin, viola and cello).
    If I select just violin it returns no result (good).
    If I select violin, viola and cello (all the categories it is in), I get the correct result.
    This is the AND as I’d expect it – returning ‘peccatte’ items which are in in violin AND viola AND cello categories.
    (see attached screenshot searchANDpeccatte)

    What I actually need for the site search is the category/term logic set to OR though so customers get to peccatte with only the violin category selected (as it is available in that category).

    3) With category/term logic to OR and search for product ‘dominant’…
    With violin only selected I get nothing returned. It should return the products with ‘dominant’ in the title within the violin category.
    With violin and viola selected I should get results of ‘dominant’ in violin along with ‘dominant’ in viola.
    For both I get no results returned.
    (see screenshot searchORdominant)

    4) With category/term logic to OR and search for product ‘peccatte’…
    With violin only selected I get no result (I should as it is in that category)
    With violin and viola selected I still get nothing. I should as it should be returned from ‘peccatte’ in violin category OR ‘peccatte’ in viola category.
    With all the categories peccatte is in selected… I still get nothing.
    (see attached screenshot searchORpeccatte)

    You can test these out on the website frontend. I have set up 2 search pages, one for AND (website.com/searchand/) and one for OR (website.com/searchor/).
    Both have identical settings except for the category/term logic which is set accordingly.

    Any ideas?!

    Attachments:
    You must be logged in to view attached files.
    #6448
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #6452
    divabanana
    divabanana
    Participant

    Wow! Thanks for such an awesome response!
    All clear on the AND functionality now and the OR working perfectly.

    Best support response ever.

    #6453
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank you very much, it’s my pleasure helping my customers 🙂

    Feel free to rate the plug-in on your codecanyon downloads page.

    I just saw your awesome comment on codecanyon as well, I will leave a thank you note there as well.

    Have a nice day!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.