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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mErilainen’s picture

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

cpliakas’s picture

Status: Active » Closed (duplicate)

Hi 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

mErilainen’s picture

You "cross posted" that issue to itself ;)

cpliakas’s picture

mErilainen,

Ha. I suck at the issue queue. Re-cross posted.

Thanks for picking that up,
Chris

mErilainen’s picture

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

mErilainen’s picture

FileSize
4.84 KB

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

mErilainen’s picture

FileSize
4.87 KB

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

cpliakas’s picture

Status: Closed (duplicate) » Active

Thanks 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

mErilainen’s picture

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

mErilainen’s picture

FileSize
5.5 KB

Okay, 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

cpliakas’s picture

Excellent blog post by Wunderkraut on this topic.

alexweber’s picture

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

quardz’s picture

Nice module, Search API is heavy for my shared hosting. Needs to add Dependence in info file.

gettysburger’s picture

This is exactly what I need. Three cheers. I have not tried it out yet but will today. Thanks!

SandraVdv’s picture

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

Soul88’s picture

Maybe this will help someone: http://drupal.org/sandbox/Soul88/1865682

andypost’s picture

I 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

PlayfulWolf’s picture

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

batdesign’s picture

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

das-peter’s picture

Status: Active » Needs review
FileSize
14.41 KB

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

  • Configure the url processor per searcher.
  • Added a dedicated views filter handler that adds the current facets to the exposed form.

Not yet tested with Facet API pretty paths or similar modules.

andypost’s picture

Awesome idea and clean approach!

das-peter’s picture

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

GaëlG’s picture

Is this supposed to work with text exposed filters like search_api_views_fulltext?

pinkonomy’s picture

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

mErilainen’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.29 KB
14.62 KB

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

jlapp’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.19 KB
14.73 KB

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

jlapp’s picture

There'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.

pinkonomy’s picture

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

pinkonomy’s picture

Has anyone any luck with this patch?

pinkonomy’s picture

Any news on this? :)

Bès’s picture

Hello,

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.

cpliakas’s picture

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

alCHE’s picture

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

aelling’s picture

I am also experiencing what #33 reports. Is there a known work around?

pinkonomy’s picture

What about if the facet has taxonomy hierarchy?
#33 didn't work for me...

pinkonomy’s picture

Any news on this?

cpliakas’s picture

Component: Code » Contrib
Status: Needs review » Closed (won't fix)

Respectfully 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

geek-merlin’s picture

Component: Contrib » Documentation
Category: Feature request » Task
Status: Closed (won't fix) » Active

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

geek-merlin’s picture

Just added mErilainen as comaintainer. Welcome aboard!

NWOM’s picture

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

ropic’s picture

Nice work ! but it's breaking my pretty alias feature with "Reuse term aliases"

mikemadison’s picture

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

DamienMcKenna’s picture

BTW there's a patch in #2378945: Facets are lost by Views on keyword search for Search API that resolves this problem automagically :)

geek-merlin’s picture

@damien #43:
> ...that resolves this problem automagically :)

would this obsolete (parts of) this module?

DamienMcKenna’s picture

I haven't tested the module, the code solved the problem I had.

mErilainen’s picture

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

Summit’s picture

Hi, Is this succeeded now for Drupal 7 please?
Thanks for sharing the answer, greetings Martijn