AND Logic Operator not working properly

Home Forums Product Support Forums Ajax Search Pro for WordPress Support AND Logic Operator not working properly

This topic contains 9 replies, has 2 voices, and was last updated by STEMadvocacy STEMadvocacy 6 years, 6 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #14656
    STEMadvocacy
    STEMadvocacy
    Participant

    Hello
    I have noticed that the search results by category are not responding to the AND logic operator that i have enabled. It seems like it is stuck in the OR position based on the results i am seeing from ajax pro since the number of results goes up when i select more than 1 category. Furthermore, the category selection is not as strict as it should be. Posts whose category is not selected still show up. There no error messages in the back end.
    any help appreciated as soon as possible.

    admin user credentials log in page: http://www.storiesinscience.org/wp-admin

    STEM

    #14665
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Stem,

    If I understand correctly you are reffering to the category filter operator: https://i.imgur.com/MdqtqRW.png
    Please correct me if I’m wrong. In your case however that operator is not in use, because that is to set how the comparision should be made between different taxonomy groups. Since you use only one taxonomy (post categories) as filter, that does not affect the outcome. The rest of the configuration looks okay on that page.

    I believe you want to display results from those categories visible in the front-end filter? So basically results from ‘Sex’ and ‘Who is’ main and sub categories, based on selection. The problem here is that there are many other categories, and unless the search is told excplicitly to ignore those, it will still include them as results, since the categories in the filter have no connection with the items in the other categories. Basically items not affected by the chosen category filters will still be visible as results. In most use-cases this is an expected behavior, that is why it’s set as default.

    To change that, there are thre possible solutions:
    1. Change the individual term logic to ‘At least one selected term should match’: https://i.imgur.com/vrzRq81.png
    This is different in a sense that at least one of the choosen terms has to match. However this is possibly not the best solution.

    2. To tell the search which categories to restrict the results to. In your case it would be ‘Sex’ and ‘Who is’ and all of the desired sub categories you want. You can configure this on the Advanced Options -> Exclude results panel: https://i.imgur.com/P3l1SOf.png
    This will only allow results from categories which match any of the selected categories.

    3. Similarly to solution 2., it is possible to excplicitly define which categories to exclude (just above the previous ‘include’ option): https://i.imgur.com/ihB9HUo.png
    This is the most strict option, as similarly, if any of the items match any of the selected categories, it is automatically excluded.

    Depending on your requirements, I would recommend either solution 2 or solution 3, or combination of the two.

    Best,
    Ernest Marcinko

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


    #14674
    STEMadvocacy
    STEMadvocacy
    Participant
    You cannot access this content.
    #14684
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Fanuel,

    It was because this option was set incorrectly: https://i.imgur.com/qAcVDr0.png
    I have reverted it back to it’s default state. Now I don’t see any results from the un-checked categories.

    I also excluded the remaining categories under the ‘Who is’ parent category, as I’m assuming you don’t want any results from them whatsoever – and without exclusions it is actually possible that if no filters match, it could be still match an inclusion: https://i.imgur.com/8o14OWg.png

    Currently, it will only match within the choosen subset, and if only each selection strictly matches.

    Best,
    Ernest Marcinko

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


    #14721
    STEMadvocacy
    STEMadvocacy
    Participant
    You cannot access this content.
    #14733
    STEMadvocacy
    STEMadvocacy
    Participant

    Hi Ernest

    Just wanted to check in. Any thoughts?

    Fanuel

    #14745
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Fanuel,

    Sorry for the late response, I had some importand business related things to take care of yesterday.

    It is more-less how it should work right now, and I’ve just tested, and I believe there are no results from ‘male’ category, if I select ‘female’ and ‘faculty’: https://i.imgur.com/lwHtUFK.png

    However you are right, there will be results from faculty category, that are not in female nor male category, and not on the un-checked category list. The main issue here is that usually custom category groups are defined as custom taxonomies. So for example checking ‘female’ and ‘faculty’ means to match female and faculty, or female where faculty is not defined, or faculty where female is not defined.

    I should however add an option to restrict results to exactly match the selections, and nothing else (so faculty and female, nothing else at all), so results that does not have any of the categories defined. I’m not even sure how this never came up before. There are so many ways people want the filters to work, that sometimes I get lost with all the ways of configuration.

    Anyways, can you by any chance add temporary FTP details to this ticket? I would like to experiment with the search code to see if there is a simple resolution to only allow ‘selected’ categories from the list. Your content seems to be perfect for testing this out, if you don’t mind 🙂

    Best,
    Ernest Marcinko

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


    #14754
    STEMadvocacy
    STEMadvocacy
    Participant
    You cannot access this content.
    #14784
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Fanuel,

    Sorry about the delay, but I had to make sure I come up with a solution on my test servers first, before going on testing it on yours.

    I believe I have found a solution. I’ve made it to a new option as well: https://i.imgur.com/hkMeXQ9.png
    As a test, I have selected ‘Female’ and ‘Faculty’, and there are only results that match at least BOTH of these categories (or others too, but these 2 must match).
    As a counter example, if I choose ‘Male’, ‘Female’ and ‘Faculty’, there is a contradiction, as no posts match all 3 categories, so no results are shown.

    There is however a small issue there (but I solved it as well): I see you have the ‘Sex’ and the ‘Who Is’ categories also in the filter list, but there are no posts within those categories. Meaning if you choose any of them, then no results will be shown – because the logic now strictly displays results that match ALL of the categories exactly, but since there are no items within those, nothing will show.

    One solution is to simply not use those at all, another is to place everything that is in male or female into the ‘Sex’ parent category as well, but that could take some time.
    There is a third solution, and since you gave me FTP access, I have made a custom filter code, which I placed to the functions.php file in your active theme directory. This code basically detects if the ‘Sex’ or the ‘Who is’ category is selected, and removes them from the actual filter code, solving this problem. For future reference, this is the code I have placed there:

    add_filter('asp_query_args', 'asp_change_tax_query_args', 10, 3);
    function asp_change_tax_query_args($args, $search_id, $options) {
      $remove = array(128, 122);
      if ( is_array($args['post_tax_filter']) ) {
        foreach ( $args['post_tax_filter'] as $k=>&$v ) {
          if ( is_array($v['include']) && $v['taxonomy'] == 'category' ) {
            $v['include'] = array_diff($v['include'], $remove);
          }
        }
      }
      return $args;
    }

    Now the search should display results that match all the selected categories, and if any of the selected ones does not match the potential result, it will not show up.

    I hope this helps!

    Best,
    Ernest Marcinko

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


    #14807
    STEMadvocacy
    STEMadvocacy
    Participant

    Hi Ernest,

    Thank you so much. This is beyond perfect. The search works great! Waw! I think this feature will be critical when we have 100s of stories.

    Will keep you posted with updates!

    Fanuel

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

The topic ‘AND Logic Operator not working properly’ is closed to new replies.