I'm using views for my search pages with facets enabled and I'm trying to come up with a solution to show results from the whole site when a faceted keyword search returns no results. What I'm trying right now is to embed the same search view minus the No Results area in a No Results php area but I can't figure out how to get the embedded search to ignore the facets.

Basically I want to show some results if there'd be results without the facets applied like amazon would do if you're searching inside a department for something that exists in other departments.
Anyone have any suggestions on how to pull this off?

Thank you

Comments

drunken monkey’s picture

Status: Active » Fixed

For the view, you could try

$view->query->setOption('search id', 'something');

Then the second search will have a different search ID and you can just set up the facets to not work on the search.

My approach to the whole problem would have been entirely different, though: implement a Search API processor that postprocesses the search results and, if there are no results, alters the query to remove the facets' filters, executes it again and returns the results of the new search instead. (Just be careful to only re-execute searches that had any filters in the first place, otherwise you'll run into an infinite loop. Same if the facet filters would get re-added, but theoretically a cloned query shouldn't have any preprocessing done anymore anyways.)

Hope this helps.

mnapier’s picture

Thanks for the reply
Not getting the views one to work yet but I'll keep playing with it.
Thanks for pointing out the processors I hadn't played with that option and I got it to work. Although it doesn't give me the opportunity to tell the end user nothing was found for their search and the results are against the whole site. Or at least I'm missing where I might implement that piece.

Thanks again you've given me somethings to play with as I was fed up with it before :)

drunken monkey’s picture

Although it doesn't give me the opportunity to tell the end user nothing was found for their search and the results are against the whole site.

You could probably just do a drupal_set_message() in the processor method in this case? Or set some static variable somewhere which tells some other part to display the message. Depending on your setup.

Anyways, glad I could help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.