Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi,
I have come across an issue with the faceted filters.
The user has to be able to select the amount of results he wants on a page.
This can be done simply in views by checking the "Expose items per page" check box in the pager settings and then doing some settings.
However, this seems to collide with faceted filtering:
when I go to my search page and do some filtering and then decide to show more/less items, all filters are reset so I have to redo my faceted filtering.
Maybe this is related to http://drupal.org/node/1217506 ?
Any suggestions to solve this?
Thx
Comments
Comment #1
drunken monkeyThis issue isn't really related to the Search API, as the pager is provided by Views itself. The problem is that it will seemingly discard all existing (unknown) GET parameters when you set a new "items per page" value. I guess this will have to be fixed (or added as a feature/option) in Views.
Comment #2
dits CreditAttribution: dits commentedI'm running into this same issue: every new full text search resets the facet filters. Setting the pager to display all items did not fix the issue for me. Is there some other quick fix or workaround?
Comment #3
zenlan CreditAttribution: zenlan commentedNot sure if you count this as quick or whether it fits the bill... but its definitely a workaround or "bodge" as I like to call it: http://www.iwm.org.uk/collections/search?query=cats
A custom block top left, on block_view it grabs the filter ($_GET['filter']) and creates the items_per_page links using the same options/args that the items_per_page select uses. The items_per_page select is still on the page but hidden. So once you have clicked on an items_per_page element in the block, that preference persists if you use the pagination, the facets or the fulltext search (thanks to the hidden select). The facets reset on fulltext search, this is intended. View source and search for "items_per_page".
Comment #4
dits CreditAttribution: dits commentedUsing search pages (without views) has the same effect: the facets also get reset.
Comment #5
dits CreditAttribution: dits commentedDear Zenlan, Thanks for your feedback. Your reply lets me realize that my issue, although related, is a different issue. My issue is the facet filters are being reset when searching on a new search key. I might open a new ticket.
Comment #6
zenlan CreditAttribution: zenlan commenteddits... but isn't that how it should be? Every search key will return different facets, no?
e.g.
if 'dogs' has facets media:images and media:video and media:sound
and if 'cats' has facets media:images and media:video
If you search for 'dogs' and select 'sound' then change the search key to 'cats' your search would return 0 results.
The way I see facets is that they present the user with all of the viable filtering options available for the given search term/s and thus the user cannot end up in a dead-end.
I suppose it depends on your data and how it is indexed though. Do you want a static list of all possible facets for a user to select from regardless of search term?
Comment #7
dits CreditAttribution: dits commentedMy use case is a bit different. Unfortunately the site is not yet live, but you can have a look at this screenshot from this issue to see what I'm trying to implement.
My intention is for the user to navigate the facets and add/update search terms, independent of each other, showing an AND-ed set of results from 'facet navigation' plus 'full text search'. Thus for my purpose the facets related to a specific search term are only used to update the counters of facet item occurrences.
What I did for now is hide the search term input form on the results page, making it clear for a user that a new search resets the facet selections. In my experience a user won't expect these facet selections to be reset upon a new search term.
In future I would prefer to have the search term form on the results page and executing a full text search not to reset the facet selections, but in stead update the facet item counters. All Ajax based, using stemming and proximity searching of course :-).
Comment #8
mrfelton CreditAttribution: mrfelton commentedJust reported a similar (I think the same) issue at #1434428: Applying an exposed views sort results in lost active facits. Cross posting to make this thread easier to follow:
---
I have a view on a search index, some facets, and a views exposed sort block shich includes search api sort options, as well as an exposed number of pages selector and asc/dec selectors. If I go to the base view and apply a couple of facets, and then change the order (asc, desc, or my sorts configured through search_api), the active facets are lost.
eg.
1. Go to /mens
2. Apply the 'D&G' brand filter
3. This takes you to ?f[0]=field_product%253Afield_optics_brand%253Afield_optics_brand_displayname%3AD%26G
4. Apply a sort or some kind.
... Now you are on /mens?search_api_views_fulltext=&sort_by=new_arrival&sort_order=ASC&items_per_page=12
It has removed the active facet, and replaced it with search_api_views_fulltext=
Comment #9
Pedro Lozano CreditAttribution: Pedro Lozano commentedI've created a little module in a sandbox project that helps with this problem: http://drupal.org/sandbox/pl2/1438442
Comment #10
batje CreditAttribution: batje commentedYou could also try to get around this using http://drupal.org/project/views_modes
Comment #11
emorency CreditAttribution: emorency commentedSolution #9 is working great for me !
Thanks !
- Etienne
Comment #12
SandraVdv CreditAttribution: SandraVdv commentedWhat is the best solution for this problem? When I use a fulltext search exposed filter and I click on a facet my search exposed filter also gets resetted...
I saw the blog post from Wunderkraut about "Marrying facets and exposed filters" and this post https://drupal.org/node/1797616, but does this also solve the results per page problem?
Comment #13
anj CreditAttribution: anj commentedThe solution from #9 worked perfectly for me too. Please consider merging the functionality into the search_api module.
Comment #14
kenorb CreditAttribution: kenorb commentedInstalling Facet API Pretty Paths should remember the filters in the URL:
http://drupal.org/project/facetapi_pretty_paths
See: #1826576: Remember facets result after search word changed
Comment #16
dergachev CreditAttribution: dergachev commented#9 seems to work well for us too, thanks so much!
It might be nice to consider rolling this into search_api core.
Comment #17
fonant CreditAttribution: fonant commentedFacet API Pretty Paths is recommended by me. It works very nicely and provides an easy way to replace the machine-names for facets with nicer-to-read (and often shorter!) names in the URL.
Comment #18
amjad1233#9 works like a charm
Comment #19
burkeker CreditAttribution: burkeker commented#9 works nicely. A million thanks to Pedro Lozano!
Comment #20
brahimmouhamou CreditAttribution: brahimmouhamou commented#9 does the trick, thnx!
Comment #21
drewpal3 CreditAttribution: drewpal3 commented#9 saves the day! Thanks Pedro!
Comment #22
freezeCoder CreditAttribution: freezeCoder commentedThanks, Pedro!
Comment #23
jennypanighetti CreditAttribution: jennypanighetti commented#9 fixed it for me!! Thank you, Pedro!! You saved me SO much frustration!
Comment #24
3119999 CreditAttribution: 3119999 commentedHello Community
Does someone know if the code from #9 ist available anywhere?
Thanks in advance and best regards
Comment #25
NWOM CreditAttribution: NWOM commented3119999: It is a sandbox module which means their are no public releases to download. If you would like to download the current version from GIT, click on the "Version Control" tab, and follow the instructions. I hope this helps.
Comment #26
3119999 CreditAttribution: 3119999 commentedThank you, NWOM,
I've found it :-) but unfortunately it didn't help: https://www.drupal.org/node/2686467
Best regards
Comment #27
eevensen CreditAttribution: eevensen as a volunteer commented#9 works great. Thanks a million, Pedro Lozano!
Comment #28
chrisolof CreditAttribution: chrisolof at Lima Solutions for CivicSolar, Inc. commentedI'd suggest we re-open this. I'm not convinced Facet API Pretty Paths fixes this as we just ran into it with a results-per-page selector in a search API view with Facet API Pretty Paths in the mix. Also - Facet API Pretty Paths may not be appropriate for all sites that wish to expose Search API search interfaces.
dits also mentioned that this happens "Using search pages (without views)...", so that makes me wonder if it might be better to fix this in search_api_page and search_api_views (rather than the views module).
Also confirming that Pedro Lozano's sandbox module in #9 fixes the issue for us (using search_api_views).
Comment #29
HiMyNameIsSeb CreditAttribution: HiMyNameIsSeb commentedI have been using search api with search api facets for filtering. The facet filters were being cleared when you update the sort. Simply by selecting "use AJAX" > "yes" fixed the issue.
The view was updating without the pageload meaning the query string in the URL was still present therefor both the search order and filtering were being respected.
The limitation is that as the URL doesn't include the sort order when you update the filter, the sort is reset to default. For our solution (using links for facet filters) this was not a major issue.
Comment #30
AswathyAjish CreditAttribution: AswathyAjish commentedIs there any solution for this in drupal 8?