hook_search_api_query_alter()'s implementation within search_api_facets module checks to see if a search facet block has been enabled, and if it has, the allows for it's queries to be altered. This, however, completely depends on the core block enabling methodology if you wish to utilize a facet's query altering at all, and is VERY frustrating to use in a page_manager scenario.

Let me illustrate:

Search_api provides its own pages module, but ctools page_manager is more flexible/well developed. Utilizing search_api's built in views integration, we can provide a view as a context to page_manager/panels and reproduce all the capabilities of search_api_pages and much much more, however adding facets to the page requires me to not only add them to the page_manager page, but to also ensure they are enabled in the drupal blocks ui. This really should not be necessary, it'd be nice to have a more generic methodology for caching the fact that these blocks are turned on. I'm happy to help in this regard if a few more details concerning search_api's query_altering can be provided. What would be the best place to try to hook into this?

Initially I had hoped to be able to check if we have a page_manager page available to us, and if so see what blocks are enabled on it, however the hook_search_api_query_alter() happen before a page is established, (it seems). Again, any direction on this would be GREATLY appreciated.

Eclipse

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EclipseGc’s picture

Title: Facet Static Caching inssuficent » Facet Static Caching insufficient

I apparently can't spell today.

drunken monkey’s picture

Ah, interesting, another use case I didn't think about …
You are right, currently facets are hard coded to use core blocks, and in this case this really is a problem. However, as I understand it, the only problem here is the use of search_api_facets_by_block_status() in search_api_facets_search_api_query_alter(), right? This code is only there so only the used facets are requested from the search server — removing the function call shouldn't do any harm except cause a slight performance drop if you have facets which are enabled but are not used (because their blocks are turned off). And as I'd say that enabling facets that they don't intend to use is the users' own problem, I think it wouldn't hurt if I just removed that call (and, hence, the whole ugly function).

Will do it some time in the next few days, I think, if nobody objects. If it wouldn't be too hard, could you please verify before that this would really solve your problem? Just replace said function call with FALSE and see what happens.

I can't really think of any cleaner or more general way to check if a facet is used, so I'll just have to trust the user there. And, as I just realized, the current way doesn't take blocks that are enabled only on certain pages into account. So, probably no big harm in just removing this.

drunken monkey’s picture

Title: Facet Static Caching insufficient » Remove search_api_facets_by_block_status()
Category: bug » feature
Status: Active » Needs review
ygerasimov’s picture

I have same situation. When you build a panel and add facet blocks to it, they do not work untill you enable these blocks in blocks system that is completely not obvious.

After removing search_api_facets_by_block_status() function and replacing its call with FALSE everything starts working.

Here is patch to fix this issue.

drunken monkey’s picture

Status: Needs review » Fixed

Sorry for not fixing this earlier, but when the issue creator seemingly doesn't care …
Thanks for jumping in and even creating the patch! I just committed it slightly modified), everything should work now.

Status: Fixed » Closed (fixed)

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

7wonders’s picture

Status: Closed (fixed) » Active

I believe im suffering the same issue here which is why I have re-opened this issue. My apologies if that is not the correct thing to do in this situation. I am using most recent dev of search_api, search_api_solr, ctools, panels and beta3 views. I am trying to get a taxonomy facet into a panel view but cannot for the life of me figure it out. When using the facet blocks normally, the facet appears (how do I default the facet as open instead of closed with a more link?) but when trying to get the facet block in panels I get nothing. Enabling the block then means the block ends up above the panel in its usual place instead of within the panel. How to enable the panel facet block?

Thx for any help.

drunken monkey’s picture

Since the problem really sounds similar, re-opening this issue was the right thing to do, no worries.
However, I'm at a bit of a loss here, as I don't use, nor know much about Panels, and can't think of something that might cause such problems …
Does it work with other facet blocks?
And to what extent could you help debugging? Are you a developer, or do you know how to apply patches? I'll see if I can reproduce this myself (in the next few days), otherwise such help would probably be needed to solve this.

how do I default the facet as open instead of closed with a more link?

Oh, hadn't thought that anybody would want to do that. I fear this isn't possible normally, you'll have to do this in your theme. (Simply simulating a click on the "more" link via Javascript should suffice.)

7wonders’s picture

Other facet blocks - no, its not working with any of the ones I am using (integer, decimal and taxonomy).

Im not a developer, limited php at the best. I do know how to apply patches though :) I can manouver around drupal semi ok though. Could this be something related to contexts needing to be passed to the panel? I see in the contexts section of panels that Search facet, index, page, server and sort are all available but im still getting my head around the whole panels context stuff. I will have a play around and see if it makes any diff.

