Online store search "article" type not working with "handle" field

Solved
New Member
6 0 0

 

Go to this URL: https://brooklyn-theme.myshopify.com/blogs/news - it's a blog with the handle "news" which contains one article with the handle "the-big-launch". We can search for this article by title by visiting this URL:

 

https://brooklyn-theme.myshopify.com/search?type=article&q=title:The%20big%20launch

 

This will show all articles which match the title "The big launch"

 

I need to search for this article by handle, according to the documentation, we should be able to visit a URL like this:

 

https://brooklyn-theme.myshopify.com/search?type=article&q=handle:the-big-launch

 

This should show all articles with the handle "the-big-launch", but it doesn't work.

 

The documentation states that the "article" type supports to "handle" field in the search, but it's either broken functionality, or the documentation is incorrect.

 

I've also tried a URL like:

 

https://brooklyn-theme.myshopify.com/search?type=article&q=handle:news/the-big-launch

 

And it still doesn't work - any help would be greatly appreciated.

0 Likes

hey @tomblanchard

I'll answer here for others to reference rather than slack.

This will give ya what you need:

https://brooklyn-theme.myshopify.com/search?type=article&q=the-big-launch

Does also seem to return what you need in a more complex blog with a lot of content.  e.g. here

https://whitelotusantiaging.co.uk/search?type=article&q=silk-hats-and-silk-lined-baseball-caps

where there's about 20 results containing keyword silk - it just returns the one article.

Documentation could probably be clarified by Shopify there.

 

★★★ Need help setting up your Shopify store? Hire me here: https://liquify.design ★★
0 Likes
Highlighted
Shopify Expert
9420 11 1262

As an aside, if you must search by handle you don't really need the search results. 
All you need is the search query.

From there you can work out if there's a matching article that's available via Liquid and then opt to show it or not. Since you know there will only be one article with the handle in the blog you don't have to worry about things like pagination. Most of the work would be hiding the parts that say that no results are returned.

I realise this doesn't answer the question or let you know if the docs are out of date, but something fun to consider when it comes to Liquid.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
New Member
6 0 0

Hey @Liquify - yeah I'm aware we can just search using the handle as the whole query but this won't work for my use case, a key part of the documentation regarding this is:

 

Searches for "handle" produce results for exact matches only. Searching for handle:artichoke matches a product with the handle "artichoke", but not a product with the handle "artichoke-hearts".

 

This will fail with your example in the case that a product has the handle "silk", e.g. this URL:

 

https://whitelotusantiaging.co.uk/search?type=article&q=silk-hats-and-silk-lined-baseball-caps

 

Will show the product with the handle "silk" and all other products which have "silk" in the handle, I need exact results.

0 Likes
New Member
6 0 0

Hey @Jason - that's a pretty good idea, except I need to use the default search pagination undisturbed as I plan to use the "OR" search logic, so this won't work for my use-case. A Shopify Partner support rep said:

 

I know we've been putting a lot of work into improving the search recently, so it's possible the bug he's noticed is related to those changes. I'll pass the message on to the team :)

 

So I'm not sure if this is a new bug or if the docs have always been incorrect, anyway we can raise this at all?

0 Likes

Hey @tomblanchard

gotcha - thought my solution would be too simple.

This appears to be a bug/unsupported functionality.

Maybe Jason has some ideas on escalating bug reports.  I've not had much luck in that dept recently I'm afraid.

★★★ Need help setting up your Shopify store? Hire me here: https://liquify.design ★★
0 Likes

Success.

Shopify Expert
9420 11 1262

Using OR doesn't strike me as a big problem either. Returning one result is easy. Parsing the query to grab two is also fine. Let's take a look at some code and an example.

 

First the example. I've got a pile of test shops but on this one it has articles. There's an article with the handle of "example-press-article-6" and another with "example-press-article-5".

 

Now if if I do an or search for totally different handles...

https://jasons-experiments.myshopify.com/search?q=example-press-article-A+or+example-press-article-B

 

... nothing returns. But you will see something interesting on the page. First, you'll see O results returned.

 

You will also see "press/example-press-article-a doesn't exist... press/example-press-article-b doesn't exist...". That's part of the code I quickly popped in.

Now search for the articles handles that do exist...
https://jasons-experiments.myshopify.com/search?q=example-press-article-6+or+example-press-article-5

 

As far as the search goes, we still have 0 results but the added code grabs the search terms and just looks for the handle directly. If it finds a published article it shows a link. 

 

Here's the basic code:

  {% if search.results_count == 0 %}
    {% assign searchTerms = search.terms | split:' or ' %}
    {% for term in searchTerms %}
      {% assign cleanTerm = term | handleize %}
      {% assign blogHandle = 'press/' | append:cleanTerm %}
      {% assign article = articles[blogHandle] %}

      {% if article.title == blank %}
        {{ blogHandle }} doesn't exist...<br>
      {% else %}
        <a href="{{ article.url }}">{{ article.title }}</a><br>
      {% endif %}
    {% endfor %}
  {% endif %}

I'll write a blog post on this as it needs more details/content but the storefront search is really quite cool. Getting 0 results back doesn't always mean that you have no options left. The terms themselves still add value.

 

(Those reading this later may find the links above may not work. I tinker on that shop a lot so will likely remove the articles or the code on the search page)

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
New Member
6 0 0

Hey @Jason - that is pretty cool and almost gets me to where I need to be, but this method can't be paginated; I need to use the native Shopify "search.results" pagination, it's a real shame the Shopify search is missing this feature, especially when the documentation says it supports it.

 

PS: I do appreciate you experimenting here for me, using the search template and returning results via Liquid using "search.terms" is pretty genius and something I could of definitely used in the past when I opted for a JS-heavy solution.

0 Likes
New Member
6 0 0

Hey again @Jason - I'm still battling this issue, is there really nothing we can do here to get this working how the documentation states? If not, we could at the very least update the documentation so future developers don't get confused/frustrated, what do you think?

 

Tom.

0 Likes
Shopify Expert
9420 11 1262

Expect the docs to be updated on this.

 

To be fair, I still don't understand why you need pagination if you're looking for handles. Perhaps you're looking for a handle, and something else. That would make sense. If you don't mind sharing the reason that would be cool - otherwise I'll be forever wondering.

 

Does a combo call with JavaScript help at all? So search for one thing, than the other, and combine results? Assuming the one of the searches only fills one single page you can then default to standard pagination links for the other search.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes