Is there a reason why facetapi is using different structure in URL attributes than views exposed filters? At least for terms.
Views exposed filter: /search/url?field_name_term[0]=284&field_name_term[1]=285
Facet API facets: /search/url?f[0]=field_name_term%3A285&f[1]=field_name_term%3A286
If they would use the same structure, I think activating one would show the other one active also. Changing the order should be quite trivial, that's why I'm asking is there some deeper purpose for this difference?
It would be awesome to use Views exposed filters to build an advanced search to start with and then the facets would be active on the result page, to make it very easy to "navigate" the results further. And by clicking on facets the exposed filters would change also.
Comment | File | Size | Author |
---|---|---|---|
#31 | facetapi-marry_facets_and_exposed_filters-1797616-30.patch | 14.82 KB | Bès |
#27 | interdiff-1797616-25-27.txt | 2.19 KB | jlapp |
#27 | facetapi-marry_facets_and_exposed_filters-1797616-27.patch | 14.82 KB | jlapp |
#26 | facetapi-marry_facets_and_exposed_filters-1797616-26.patch | 14.73 KB | jlapp |
#26 | interdiff-1797616-25-26.txt | 2.19 KB | jlapp |
Comments
Comment #1
mErilainen CreditAttribution: mErilainen commentedLooking deeper into facetapi code, it looks like using the field_alias as filter_key and leaving out the "%3A" (colon) would make the URL consistent with views exposed filter?
Comment #2
cpliakas CreditAttribution: cpliakas commentedHi mErilainen.
The URL structure is pluggable, so feel free to implement another URL processor such as Facet API Pretty Paths did. Views integration would definitely be nice, and I would love to see some contribution around this since I believe the core module is pluggable enough to achieve the desired use cases. Closing as duplicate of #1274086: Render facet items via views (aka "Views integration") as that should be the issue that Views integration ideas should be posted against. I will cross post to this thread as well.
Thanks for the post and ideas,
Chris
Comment #3
mErilainen CreditAttribution: mErilainen commentedYou "cross posted" that issue to itself ;)
Comment #4
cpliakas CreditAttribution: cpliakas commentedmErilainen,
Ha. I suck at the issue queue. Re-cross posted.
Thanks for picking that up,
Chris
Comment #5
mErilainen CreditAttribution: mErilainen commentedHere is a small patch which works for simple taxonomy terms. When I click a facet, an exposed filter will activate and vice versa. I will have to do this same in a custom module overriding the functions of facetapi so that facetapi is not hacked, but I want to show the patch here as some food for brains.
Currently it doesn't work with ranges (integer values) for example, but I would be interested to know if it is possible to change the structure of facetapi core, or do I have to always rely on my custom module to override facetapi behavior?
I guess I can try to do the same as facetapi_pretty_paths and use the custom processor only for taxonomy term values.
Comment #6
mErilainen CreditAttribution: mErilainen commentedI worked a bit more with this and made a module which makes the taxonomy facets work with Views exposed filters. At least for now I don't need anything else, because I can't really expose anything else in Views as an exposed filter. I hope some of this work could be included in facetapi module, maybe as a selection per facet to make them compatible with Views exposed filters or some other way. It doesn't seem to break other field types such as integer and string fields, but the main reason I'm posting it here is if someone can check if there are some other situations when it's not working.
Basically I just altered the fetchParams() and getQueryString() functions so that the URL is altered in getQueryString() to work with Views exposed filters (no filter key, only underscores, no colons) and then in fetchParams() URL attributes are transformed back to parameters in the same format as facetapi handles them. So I'm not sure where else these changes might affect.
Comment #7
mErilainen CreditAttribution: mErilainen commentedHere is a new version of the module. Fixed a bug when user had a keyword from views exposed filter, it was forgotten when building the facet URL, now it will be included. I also noticed that I can now change the keyword and the facet values will remain in the URL, but usually the facets get lost? I thought that would come from views form, but it works now.
Comment #8
cpliakas CreditAttribution: cpliakas commentedThanks for the work on this! Can't wait to check it out. Since you are doing some great work and providing some code, re-activating this issue since it would be cool for other people to more easily find what you are doing as well.
Thanks for the contribution!
Chris
Comment #9
mErilainen CreditAttribution: mErilainen commentedI also want to point out that my use case might be specific and the module might break some facets which I don't need. That's why I wanted to post it here for someone to take a look who has better insight about facetapi and might know issues which can come from the alteration of the URL structure.
But I hope my approach is a sensible one, since I'm not touching any other parts of the facetapi classes, only altering the way how the query is built and how the parameters are fetched from the URL.
EDIT: I noticed at least one case where this module doesn't work. When I enabled "Add facet for missing values" and try to use one facet with that value, I get an error saying "An illegal choice has been detected. Please contact the site administrator." The value in the URL for the missing value facet is "!", not sure yet why it doesn't work like other values.
Comment #10
mErilainen CreditAttribution: mErilainen commentedOkay, I figured out the problem with the "none" facet item. Because I'm rewriting the parameters to work with views exposed filters, now Views is trying to process the value "!" which spits out the error, I think. So I made a small fix to this by checking if the value is "!" and then using the normal FacetAPI processing for that field. See the attached updated module.
It looks like working normally now, but there is a problem with the "none" facet item I discovered in FacetAPI workflow #1815204: Facet for missing values doesn't work with AND operator
Comment #11
cpliakas CreditAttribution: cpliakas commentedExcellent blog post by Wunderkraut on this topic.
Comment #12
alexweber CreditAttribution: alexweber commentedThis is excellent and much needed, props to the OP for addressing this. Can we roll this as a patch against Facet API dev, I see no reason why it shouldn't be committed... :)
Comment #13
quardzNice module, Search API is heavy for my shared hosting. Needs to add Dependence in info file.
Comment #14
gettysburger CreditAttribution: gettysburger commentedThis is exactly what I need. Three cheers. I have not tried it out yet but will today. Thanks!
Comment #15
SandraVdv CreditAttribution: SandraVdv commentedAre the values of the facets always filled in the views exposed filters? Do you really need to use the Wunderkraut module when you want to display a fulltext search box and the "results per page" dropdown on your Search API Views page? Is that the only way to let them work together? Is it correct that you need to include all your facets into your views and hide them with CSS then?
Comment #16
Soul88Maybe this will help someone: http://drupal.org/sandbox/Soul88/1865682
Comment #17
andypostI think the root of the problem here that seach index have only one facet adapter so Only One url_processor allowed.
So if you need some kind of "mixed" sources to set active facets so you need a lot of work to attach url_processor with some kind of context-data.
Some simple example: display 2 views from one search index on page with different filters/facets but this require to reset statics(facetapi_adapter_load) and hack into hook_facetapi_searcher_info() to conditionally set processors
Comment #18
PlayfulWolf CreditAttribution: PlayfulWolf commentedWas looking for similar solution - it would be great, if url structure between exposed filters and faceted search could be unified to get both for the same view.
Perhaps a separate views sub-module could be a solution, like BEF?
Comment #19
batdesign CreditAttribution: batdesign commentedForgive me if this the wrong arena for this. I am new to both Search API and Facet API.
I am building a directory site which needed both a way to search by a listing name and display results with taxonomy. facets for further filtering, and I needed taxonomy links on the homepage that would show listings with those facets active.
My solution, which may be absolutely demented, I dont know was this:
Search index with 2 facets for my relevant taxonomies.
A search api view, to list all relevant fields. On this view An exposed search filter as a block.
A view on my homepage that lists my taxonomy name, with tid as hidden field.
I rewrite the taxonomy name field as a link, prefixing with the path to the search view, the facet result path, and passing the term name and tid so it matches the url pattern of an active facet.
I used facet pretty paths to make this easier on me.
I set the block to appear on all pages.
This seems to work fine.
Is this a sensible way to achieve this, or am I missing something vital here?
Comment #20
das-peter CreditAttribution: das-peter commentedI've started to combine the approach provided by @mErilainen and @Soul88.
The attached patch contains a dedicated module which will be located in
facetapi/contrib/views
.Features:
Not yet tested with Facet API pretty paths or similar modules.
Comment #21
andypostAwesome idea and clean approach!
Comment #22
das-peter CreditAttribution: das-peter commented@andypost I'm not really happy about the form field injection in the views handler. But it was the only way I could think of how I can use
facetapi_get_active_searchers()
to get the searcher of the actual view too. Another possibility would be to load all searchers but that could bring quite some overhead.Comment #23
GaëlGIs this supposed to work with text exposed filters like search_api_views_fulltext?
Comment #24
pinkonomy CreditAttribution: pinkonomy commentedAfter applying the patch I still cannot make exposed filters work with facets (Facet api + search api views).
EDIT:Finally it works without using the previous patch.
Comment #25
mErilainen CreditAttribution: mErilainen commentedThe patch looks good! I tested it on the same project I had to create my custom solution for about a year ago, and it seems to work fine. The options to enable it per search index rock!
I did minor changes to the instructions and moved the FacetAPI Views module under Search Toolkit where other FacetAPI modules are located. I'm marking this as reviewed because I only made some non-functional changes.
Including a diff.txt of the small changes I made.
Comment #26
jlapp CreditAttribution: jlapp commentedI tested the patch in #26 and had some issues with it - it did not work for single-value facets/exposed filters. I'm attaching an updated patch that fixed the issue for me along with an interdiff file with the changes I made compared with #26.
Comment #27
jlapp CreditAttribution: jlapp commentedThere's an issue in the patches from #26 where non-facet query string parameters were not being persisted when selecting/deselecting facets. I've resolved that in the attached patch and am also including an interdiff file from #25.
Comment #28
pinkonomy CreditAttribution: pinkonomy commentedI applied the patch from #27 but the facet string in the url is of type f[0]=field__fuel_type_%3A1
Am I missing something?
Comment #29
pinkonomy CreditAttribution: pinkonomy commentedHas anyone any luck with this patch?
Comment #30
pinkonomy CreditAttribution: pinkonomy commentedAny news on this? :)
Comment #31
Bès CreditAttribution: Bès commentedHello,
it seems that patch work with only one facet active. When i have 2 facets or more, as multiple facets have the position "0" inside they proper facets, we lost some of them when merging parameter inside "f".
Removing the $pos during the fetchParams() seems to fix that, but i'm still not sure of all the implication.
Comment #32
cpliakas CreditAttribution: cpliakas commentedTo me this is a great candidate for a separate contributed module. Would love to see this as it's own project, and would be happy to link to it on the project page. That way it can continue to innovate at it's own pace and get the attention that it deserves.
Comment #33
alCHE CreditAttribution: alCHE commentedWorks great, but the problem is when user select option "Any" in Views exposed filter and there is no results when there should be all results displayed. Any known solution for this?
Comment #34
aelling CreditAttribution: aelling commentedI am also experiencing what #33 reports. Is there a known work around?
Comment #35
pinkonomy CreditAttribution: pinkonomy commentedWhat about if the facet has taxonomy hierarchy?
#33 didn't work for me...
Comment #36
pinkonomy CreditAttribution: pinkonomy commentedAny news on this?
Comment #37
cpliakas CreditAttribution: cpliakas commentedRespectfully marking as won't fix.
This is a great idea and some good code, but as mentioned in #32 it would be best for this to be it's own contributed module so that it can innovate and improve at it's own pace.
Thanks for all the work on this issue and I look forward to linking on the project page!
Chris
Comment #38
geek-merlinThis is great stuff that works well for me. So i did some Improvement on it and added it as full project.
https://www.drupal.org/project/facetapi_views
Any one like to join as co-maintainer - go PM me!
A link on the project page is appreciated.
Comment #39
geek-merlinJust added mErilainen as comaintainer. Welcome aboard!
Comment #40
NWOM CreditAttribution: NWOM commentedI'm excited to see that this being worked on. Thank you! Here are a few URL persist sandbox modules that may help that were created for similar fixes.
VEFKUP - views exposed filters keep URL params
Persist url params
Comment #41
ropic CreditAttribution: ropic commentedNice work ! but it's breaking my pretty alias feature with "Reuse term aliases"
Comment #42
mikemadison CreditAttribution: mikemadison at Pacific Northwest National Laboratory commentedReally like the direction facetapi_views is taking, this (at first glance) seems to address the problem raised in this ticket. I'm curious however, if it makes sense to roll a separate module for this feature. I think most people are going to use Facet API in the context of views, and making the facets themselves play nicely with Views features seems to be a high priority. Is there any way of rolling the work being done on facetapi_views into the core facetapi module (or adding it as a contrib module inside facetapi) so that people don't have to go and look for a separate solution?
Again, thank you to axel.rutz and team for the hard work here! Looking forward to a release of the facetapi_views module.
Comment #43
DamienMcKennaBTW there's a patch in #2378945: Facets are lost by Views on keyword search for Search API that resolves this problem automagically :)
Comment #44
geek-merlin@damien #43:
> ...that resolves this problem automagically :)
would this obsolete (parts of) this module?
Comment #45
DamienMcKennaI haven't tested the module, the code solved the problem I had.
Comment #46
mErilainen CreditAttribution: mErilainen at Wunder commented@damien, not sure if it helps with the use case I had originally: Using Views filters for example in a site front page, then switching to facets on the results page. The problem with facets is by design, that they make a query on each click or selection, and it's not suitable for every use case.
Comment #47
Summit CreditAttribution: Summit commentedHi, Is this succeeded now for Drupal 7 please?
Thanks for sharing the answer, greetings Martijn