The more link is actually a "feature" of using the 0 or blank for no limit to the amount of terms showing. By setting it to a number that I knew would cover the amount of terms I have opened the facet by default. So in other words, using the no limit feature will just give a more link (bug??).

EclipseGc’s picture

So, I've not had a chance to try this myself, the project I was doing all this work for got side tracked for a bit.

Try telling panels to kill all the sidebars on the page (I'm assuming the facet block is placed in a sidebar) and see if it shows up in the panel as desired after that. Just a hunch.

Eclipse

drunken monkey’s picture

The more link is actually a "feature" of using the 0 or blank for no limit to the amount of terms showing. By setting it to a number that I knew would cover the amount of terms I have opened the facet by default. So in other words, using the no limit feature will just give a more link (bug??).

Sounds like a bug, but I don't know exactly what you mean. Anyways, this is completely unrelated, so please create another issue and explain in detail what you do and what happens. (E.g., are you entering 0 for "Number of terms" or for "Total number of terms"? And do you check "Display 'more' link"?)

And yes, please test EclipseGc's hunch – better then my completely uninformed guesses.
Otherwise I'll come up with some patch for debugging.

7wonders’s picture

Sadly I had already tried that and it does not work (just tried again and still nothing even with "Disable Drupal blocks/regions" option checked).

drunken monkey’s picture

First round of debugging: Please apply the attached patch and tell me what message(s) you see on the page on which the facet block should be displayed.
For easier debugging, please enable only a single facet and add its block to the panel.

7wonders’s picture

Status
$search_ids[games_field_gamecategories] is not set.

drunken monkey’s picture

Nothing else? That's weird …
Let's try another one …
Also, to be sure: "games_field_gamecategories" is the correct delta of the facet block you are trying to display, and the facet is enabled in the index's "Facets" tab?

7wonders’s picture

How do i check the delta is correct? The field is called field_gamecategories and the index is called games so im guessing this is correct??

The facet is 100% enabled and functions outside of a panel.

Will get back on the debug shortly.

7wonders’s picture

Status

search_api_facets_search_api_query_alter() called.
Access allowed.
Looking at facet games_field_gamerecommendation ...
-> Added to $active.
Looking at facet games_field_gamemetascore ...
-> Added to $active.
Looking at facet games_field_gamecategories ...
-> Added to $active.
Looking at facet games_field_gametags ...
-> Added to $active.
Looking at facet games_field_gamerecommended ...
-> Added to $active.

drunken monkey’s picture

Hm, seems to be alright …
But maybe the wrong function is called first? Displaying a facet block before the search was executed of course wouldn't work.
Please debug again with the attached patch.

7wonders’s picture

Looks like the facet is called first:

Status
search_api_facets_block_view(games_field_gamecategories) called.
search_api_facets_search_api_query_alter() called.
Access allowed.
Looking at facet games_field_gamerecommendation ...
-> Added to $active.
Looking at facet games_field_gamemetascore ...
-> Added to $active.
Looking at facet games_field_gamecategories ...
-> Added to $active.
Looking at facet games_field_gametags ...
-> Added to $active.
Looking at facet games_field_gamerecommended ...
-> Added to $active.

drunken monkey’s picture

Status: Active » Fixed

Oh, OK, then that solves it. Or, at least we know what's going wrong.
The question now is: How can we solve this? There's really no way to solve this in the Search API, I think – you'll have to somehow make Panels execute the search display (I guess that's a view in a panel as well?) before it tries to get the facet blocks. Maybe ask in the Panels issue queue how that can be done.

7wonders’s picture

Status: Fixed » Active

wow, that was easy to solve just off a hunch once I knew the problem!!!

Problem: I had a canvas with 2 columns, each column with a single row and each row with a single region (left and right, quite a normal usage of panels). This meant that no matter where I put the facets and the search_api view, they were being called at the same time and the search_api block view was NOT taking precedence as figured out above.

Solution: I simply added a further region to the right column/row under the existing region and moved the view into that region (leaving a now invisible unused region). That changed the priority to be correct for some reason and voila, it works :)

Many, many thanks for your time Mr Monkey :) When I get everything up an working I will try and write a short explanation so no-one else falls into this problem!

7wonders’s picture

EclipseGc’s picture

Status: Active » Fixed

Oh uh yeah... so actually if you'll utilize a "context display" the order in which you place stuff in the panel will cease to matter. Utilizing any other type of view will cause this "ordering" problem.

The context view is the proper solution even if it is a little more complicated. Look into it and ping me on irc if you have issues, I'm happy to help.

Eclipse

MrMaksimize’s picture

Tried this, and still doesn't work :(

MrMaksimize’s picture

