How do I use Site Search with Blog Articles


#1

I am trying to integrate the new Site Search for my Blog Posts but the site search only searches Website pages, how would I adjust the params of the Search Results JS code to search only Blog Posts?


#2

Hi @cabplanalp,

You can include the &type= parameter set to include BLOG_POST to search for blog posts:


#3

@Derek_Gervais, thank you for this information, yes I did find this searching for documentation right after you posted reply, appreciate it. So I had a follow-up to this. So I have a Website using the Hubspot Search but I also have a Blog using a sub-directory under the same domain (mydomain.com/blog/) but I would like a different template than the website template. I want the blog template, every time I try to use the form code from the Search Input field it takes user back to the Website template because that is what is designated in the System Template files. I also tried to create a Page Template for the blog and then for the form action tried to point the Search Results to populate on that page but nothing seems to populate, do you have any documentation on how to have two different search results templates under the same domain, one for blog and one for website?

Here is the Page Template I created for the blog that does not work:
https://us.epsilon.com/a-brand-new-view/search-blog?term=personalization&type=BLOG_PAGE

The current blog search, redirects back to the website search results page:
https://us.epsilon.com/a-brand-new-view
If you search (upper right) it takes you the website search results template because the code is set to that:
<form action="/{{ site_settings.content_search_results_page_path }}">

Any help would be much appreciated.


#4

@Derek_Gervais, so after I replied I looked at that pathPrefix, and when I applied that to the input of the blog search input, it did indeed help with filtering out just Blog posts, even when Type was not working:

<input type="hidden" name="pathPrefix" value="/a-brand-new-view">

I am having issues with loading results on another template for the blog though, even when I use the above, it goes back to the Website page template for Search Results. Here is the template I am trying to get the results to show up on:

https://us.epsilon.com/a-brand-new-view/search-blog?term=marketing&pathPrefix=%2Fa-brand-new-view

I even tried to change the JS in the search to point the results to that page by using this:

getSearchResults = function(){
var searchUrl = "/_hcms/a-brand-new-view/search-blog?&term="+encodeURIComponent(searchTerm)+"&limit="+encodeURIComponent(TYPEAHEAD_LIMIT)+"&autocomplete=true&analytics=true&" + searchOptions();
$.getJSON(searchUrl, function(data){
  if (data.results.length > 0) {
    fillSearchResults(data.results);
    trapFocus();      
  }
  else {
    emptySearchResults();
  }
});

},

Any help you can provide would be most appreciated.


#5

Hi @cabplanalp,

It's not currently possible to specific separate search results templates for different content types. If you have specific features that should be different based on the content type being searched, you might consider using HubL if statements to render different elements/CSS based on the content type: