Currently using Views + search_api + facet_api to build a classified ads system. This works great except for the fact that a fulltext search forgets about all the set facets.
On the main page of the system the user can browse by selecting a specific category, for example 'Cars'. On the resulting search results page all ads within this category are shown including several facets.
Now if you enter a search term (exposed filter in Views) and hit 'Search' the selected facets (category = cars) is completely forgotten and a new search is started for your keyword. One would expect that the fulltext search is added to the filters/facets that are already active.
What would be the best way to solve this? Our current quick hack is adding a hidden field to the Views form to add all existing URL query parameters but that's hardly a longtime solution.
Comments
Comment #1
alexverb commentedAt the moment there's no solution to remember facet settings. There is a feature request that is moved to Facet API Extra at http://drupal.org/node/1380716.
I think the best approach to remember your facets is the same way views remembers exposed filters. By storing it in $_SESSION['views'][$this->view->name][$display_id]. Maybe this way you can even combine the facets and exposed filters to be remembered.
Ps: I'm also working on a classified ads system, looks like this is a "must have" for classifieds systems. I'm willing to pitch in on a project if someone wants to take on the feature request. Even though I'm pretty scared of views code :).
I suggest we take this discussion to the feature request since it's not really a bug.
Comment #2
jtbayly commentedAccording to this comment on the above linked issue, this feature should not be implemented in facet api.
It seems to me, given what I've read, that that means it should be implemented here. Marking as active feature request, and moving to the UI component, although I'm not sure that's where it belongs.
-Joseph
Comment #3
jtbayly commentedAt one point (maybe still, I have no idea) this was supported in the apachesolr module with a simple checkbox next to the search box that said "Keep current filters" or something like that. Seems pretty simple to implement to me... but I can't at the moment.
Is anybody else interested?
-Joseph
Comment #4
luo8 commentedHello,
please..did you anybody solve it?
Thanks.
Comment #5
jtbayly commentedStill waiting. Seems pretty basic to me. Can't work on it myself.
-Joseph
Comment #6
Ravenight commentedI would love to see this too. Since it is not ready I did what BartVB did by adding a hidden field to the Views form to add all existing URL query parameters.
Since I had to futz with it for more than a few minutes to get it to work, I thought I would post back what I did for reference in case someone else needs this before a more permanent fix can be implemented.
I added this to the template file:
Not the best workaround, but it does work.
Comment #7
luo8 commentedDear all,
problem was solve for "Search api" module need to be installed module "Facetapi_pretty_paths" (http://drupal.org/project/facetapi_pretty_paths),check http://drupal.org/node/1826576 .
Comment #8
merilainen commented#7 is not a solution per se, it's an alternate solution. In our case we need to stay in same /search path and use parameters, so Pretty paths is not an option because it will spread the search to sub paths like /search/parameter1/value1/parameter2/value2 etc.
Comment #9
drunken monkeyI think this issue would be better suited for the "Views" module's issue queue, as this is a problem of / feature request for Views in general, not just the Search API. But please search in the issue queue there first, maybe there's already something about this.
Comment #10
mpp commentedA similar solution would work for Drupal 8:
Comment #11
mark_fullmerI can confirm that the D8 solution in #10 works for me. Do note, though, that if your facet configuration defines a different string than "f" for the query parameter key, you'll need to adjust that in your code. The below provides a solution where you can act on one or search_api views + facets, supplying the different facet query parameters:
Comment #12
watergate commentedThanks for the code snippet!
Comment #13
idebr commentedRelated to (or duplicate of) #2378945: Facets are lost by Views on keyword search
Comment #14
idebr commentedIn this Drupal Core issue #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items', the Views exposed form maintains existing query parameters when searching. This would fix the issue reported here.
Comment #15
mkalkbrennerI wonder if this is not already solved by #2378945: Facets are lost by Views on keyword search within Search API.
Comment #16
drunken monkeySeems like it, yes. Thanks!