So I tried both #23 and #21, and nada :( I ended up sticking a view on top of my left column, and tricking it that way. But that's dirty. maybe there's a way to run a view bootstrap? What exactly does it look for to know that the view has been initialized?

MrMaksimize’s picture

oh and sorry one more - search_api_facets_by_block_status() which file is this function in?

drunken monkey’s picture

search_api_facets_by_block_status() is in no file anymore, and it was in the search_api_facets.module file previously.

For advice regarding Panels and Views, please go to their respective issue queues. Re-ordering the order panels are built hasn't got anything to do with the Search API.
The thing that has to have happened before building the facets block is that the search query has to be executed. It doesn't check at all whether a view is present or built. If the search query comes from a view, the view will have to already be executed.

7wonders’s picture

EclipseGc actually gave me a quick walkthrough on how to do this the "proper" way. It takes a bit more time and effort but its a lot more flexible and effective (plus it works without having to try and figure out the order of blocks like above). The basics of it are:

1. Create a context view for your display.
2. Go to contexts in your panel and add a view context with your view.
3. You will now have a new "view context" option when adding content to a region.
4. Choose view row (this is where it gets a bit more complexed as you have to manually build grids etc using regions and rows and so forth).
5. You can now add your facets using the miscellaneous content option in panels wherever you want in your panel!
6. I had to use to the default view exposed forms as the context view exposed forms didnt want to inherit the path. These can also go wherever and work!

Search API and Panels = wonderful :)

Side question: How to get checkbox facets instead?? Feature request or am i missing something?

EclipseGc’s picture

7wonders:

on your #6, within the context view display in the views UI there's a "use page path" option. Set that to true, and it will work for you as desired.

MrMaksimize:

In ctools, there's a module called views_content. Enable that, it will give you "content_panes" and "context" view displays (likely you're familiar with adding page and block views, this is done the same way but these are page_manager/panels specific solutions.

Then follow 7wonders little 6 step process above.

drunken monkey’s picture

Thanks for the detailled explanation! I made a note to include it in the documentation once I start creating handbook pages. Such an explanation will definitely be valuable for a "Known problems / fixes" section.

Side question: How to get checkbox facets instead?? Feature request or am i missing something?

Definitely a feature request, and a rather hard one at that. There is currently no way to do "OR" facets in the Search API, introducing them would be a rather large API change. So I don't know if this will be done …
See #988276: Support Configurable OR | AND Facets for the issue.

Status: Fixed » Closed (fixed)

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

Ilbaboomba’s picture

Status: Closed (fixed) » Active

Hi, sorry to reopen this but I'm having the same problem and solution #28 didn't solve for me...
I'm using Drupal 7.9, CTools & Entity API & Search API 7.x-1.0-rc1, Facet API 7.x-1.0-beta8, Panels 7.x-3.0-alpha3, Views 7.x-3.0-rc3.
Facet blocks show up only when placed after the search view, if I try to place them above or on the left of the view, they disappear.
Context view solution doesn't work either :(

EclipseGc’s picture

I can confirm that this is definitely true, I have a local fix in which I iterate over all of search_api's facet blocks and provide them as content_type plugins in panels separately from the typical provisions for them. In this separate version I set render last to true on the content type and that helps immensely. I have still not had time to drop a patch on this issue, will see if that might be doable this week.

Eclipse

drunken monkey’s picture

Title: Remove search_api_facets_by_block_status() » Problems with Context/Panels and facets
Category: feature » support

You are free to discuss this here, but I'm pretty sure we really can't fix this in our module. This has to be handled by Panels somehow.

EclipseGc’s picture

Yes and no... ctools has this block alter thing for blocks it's turning into content types. It doesn't really work, and even if it did, you'd need to utilize it to tell it that all facets you're defining need to render last. Best to just build a content_type plugin for this and render last in it.

jaxxham’s picture

Hey, I'm having the same problem - created a facet block in views that's not appearing in panels.

Jon Pugh’s picture

re:#33 Any chance we can get that patch? Sounds like a good solution...

osopolar’s picture

Status: Active » Fixed

I guess it is about "Facet blocks show up only when placed after the search view" ... using facetapi. Search-API can't do anything on this. I mark this as fixed.

see: #1018420: Allow the possibility to control the order in which content is rendered #14 and following.

Status: Fixed » Closed (fixed)

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

larowlan’s picture

for those wanting a solution see: #1669908: hook_ctools_content_subtype_alter() does not run early enough patch has been committed to facetapi but still requires panels to be patched.
You need the latest dev release of facetapi.

queenvictoria’s picture

This didn't fix the facets paths with Panels, non-search pages and Facets for me.

But what did was this patch over here. I've written up my technique over there based on #6 over here.
http://drupal.org/node/1863866#comment-7278934