1

We have two main channels: products and blog. When a user enters a search term, if we find results in the primary channel (as indicated by the search_type cookie), we display the results and we're done. If we don't find results, then we need to let the user know we haven't found anything in products, but we did get n hits in blog.

I created a complex set of templates and embeds, with hidden search forms, and javascript that fired off the search form via ajax, then a second ajax call to gather the results. It was rickety but it worked. Sometimes. But not in Webkit. :(

So, I'm wondering about other ways of doing alternate searches. Any recommendations? (I should have sent out this question a long time ago.) Thanks for your help.

2

If you're willing to step away from the native Search module, you could do this with Low Search.

You'd create 2 collections: one for Products, one for Blog. In the search form, you then add a keywords field, and don't specify a collection to search through. Instead, you define the collection in the Results tag, so it only returns results for a single collection.

Then, inside the no_results conditional, you add an embed to the alternative search results. That embed should only contain another Results tag, but this time with a different collection parameter.

Example code:

Form tag

{exp:low_search:form result_page="search"}
  <fieldset>
    <label for="keywords">Keywords</label>
    <input type="search" name="keywords" id="keywords" />
    <button type="submit">Search</button>
  </fieldset>
{/exp:low_search:form}

Main search results

{exp:low_search:results query="{segment_2}" collection="products" limit="10"}
  ...code for main search results...
  {if no_results}
    {embed="search/alternative"}
  {/if}
{/exp:low_search:results}

Alternative search results search/alternative

{exp:low_search:results query="{segment_2}" collection="blog" limit="10"}
  {if count == 1}
    No products found, but here are some blog posts!
  {/if}
  ...code for main alternative results...
  {if no_results}
    Nothing found whatsoever!
  {/if}
{/exp:low_search:results}
1
  • Thanks, Lodewijk. You were going to be my next email. Reading your blog post about it now. Hopefully find out about collections and query and such. Apr 24 '13 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.