• Hello,

    it is quite strange. I just found out today that on our site it is not possible to search for posts which have for example 4 categories selected but none of them is Primary (using Yoast for that most probably). If I click and choose the primary category, it is visible in the search right away without any reindexing or whatsoever.

    Could you please check it and fix it if it is on your side? I think that we have around 600 posts with missing primary category looking at the database (hard to say why) and this would be great to have fixed.

    Thank you.

    Regards,
    Karel

Viewing 6 replies - 16 through 21 (of 21 total)
  • Thread Starter keengamer

    (@keengamer)

    Well, in the end, just the shortcodes makes the indexing lasting a long time. Custom fields are fine.

    I am not able to disable just some shortcodes because that is the core functionality of the whole template. I wrote to the template author if he can help, I hope so but hard to say when he will react. The fact is that in this moment we are not able to use your plugin correctly :-(.

    It would be a possible fix if we could for example define which categories to index (then we could select just all the regular posts) or to choose what post types (defined in the template) to use.

    Edit: I am now trying functions.php and excluding some categories…

    Edit 2: ok, it seems to be working fine if I exclude the category. Does it include also all the subcategories? Please see the code below, is it correct? Because I don’t want to use any term, just the parent category GAMES and all subcategories, no matter the term…

    add_filter(‘relevanssi_do_not_index’, ‘rlv_exclude_cat’, 10, 2);
    function rlv_exclude_cat($exclude, $post_id) {
    if (has_term( ”, games, $post_id )) $exclude = true;
    return $exclude;
    }

    Edit 3: no it’s not working. I was checking the search during the index and at the beginning everything was fine. But later on it looks like the correct search was rewritten by a wrong post :-/

    • This reply was modified 4 years, 10 months ago by keengamer.
    • This reply was modified 4 years, 10 months ago by keengamer.
    • This reply was modified 4 years, 10 months ago by keengamer.
    • This reply was modified 4 years, 10 months ago by keengamer.
    Thread Starter keengamer

    (@keengamer)

    Ok, not working. I tried this code

    add_filter(‘relevanssi_do_not_index’, ‘rlv_exclude_cat’, 10, 2);
    function rlv_exclude_cat($exclude, $post_id) {
    if (has_term( ’19’, ‘Games’, $post_id )) $exclude = true;
    return $exclude;
    }

    but after the indexation, it still shows 0 posts excluded. 19 is the category ID. I tried also slug ‘games’, that is not working either. How should it all be written?

    But, I just made few settings. Added exact search to the functions.php. Set default operator as AND. Set partial if no hits for whole words. And right now it seems to be working fine. The biggest issue here was probably the OR operator. Because then any sentence was taken as several words which were found in hundreds or thousands of posts. And I throttled the search as well.

    So I think that it’s almost solved, great would be to tell me how to exclude the category and then it seems fine…

    Plugin Author Mikko Saari

    (@msaari)

    It may be core functionality, but I’m pretty sure it’s triggered by a small number of shortcodes that cause the problems.

    If “games” is a category, the correct code is this:

    add_filter( 'relevanssi_do_not_index', 'rlv_exclude_cat', 10, 2 );
    function rlv_exclude_cat( $exclude, $post_id ) {
        if ( has_term( 19, 'category', $post_id ) ) {
            $exclude = true;
        }
        return $exclude;
    }

    In that case “Games” is a term in the taxonomy “category”.

    Thread Starter keengamer

    (@keengamer)

    Ok, anyway, there is a bug now.

    The indexation has not stopped with this set-up. Games has 2292 posts. The indexation was stuck and was showing hundreds of lines with 0 posts indexed. So I stopped it, clicked building the rest of the index and it shows 2294 remaining posts. Which are probably those to be skipped. But it never ends.

    Also, could you please confirm that it includes all the subcategories? We have around 2600 posts in the subcategories but some of them could be in more of them so 2292 could be correct. But I would like to be sure…

    Thanks.

    Plugin Author Mikko Saari

    (@msaari)

    Well, it depends on has_term(). Looks like has_term() doesn’t include subcategories.

    However, if you’re excluding thousands of posts, relevanssi_do_not_index is not a good tool. As you’ve seen, it can cause neverending indexing. There’s a better way:

    add_filter( 'relevanssi_indexing_restriction', 'rlv_exclude_cat_19' );
    function rlv_exclude_cat_19( $restriction ) {
        global $wpdb;
        $restriction['mysql']  .= " AND post.ID NOT IN (SELECT ID FROM $wpdb->posts AS p, $wpdb->term_relationships AS tr, $wpdb->term_taxonomy AS tt WHERE tr.object_id = p.ID AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND ( tt.term_id = 19 OR tt.parent = 19 ) ) ";
        $restriction['reason'] .= ' No category 19';
        return $restriction;
    }

    This should work better, and will exclude both posts in the category 19 or in one of the child categories of category 19.

    Thread Starter keengamer

    (@keengamer)

    Yeah, this looks better, it even starts indexing the posts without those categories from the very beginning.

    Thanks!

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Missing from search if primary category is missing’ is closed to new replies.