• Resolved the_lar

    (@the_lar)


    Hi,

    I’m setting up Algolia to test on my site and have been working on autocomplete to get contents of ACF fields into my search results – this has been achieved with plenty of help, https://www.ads-software.com/support/topic/testing-algolia-on-staging-site-questions/

    Now I need to make my Search page reflective of this too. I’m using the Use Algolia with instantsearch.js option on my Search page settings. But when I hit return on the word winklepicker which is a unique word that I know only appears on my homepage in an ACF field, whilst it shows up in autocomplete, when I go to the search results page, I have zero results.

    My understanding is that instantsearch just uses the wp_searchable_posts index – is that correct?

    Looking at that index, I can see that it does indeed contain the acf_content on the homepage record which I added in previous filter algolia_searchable_post_shared_attributes when I was getting autocomplete working. But it seems that this content isn’t being considered by instantsearch. How do I make instantsearch look at content and acf_content for my Pages? I did notice this filter algolia_searchable_post_content in the wiki, but I’m not sure how I’d use it or if that’s the correct route?

    Also, my Search page is displaying results from Products and other post types as well, which I currently don’t want as I’m only testing pages. I don’t think there is any way for me to exclude post types from the Search page like I can do with autocomplete in the UI is there? I can see that my wp_searchable_posts index is 21K records whereas I only have 80 pages, so that’s probably the reason. How do I go about just sending pages to this index?

    Many thanks

    • This topic was modified 1 year, 2 months ago by the_lar.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Good day

    Throwing out some extra information for the overall scope of what I’m seeing.

    If your Autocomplete settings are using “All Posts”, the first item listed, then it would also be querying from wp_searchable_posts index. However, if it’s using anything else, like perhaps “Pages” then it’s querying from multiple indexes, for example wp_posts_page and each index has its own individual configurations.

    Understandably by name, the Search Page and wp_searchable_posts are going to index all post types that aren’t set to exclude_from_search => true for the registration settings.

    That said, there ARE filters available to limit the post types that go into this index. If I recall right, you can use this filter below, and have it return just page for the moment.

    // Add a searchable posts index.
    $searchable_post_types = get_post_types(
    	array(
    		'exclude_from_search' => false,
    	),
    	'names'
    );
    $searchable_post_types = (array) apply_filters( 'algolia_searchable_post_types', $searchable_post_types );

    However, you’d still need to make any configuration changes to match any made on wp_posts_page index, to wp_searchable_posts. THAT SAID though, as you mention above, you’re already using the searchable posts based filters already in places, so that may not be needed as much.

    The fact that content is being found for the autocomplete and not instantsearch says something isn’t quite matching somewhere.

    Thread Starter the_lar

    (@the_lar)

    Hi again @tw2113 – sorry, feel like I’m being such a pain but I’m so close!!

    So limiting searchable_posts to just pages now works thanks to the above:

    add_filter( 'algolia_searchable_post_types', function( array $post_types ) {
        $post_types = ['page'];
    
        return $post_types;
    } );

    So now my wp_posts_page index and my wp_searchable_posts index are both the same and just contain pages – so that’s great for now whilst I’m getting up and running.

    The biggie now is that on my Search page, instantsearch is not seeing acf_content which I’ve verified IS present on the searchable_posts index – do I need to configure instantsearch.php somehow so that it searches this field?

    Thread Starter the_lar

    (@the_lar)

    Oh I think I’ve found something…

    OK so on my wp_posts_page index – in Algolia under configuration, acf_content is present. However on wp_searchable_posts it’s not!

    I guess that is the reason? But when I try to Add a Searchable attribute in the Algolia admin, acf_content is not available – even though it is present at least on some of the records?

    Any ideas?

    Thread Starter the_lar

    (@the_lar)

    @tw2113 – figured it out. I just needed to add add_filter( 'algolia_searchable_posts_index_settings', '\App\my_posts_index_settings' ); to my filters.php, then in instantsearch.php I changed to this:

    <# if ( data._snippetResult['acf_content'] ) { #>
              <span class="suggestion-post-content ais-hits--content-snippet">data._snippetResult['acf_content'].value</span>
              <# }else if( data._snippetResult['content'] ) { #>
              <span class="suggestion-post-content ais-hits--content-snippet">data._snippetResult['acf_content'].value</span>
              <# } #>

    Works! ??

    • This reply was modified 1 year, 2 months ago by the_lar.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Correct on everything above, from what I’m seeing. I believe the biggest wrench here was probably the separate indexes going on, and that each gets their own settings.

    Now that it looks like you have the same settings going to each, things are working better.

    You know where to find us for further questions.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search page not matching autocomplete results’ is closed to new replies.