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

drunken monkey’s picture

This 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.

dits’s picture

I'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?

zenlan’s picture

Not 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".

dits’s picture

Using search pages (without views) has the same effect: the facets also get reset.

dits’s picture

Dear 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.

zenlan’s picture

dits... 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?

dits’s picture

My 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 :-).

mrfelton’s picture

Just 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=

Pedro Lozano’s picture

I've created a little module in a sandbox project that helps with this problem: http://drupal.org/sandbox/pl2/1438442

batje’s picture

You could also try to get around this using http://drupal.org/project/views_modes

emorency’s picture

Solution #9 is working great for me !

Thanks !

- Etienne

SandraVdv’s picture

What 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?

anj’s picture

The solution from #9 worked perfectly for me too. Please consider merging the functionality into the search_api module.

kenorb’s picture

Status: Active » Fixed

Installing 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

Status: Fixed » Closed (fixed)

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

dergachev’s picture

Issue summary: View changes

#9 seems to work well for us too, thanks so much!
It might be nice to consider rolling this into search_api core.

fonant’s picture

Facet 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.

amjad1233’s picture

#9 works like a charm

burkeker’s picture

#9 works nicely. A million thanks to Pedro Lozano!

brahimmouhamou’s picture

#9 does the trick, thnx!

drewpal3’s picture

#9 saves the day! Thanks Pedro!

freezeCoder’s picture

Thanks, Pedro!

jennypanighetti’s picture

#9 fixed it for me!! Thank you, Pedro!! You saved me SO much frustration!

3119999’s picture

Hello Community
Does someone know if the code from #9 ist available anywhere?
Thanks in advance and best regards

NWOM’s picture

3119999: 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.

3119999’s picture

Thank you, NWOM,
I've found it :-) but unfortunately it didn't help: https://www.drupal.org/node/2686467
Best regards

eevensen’s picture

#9 works great. Thanks a million, Pedro Lozano!

chrisolof’s picture

I'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).

HiMyNameIsSeb’s picture

I 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.

AswathyAjish’s picture

Is there any solution for this in drupal 8?