How to add multiple search queries in a search page?


(Chrishan) #1

I need to pass multiple search queries in a search page.

For example, currently my search page has a search field and submit button. When a user types a keyword and hit submit button, it will display a list of matched results. What I need to do is add more filters to refine the results when user in the search results page,

I created another form inside search results page for refine filters, but when user click apply the existing results will disappear and appear new results. Can I pass multiple search queries in the URL like below by keeping the existing results?

?queries_content_query=Test&search_page_xxxxxx_submit_button=Submit&queries_filter_query=Filter1


(Jsisk) #2

Hi Chrisan,

Unfortunately I don’t think what you are trying to do will work for a number of reasons.

There are 2 other ways, that I can think of, you could achieve the same results, depending on what kind of user experience you are going for:

  1. Additional search fields: - you could configure the Search Page asset to have more search fields that can be used to narrow down your results from the start. There’s an example here instructions how to do that: - https://matrix.squiz.net/manuals/search/examples/example-search-page#Adding-the-Search-Fields
    If you only need to have additional fields on the search results page, you could add the fields to the “Results Page Layout” bodycopy asset and they won’t appear on the “Initial Search Page Layout” bodycopy asset

  2. Javascript (JS): - Use JavaScript to filter the search results further. This would be faster than making a second request to Matrix to search again, like what you were trying to do. The downside is that if you are using search results pagination, which we would usually recommend, then the JS would only filter the results that are displayed on the page at the point in time, omitting any other search results on subsequent pages.

I would recommend going with option one, as it would be easier, cleaner and more maintainable than any custom JS.


(Chrishan) #3

Thanks @jsisk

Options one works, thanks for the help…