Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tgedny

    (@tgedny)

    I think I’ve concluded that the issue is linked to that meta query in some way but what am I looking for in the ‘matches’ loop – should there be a single match for the page in the loop if it only contains 1 instance of the search term? In my initial tests I’ve got a single term on the page but 115 instances of that page in $matches.

    Heres the query in case that helps:

    SELECT relevanssi.*, relevanssi.title * 5 + relevanssi.content + relevanssi.comment * 0.75 + relevanssi.tag * 0.75 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 0.75 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf
    FROM wp_relevanssi AS relevanssi
    LEFT JOIN wp_postmeta
    ON (relevanssi.doc = wp_postmeta.post_id
    AND wp_postmeta.meta_key = ‘location_filter’ )
    LEFT JOIN wp_postmeta AS mt1
    ON ( relevanssi.doc = mt1.post_id )
    WHERE relevanssi.term = ‘tom’
    AND ( wp_postmeta.post_id IS NULL
    OR ( mt1.meta_key = ‘location_filter’
    AND CAST(mt1.meta_value AS CHAR) = ” )
    OR ( mt1.meta_key = ‘location_filter’
    AND CAST(mt1.meta_value AS CHAR) LIKE ‘%159%’ ) )
    AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID)
    FROM wp_posts AS posts
    WHERE posts.post_type IN (‘post’, ‘page’, ‘attachment’, ‘new_releases’, ‘blog’, ‘classified’, ‘featured-publication’, ‘resource’, ‘event’, ‘office_location’)))
    OR (doc = -1))

    Thread Starter tgedny

    (@tgedny)

    I’ve done some more investigation and I think this is actually related to pre_get_posts action I’ve got in my functions.php file. We filter content based on custom field for location so in pre_get_posts we have the following logic:

    $locationFilterMetaQueryArray = array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘location_filter’,
    ‘compare’ => ‘NOT EXISTS’
    ),
    array(
    ‘key’ => ‘location_filter’,
    ‘value’ => ”,
    ‘compare’ => ‘=’
    ),
    array(
    ‘key’ => ‘location_filter’,
    ‘value’ => $selected_location,
    ‘compare’ => ‘LIKE’
    )
    );

    $query->set(‘meta_query’, $locationFilterMetaQueryArray);

    Commenting out this code returns the results as expected. Any ideas? I’m pretty sure the skew in the results is still linked to the ACF plugin in some way but this code seems to be instrumental in the error in calculating the body score.

    Thread Starter tgedny

    (@tgedny)

    I’ve not used any custom code to index those fields. The wp_relevanssi database row for the problematic page with the search term shows the following:

    term: tom
    term_reverse: mot
    content: 1
    title: 0
    comment: 0
    tag: 0
    link: 0
    author: 0
    category: 0
    excerpt: 0
    taxonomy: 0
    customfield: 0
    mysqlcolumn: 0
    taxonomy_detail: null
    customfield_detail: null
    mysqlcolumn_detail: null
    type: post
    item: 0

    I have custom field indexing set to ‘visible’ but shouldn’t I expect to see this reflected in the above database row? In the results this returns as:

    (Search hits: 72 in body, 0 in title, 0 in tags, 0 in comments. Score: 3287.27)

    Switching off custom field indexing seems to give the correct result. This then returns:

    (Search hits: 1 in body, 0 in title, 0 in tags, 0 in comments. Score: 45.63)

    I’ll do some further investigation and see if I can find any way to replicate this without using premium features of the ACF plugin.

    Thread Starter tgedny

    (@tgedny)

    The ACF repeater is part of the Advanced Custom Fields plugin:

    https://www.advancedcustomfields.com/add-ons/repeater-field/

    It appears that Relevanssi hit count is being affected by the number of rows in the repeater field. I’ve tried for other search terms on the same page and they also seem to be affected in the same way.

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