Setting search for product code
-
Good evening, I would like to have the opportunity to do a search by product code, called post_id. I’ve seen that it is possible to add it in the searchable attributes on the Algolia account (and I added) but I don’t know how to insert it in the session in wordpress backend. If I only add it in the searchable attributes you don’t see it in the website, saying “no results found” when you search for the code number. Can you help me setting this feature??
Thanks for the collaboration
The page I need help with: [log in to see the link]
-
If I’m following everything correctly, you essentially want to make it possible to search by the post’s ID, a property that’s indexed by default? And you’re not using Instantsearch? Only “Use Algolia with the native WordPress search template” ?
For example, I have a post in my test index, that has an ID of 1819, and you want to be able to put that 1819 value in have the direct hit returned.
Do I have you accurate so far?
At least with my own testing, I was able to get this working with adding
post_id
to mysearchableAttributes
settings in my Algolia Dashboard, and a bit more refinement with it by removing typo tolerance for thatpost_id
property.One last question, in case you have Autocomplete enabled as well, are you making this configuration change to the
wp_searchable_posts
index and not thewp_post_posts
index? Cause Autocomplete and Search Page settings create separate indexes.Hi Michael,
unfortunately it doesn’t work:
I’ve set up in the searchable attributes of wp_searchable_posts the option post_id; then in the wordpress dashboard indexed in the autocomplete session the products. What i need to know if there is another option where I should link the plugin to algolia account…Is there something I’m missing in these settings?
Thanks for your help!
Ilaria
The autocomplete page UI/buttons would be affecting and indexing to a
wp_post_posts
index and similar named index and not specifically thewp_searchable_posts
index. The “Search page” options page has its own re-index button that pushes all post types that aren’t set to be “exclude from search true” into thewp_searchable_posts
index.Sounds like you’re editing and then testing different indexes accidentally.
You should be able to see all the available indexes at the top of your Algolia.com Dashboard, in the area on the right of this screenshot, once you’ve chosen an application and navigated to the search area.
Hi,
thanks for your reply. I still don’t get where it’s the wrong index, so I took a screenshot of the settings, so you can tell me where to look at.
Thanks for your help!
Hmm,
Valid point, I forgot to ask if you were using “All Posts” in autocomplete vs just an individual content type. Apologies there. “All Posts” definitely does reuse that index.
Is there somewhere where I could try this out myself, in terms of performing a search and whatnot?
Do you need to enter the dashboard of WordPress or Algolia account?
You can try on the website: https://www.tecnografica.net to search for products Id such as 74433, 74216 or 92121. You’ll see they are not found. Let me know what do you need to test the settings.
Bests
Just the frontend was what I was looking for, where I could interact with the search as if I was a visitor to the site.
Checking.
I wonder if this is playing a part in anything:
"filters":"language:it"
I did a search for say “metal” and inspected the returned hits array, and got a post ID of
87282
and then when I do a search for that product ID, I get results still.So it feels like possibly the language filter is affecting things, and not all of the products match that attribute.
Interesting…So I have 2 possibilities: one is languages in the browse settings, by flagging all the languages (should I select none of all?) or the other option is in the configuration section with languages (this I need for statistics).
Should I de-flag them? Here I attached the settings I have
Another thing I observed: if you search for “polly” you get a roduct whom number is 69766, but if you then search for 69766 you’ll get the product “Lullaby” (code 71439)
Really not a thing that I can make final decision on and not something that the plugin can dictate. So I’m not sure how to best handle product IDs potentially being associated with only specific languages and with that filter in place.
Doing a search of
69766
for me does get aLullaby
result which has a post ID of49766
so that feels like typo tolerance in play. Just that first character is different.Out of curiosity, are you advertising, or listing in some way, these numeral IDs? Asking because most people wouldn’t be searching by that type of detail because it wouldn’t be an obvious thing shown. However, SKU values I could definitely see potentially being shown and a good candidate for a search value.
Yes, this is something that clients was asked for: so what happens is that architects or interior designs decide which wallpaper it fits fr their project and then ask for info about the price. Sometimes, they just have the code (post id) of the wallpaper and they search for it…but so far it doesn’t work, or it doesn’t fit.
I don’t understand why the post id (cod in the woocommerce session) is not found although the settings are fine…
It’s going to be because of the filtering.
If you have a product with a post_id of 12345, and the language code is set to
de
for it. If I do a search with the filter set toit
for Italian, it won’t get found, because we’re filtering based on language code. However, if I switch my site language over to German, and re-perform the search, it would, or at least should, show up.I have to assume this
"options":{"filters":"language:it"}}
is being filtered in custom.Closest idea I can think of to having the post ID search not be limited by language would be somehow intercept the query being made, and check if it’s numbers only, and if that’s the case, unset the filter itself. However, how to do that…I don’t have an answer for.
I would understand the language issue if the codes would vary, but each product has only one code that it would be the same for all the languages.
For ex: product “Lullaby” has the code 71439 in it, de. en or es.
Yes, but it’s my understanding that the filter added via the widget is acting AFTER the initial query has been made and before the final results get returned.
As a hopefully understandable mental example, say you want to fetch socks from your dresser. The initial query would be “looking for socks” and you go to the sock drawer where all of them are stored. You’ve queried for the socks. However, you have a filter of “color:red”. Gotcha, fetch only the red socks in the end. Even though you have other pairs in the color of blue, green, orange, etc. You only get red in the end.
You said the language code was getting used for tracking/analytics of some sort? Curious if there’s an alternative way to achieve what’s needed. Please correct me where I’m wrong with this part, regarding how the codes are being used.
- The topic ‘Setting search for product code’ is closed to new replies.