How is it possible to display an "All" (=show all items) link in facets? Ideally with the total number of matching search results?
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | add-all-link-with-override-string-1440016-39.patch | 3.82 KB | qandeel |
| #37 | add-all-link-1440016-37.patch | 2.25 KB | xlin |
| #21 | Screen Shot 2013-10-14 at 6.20.32 PM.png | 7.82 KB | mmncs |
Comments
Comment #1
danielnolde commentedComment #2
cpliakas commentedI think it is possible, but this would be handled by the backend. Not sure if Solr provides this option out of the box, but you could add an
alter callbacksfunction to each facet to explicitly add an "All" item with whatever query will show all facets.Comment #3
danielnolde commentedThanks Chris for the assessment.
Actually i just figured out a nice way to add an "All" link (without any resultcount, however) by changing the facet item build, either by implementing a custom facet filter class, or by using facetapi_bonus and implementing its hook_facet_items_alter() with the following code:
A bit of custom/overridden theme functions for link widget rendering bring the icing to the cake.
Comment #4
cpliakas commentedThanks for posting your solution! This looks like a pretty cool workaround that is backend agnostic. My only concern would be if the "hard limit" was reached, in that case you would only be filtering the facets that were returned.
Just to cross post, there is some relevant information for Solr at #738076: Implement "All" Facet to facet block configuration.
Thanks again for posting,
Chris
Comment #5
danielnolde commented> if the "hard limit" was reached, in that case you would only be filtering the facets that were returned.
hm, not sure if i understand you correctly, but there's no "filtering" of facet items in the code above, there's just the faux-item "All" added, whose query parameters are filtered to _not_ contain facet items of the facet it is added to. I can't see a.t.m. what problems that could cause in conjunction with hitting the hard limit for facet items...
Comment #6
cpliakas commentedGotcha. That makes sense to me. Marking support request as fixed.
Comment #7
iajay commentedI tried the above code and it was working correctly. But it does not work after installing this module http://drupal.org/project/facetapi_pretty_paths
When the hook_facet_items_alter is called the path of the facets is already changed and the #query is also null
Can you help me in fixing this?
Can we somehow call the hook_facet_items_alter before the paths are changed?
Kind regards
Ajjaykummar
Comment #8
iajay commentedI was able to solve this with the code. Sharing the code if anybody needs that
Let me know if there is any problem in this and how I can retrieve the alias for the facet.
Kind regards
Ajjaykummar
Comment #9
cpliakas commentedThanks for posting, iajay!
Just a little tip, would you mind wrapping your code in
<?php ?>tags so your snippet is easier to read?Thanks,
Chris
Comment #10
iajay commentedadded the
do let me know if you find a problem
Thanks
Ajjaykummar
Comment #12
sokrplare commentedThis is available in the bonus module: http://drupal.org/project/facetapi_bonus
Comment #13
nick_vhcovenantd, can you explain how this is available? I grepped for all and view all but I could not find a reference to this?
Comment #14
doliveros commentedIf I understand #3 & #8 correctly, the code works more like a reset facet link, instead of a "select all" link.
This isn't what is expecting if, for example, you have a "Gifts" taxonomy with different gift types to filter in, and you want to filter out all products that doesn't contain any Gift taxonomy. Clicking on the -All- filter would reset the filter and display all the products (even if they are not classified as gifts), not the products containing any of the gift taxonomies (All gift products).
Any thoughts on this one?
Comment #15
peterx commented#14 is right. I expect the All option to select all the categories displayed below the all.
Select abc:
* All
* a
* b
* c
All should select a or b or c. X, y, and z might also exist but if they are not listed, they should not be included.
Comment #16
scoffield commentedThe solution is here ->
http://drupal.org/project/facetapi_tabs
Comment #17
mattiasj commentedThis solution works great, but in my case I have several different facets. Category and year. With my custom "all", or in my case "reset" link they will clear the facets for all my blocks. Any ideas how to make the link only function for their own blocks?
Comment #18
drclaw commentedJust an update to the solution in Comment #8 where the pretty path alias is pulled dynamically:
Comment #19
auraell commentedwhere do we put the code in comment 18?
Comment #20
drclaw commentedYou can put it in a custom module or in template.php in your theme. Be sure to replace "HOOK" with your module name (or theme name if it's in your theme)
Comment #21
mmncs commentedWhen I add this code in a custom module I get a checked all link even when I use one of the filters?
Comment #22
madhusudanmca commentedHi All,
I have done some modifications to code in comment #18 , as that code didn't worked for me.
Comment #23
mattiasj commentedI would like to have a unique class for the reset link. I tried some variations without success. Any ideas?
Comment #24
PMorris commentedDoes this code still work? I tried it in a custom module and in my theme but it doesn't seem to do anything at all.
I have the Facet API Bonus module installed. Is there something I have to turn on that I missed?
Comment #25
woprrr commentedI suggest that this approach is more facet api way . Here I apply the theoretical facet how to use API, and this makes it possible not to have to recreate things that should not be done here as the URL processor (if needed requires more use $adapter->getUrlProcessor().
precisely this hook is invoked only once a facet with the active callback.
Comment #26
woprrr commentedI think this issue do move to facetapi_bonus issue.
Comment #27
woprrr commentedComment #28
nareshbw commentedHi woprrr,
Thanks for your solution . It is working fine for me .
Comment #29
woprrr commented@nareshbw
I'm glad that I served you :)
Comment #30
nareshbw commented@woprrr
This code can be used if I want to reset filters from same block . But if I want to reset all filters from all blocks then this code is not working . Kindly help/suggest.
Comment #31
nareshbw commentedI changed the path and it fulfilled my requirement
$firstitem = reset($build);
$path = $firstitem['#path'];
$path = explode('/', $path);
// Loop through the path parts
$path = $path['0']."/".$path['1']."/".$path['2'];
Comment #32
knalstaaf commentedI've tried the code from #18, #22 and #25 in my template.php but with no result. Also tried the Facet API Bonus module (as mentionned in #12), but it's not clear to me either how that module offers a solution for this.
I have a vocabulary containing more that 50 items, so that url starts to look quite exotic with every term in there. If I could use a URL with such as
myvocabulary/All(built with Facet API Pretty Paths), it would look a lot healthier.(BTW: I'm not using Solr, but Search API Database Search)
Comment #33
marcoka commented@knalstaaf facet api bonus offers a setting that you can use hook_facet_items_alter
here: http://root.artwaves.de/sharex/2016-02-04_13-33-39.png
my goal is also to have a link on a facet that shows all/ like skip this filter. my only problem is that i dont know what param the api needs to "show all/skip"
#2662018: Skip facet link / ignore filter / show all
#25
This code adds an "all" link to facets. But it is also selected by default: http://root.artwaves.de/sharex/2016-02-04_13-36-47.png
The code also adds the all link so that it like resets all filters
Comment #34
ray17n commented#25 by woprrr works for me. Thanks.
Comment #35
igasi commented#25 works perfectly to me.
I only added this code for collect all results and displayed in the filter.
Thanks woprrr
Comment #36
baldalo commented#35 will work only if indexed entities belong exclusively to one item. If entities belong to multiple items, #35 will result in double counting them. Am I correct?
Comment #37
xlin commentedAdded an option to add an "all" link, tested with Solr + type and language filter.
Comment #38
xlin commentedForgot to add that code from #37 are mostly from search_api_glossary module.
Comment #39
qandeel commentedI have enhanced its functionality; with this patch, 'All' can be overridden by any string; also carry count and hide default missing value item.
i.e. "(none) (11)" will be replace by "(Overridden string) (11)"