• Resolved schwindt14

    (@schwindt14)


    I’ve setup your plugin to index my custom post type “products” as well as the custom taxonomy for product categories.

    The Autocomplete functionality correctly displays my “products” in the search results, but only the title, because there is no default “content” field for this post type, but rather there is an ACF field called “product_description”. I want that “product_description” to display in the Autocomplete results.

    I have successfully followed your instructions to push the “product_description” ACF field out to the Algolia platform, and I can see that field in the Algolia UI, so that part is good.

    My problem is in getting that “product description” added into the Autocomplete output in place of the default “content”.

    I tried editing the autocomplete.php file in various ways (per some online documentation) to replace the references to “content” with references to “product_description” but that doesn’t seem to be working.

    Here’s what I currently am trying in autocomplete.php for lines 22-35:

    <a class="suggestion-link" href="{{ data.permalink }}" title="{{ data.post_title }}">
        <# if ( data.images.thumbnail ) { #>
            <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}">
        <# } #>
        <div class="suggestion-post-attributes">
            <span class="suggestion-post-title">data._highlightResult.post_title.value</span>
            <# if ( data._snippetResult['product_description'] ) { #>
                <span class="suggestion-post-content">data._snippetResult['product_description'].value</span>
            <# } #>
        </div>
        <?php
        do_action( 'algolia_autocomplete_after_hit' );
        ?>
    </a>

    Again, I basically just replaced “content” references with “product_description”. But that fails to product any result, even though the data is out in the Algolia platform.

    Here is the page: https://wordpress-1341165-4918007.cloudwaysapps.com/search-test/

    What am I missing?

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

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

    (@tw2113)

    The BenchPresser

    Hi @schwindt14

    Looks like you have most of it but you didn’t set the product_description to be a snippeted attribute.

    You can see some sample code at https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Advanced-Custom-Fields#make-custom-fields-searchable that adds an attribute to the snippet setting and how much to snip. You’ll want to do the same here for your field

    Thread Starter schwindt14

    (@schwindt14)

    Hi Michael! Thanks for such a fast response.

    I actually stumbled onto that documentation after posting here and I now have the following as a snippet:

    https://codefile.io/f/VnvF0D3qZ5

    Wherein I replaced “speaker” and the attribute “bio” in the example with my “products” type and the attribute “product_description”.

    In fact in the Algolia platform after re-indexing I can now see “product_description” set in the “Snippeting” screen with a count of 50.

    But still not showing in my autcomplete results. What am I still missing?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Something to keep in mind with settings like this is that saving it in code doesn’t automatically push the settings to Algolia and the dashboard.

    That’s why you see various “Push settings” buttons in the admin UI. Those push your code customizations to the associated indexes.

    That said, if you’ve been doing any previous settings updates via the Algolia dashboard directly, clicking those buttons would overwrite those existing changed settings. You can add the attributes for snippeting via their UI as well, just in case you do have existing customizations.

    All in all, settings need pushed one way or another to get them in place and this working.

    Thread Starter schwindt14

    (@schwindt14)

    Yeah, I think that’s what has me confused. Out of the gate, I actually tried configuring snippets through the Algolia UI and thought that doing it there would cause it to be reflected on my website autocorrect results, but it didn’t (unless there is something I need to do to “push” stuff from Algolia to my site). When that didn’t work, I got into the techniques for configuring that from my site end.

    After your last message, I did go in and “push” settings in your plugin, both for my “products” type, and also re-indexed that type on the same screen, and then I also jumped over to the “search page” screen that has the “Re-index All Content” and its own “Push Settings” screen. So I did a “push” and a re-index on both screens.

    After all this, the product_descriptions are still showing indexed properly in the Algolia UI, and the snippeting appears correct with title and product_description in the Snipetting settings in Algolia, but it is not reflected in autocorrect results on my site.

    From what you can see in my posts above, should it be working by now? Really love the idea of using Algolia, sooooo much faster, and would hate to abandon it just because I’m missing a code step due to my amateurishness.

    • This reply was modified 1 month, 1 week ago by schwindt14.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    When you visit the configuration in Algolia, is the attribute listed? Example section below

    Screen Shot

    Based on the XHR results coming in when i perform a query, highlighting is configured, but snippets aren’t yet, at least for the wp_posts_products index

    Screen Shot

    Thread Starter schwindt14

    (@schwindt14)

    Here’s what I see in Algolia:

    It makes me think there’s something perhaps in my autocomplete.php edits? Which are here, just in case it helps, where I removed the “content” references and added in “product_description”, although the content item does still appear automatically in the Algolia Snippeting settings at the top.

    <a class="suggestion-link" href="{{ data.permalink }}" title="{{ data.post_title }}">
        <# if ( data.images.thumbnail ) { #>
            <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}">
        <# } #>
        <div class="suggestion-post-attributes">
            <span class="suggestion-post-title">data._highlightResult.post_title.value</span>
            <# if ( data._snippetResult['product_description'] ) { #>
                <span class="suggestion-post-content">data._snippetResult['product_description'].value</span>
            <# } #>
        </div>
        <?php
        do_action( 'algolia_autocomplete_after_hit' );
        ?>
    </a>

    I’m stumped.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Which index is that screenshot from? You potentially have many available.

    I’m not worried about the template right now as the latter screenshot was showing there’s no snippet data to show cause something isn’t yet configured correctly at the index level.

    Thread Starter schwindt14

    (@schwindt14)

    Thank you for sticking with me on this. That screenshot was from an index called “wp_posts_products” and I do have others, I see now. I’ll attach the list:

    This may or may not be related, but I’ll add that I have 257 products, so I find it odd that the wp_posts_products index only shows exactly 100 records.

    • This reply was modified 1 month, 1 week ago by schwindt14.
    Thread Starter schwindt14

    (@schwindt14)

    Ignore that last sentence. I re-indexed from the plugin side (for post type “products”) and now it shows 257 records for that index in Algolia.

    Thread Starter schwindt14

    (@schwindt14)

    Here’s something. If I go to Algolia and go to the API log, it shows requests by header, then request body, then response body, and here is an example of a request body for when I typed “dish”:

    {
    "query": "dish",
    "hitsPerPage": 5,
    "attributesToSnippet": [
    "content:10"
    ],
    "highlightPreTag": "__ais-highlight__",
    "highlightPostTag": "__/ais-highlight__"
    }

    So does that indicate that my site is requesting only 10 words from the “content” field as snippeted attributes?

    Just a thought…

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    i believe so, yes.

    curious where that 10 is coming from as we default to 30 for autocomplete based indexes, and your previous screenshot shows 30 too.

    Thread Starter schwindt14

    (@schwindt14)

    Perhaps it is from this place in the autocomplete.php file (which isn’t a section I altered, I don’t think):

    Thread Starter schwindt14

    (@schwindt14)

    Okay that fixed it. I had to alter the circled line above to say “product_description: 30” and now it is showing.

    Question — Is that how it is properly done? Should I have had to edit that? Or should I just be able to edit in Algolia and have it reflect on my website?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Good catch with that spot. I forgot that config spot was there.

    I have to believe providing a value there overrides the value at the configuration level in the dashboard, but not providing in our template would fall back to the dashboard setting.

    Looking at our git history, we’ve had this in place since our initial fork, so i have to also believe Algolia themselves were doing the same originally.

    To answer your question about “properly done”, maybe? Its more a question whose answer falls back to it’s one of multiple ways to customize, than a “proper” way.

    Thread Starter schwindt14

    (@schwindt14)

    I appreciate all your help Michael. One more question then I’ll close this:

    If we (my company) would like to setup a more comprehensive search/filter page (not just a search box) with check boxes and filtering posts by various custom attributes, and if I’m not feeling up to that task, does your company hire out hours and perform work like that? If so, what’s the best way to get in touch for a bid and/or rates?

Viewing 15 replies - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.