This works fine using the old facets module in Search API, but when I upgrade to the new Facet API powered Search Facets module, clicking on the facets doesn't trigger the update of the search results using ajax. Meanwhile, the pager continues to work fine updating the search results with ajax.

Can you help?

CommentFileSizeAuthor
#36 1341704-36.patch32.12 KBAnonymous (not verified)
#30 search_api_ajax-fix-facetapi-integration-1341704-30.patch13.95 KBjsacksick
#13 search_api_ajax.zip77.98 KBAnonymous (not verified)
#12 manually-patching.zip7.07 KBscotjam
#11 1341704-10.patch11.39 KBAnonymous (not verified)

Comments

Anonymous’s picture

I have it working with Facet API without issues. The Search API facet links aren't any different. So if you had it working with olds Facets, there is no reason it would stop working. What other things did you change?

Anonymous’s picture

Status: Active » Postponed (maintainer needs more info)
scotjam’s picture

I've not changed anything other than uninstall old facets, then install and configure new facets, and add facet blocks to theme.

here's my facet link with the old facet module... which works for me

http://example.com/search/quis?filter[author%3Aname][0]=%22Anonymous%22

and the html...

<ul class="search-api-facets"><li class="first"><a href="/search/quis?filter[author%3Aname][0]=%22Anonymous%22" class="search-api-facet-value active">Anonymous</a> <span class="search-api-facet-count">(9)</span></li><li><a href="/search/quis?filter[author%3Aname][0]=%22admin%22" class="search-api-facet-value active">admin</a> <span class="search-api-facet-count">(6)</span></li><li><a href="/search/quis?filter[author%3Aname][0]=%22hefritrocrip%22" class="search-api-facet-value active">hefritrocrip</a> <span class="search-api-facet-count">(4)</span></li><li><a href="/search/quis?filter[author%3Aname][0]=%22thatridrob%22" class="search-api-facet-value active">thatridrob</a> <span class="search-api-facet-count">(4)</span></li><li><a href="/search/quis?filter[author%3Aname][0]=%22jithawech%22" class="search-api-facet-value active">jithawech</a> <span class="search-api-facet-count">(3)</span></li><li class="last"><a href="/search/quis?filter[author%3Aname][0]=%22swesedidrina%22" class="search-api-facet-value active">swesedidrina</a> <span class="search-api-facet-count">(2)</span></li></ul>

here's with the new facet module... which doesn't work for me

http://example.com/search/quis?f[0]=author%253Aname%3AAnonymous

here's the html...

<ul class="facetapi-facetapi-links facetapi-facet-authorname facetapi-processed" id="facetapi-facet-search-apiapache-solr-index-block-authorname"><li class="leaf first"><a href="/search/quis?f[0]=author%253Aname%3AAnonymous" class="facetapi-inactive">Anonymous (9)</a></li><li class="leaf"><a href="/search/quis?f[0]=author%253Aname%3Aadmin" class="facetapi-inactive">admin (6)</a></li><li class="leaf"><a href="/search/quis?f[0]=author%253Aname%3Ahefritrocrip" class="facetapi-inactive">hefritrocrip (4)</a></li><li class="leaf"><a href="/search/quis?f[0]=author%253Aname%3Athatridrob" class="facetapi-inactive">thatridrob (4)</a></li><li class="leaf"><a href="/search/quis?f[0]=author%253Aname%3Ajithawech" class="facetapi-inactive">jithawech (3)</a></li><li class="leaf last"><a href="/search/quis?f[0]=author%253Aname%3Aswesedidrina" class="facetapi-inactive">swesedidrina (2)</a></li></ul>

happy to provide more info as needed, can you advise what I should look out for?

scotjam’s picture

I can confirm that I don't make any other changes other than switching from old facets to new facets.

I've tried this a few times now, making no other changes other than switching from old facets to new facets and back again, but still get the same problem.

The facet URLs do look different with the new facets and the HTML around them using different classes. It might not be a bug though, any support appreciated.

Anonymous’s picture

Status: Postponed (maintainer needs more info) » Active

Ok, I dont't know yet. One possibility is that the block ID's or classes have changed, and search_api_ajax.js no longer "sees" the right blocks to trigger the ajax link. You might have to debug the JS near Drupal.search_api_ajax.ajax = function(selector) { and see why the links aren't triggered anymore. Hard to tell. It's still working for me after I switched.

scotjam’s picture

Looks like the page is refreshing well before this line, as mentioned above.

I'm not clued up on javascript, so can you point me to where the browser is asked to do something when a link is clicked?

scotjam’s picture

Update...

I've added a sort block and that works, but the facet blocks still don't.

In search_api_ajax.js using firebug, I've noticed that in the code where it says...

if(Drupal.settings.search_api_ajax) {
var blocks = Drupal.settings.search_api_ajax.blocks;

blocks only contains...

Object { search_api_sorts_search-sorts="#block-search-api-sorts-search-sorts"}

Should it have more, say one for each of the facet blocks?

The other blocks have ID's like...

'#block-facetapi-vrsb2bszzhm2kr6izoivsltv5wnqlu6t'
'#block-facetapi-3mxxejvq-3sriok3j3i48prrfv59epsd'
'#block-facetapi-z1tv-nxxqmsdj31owsqglqgcjovjjk7k'

Any ideas on what next steps to take to debug?

What's interesting is that sorts block works, so the regions are okay. For some reason facet blocks don't get picked up.

You can probably tell I am clutching at straws :)

Anonymous’s picture

Yes indeed, it should have all the facet blocks in "var blocks".
I thought I added them in the latest devx of the search api AJAX module? Which version are you using exactly?

For example in search_api_ajax_modules() it should show them:

function search_api_ajax_modules() {
  static $modules = NULL;
  if (is_null($modules)) {
    $modules = array(
      'search_api_facets',
      'search_api_ranges',
      'search_api_sorts',
      'search_api_widgets',
      'facetapi',
      'facetapi_tagcloud',
    );
    drupal_alter('search_api_ajax_modules', $modules);
  }
  return $modules;
}
scotjam’s picture

I'm using the latest dev version on the project page, dated September the 8th.
It does have that bit of code in the file you mention.

But it doesn't have the facetapi lines...

function search_api_ajax_modules() {
  static $modules = NULL;
  if (is_null($modules)) {
    $modules = array('search_api_facets', 'search_api_ranges', 'search_api_sorts', 'search_api_widgets');
    drupal_alter('search_api_ajax_modules', $modules);
  }
  return $modules;
}

I'll add them in and try again.

Anonymous’s picture

Damn, in that case I must be running way behind with my updates. I thought I pushed this through already. I have check my changes and will post a patch here soon!

Anonymous’s picture

StatusFileSize
new11.39 KB

Here is a patch with my latest work on the module,
- includes update for facetapi
- includes updates for Views and taxonomy paths

scotjam’s picture

StatusFileSize
new7.07 KB

Thanks for the helps on this. This is weird, now nothing works as ajax :( I'm assuming nothing is wrong with your patch because it works for you. So the problem is my attempt at patching the files. I've tried to apply the patch a few times but as I don't have any patching software I'm trying to do it manually, attached. Will you get a chance to commit the patch any time soon?

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new77.98 KB

Attached a full update. Can you please try it? (after flushing Drupal cache)
And let me know what happens.

scotjam’s picture

Thank for that. I'm trying this out with Bartik and with Omega themes, and changing the regions etc to match.

With Bartik, the ajax spinner triggers, the url changes, but the page refreshes instead of ajax refresh. With Omega, the page dims, scrolls up, but no spinner appears, and that's it.

At what point should I give up :)

stopshinal’s picture

@ morning time - does this work with views?

Anonymous’s picture

Yes I have it working with Views, Views panes on Panel pages and even Taxonomy/term/% pages. But maybe I broke a lot of stuff trying to achieve all this... Early december I have time to do a proper review and stabilize the work.

mrfelton’s picture

Seems to work very well. I'm using it with Views. However I did find that if you set a views page path to be the site's homepage, then it no longer works.

mrfelton’s picture

Also, there is no ajax when removing a facet - only when adding new ones.

scotjam’s picture

This is interesting...

With views, everything works right. selecting facets and unselecting them results in ajax update of the view. The exposed form search query isn't set to auto-update the view, but I'm guessing that's because it not implemented. So, really, this works fine for me. I'll continue to explore more and feedback any thing that might be useful.

Without views, it doesn't work, for me anyway. I don't know that's because its only supposed to work with views. My previous comments have been from the perspective of not using any views and just using the search api search pages. So, is this expected? or should this module work with and without views?

Hope this helps.

Anonymous’s picture

Yeah the patch breaks the search api pages... So I have to go back to the drawing board.
To work with exposed Fulltext filter in views, I created a custom block with a form with id "keys". The views exposed filter is renamed to "query" so you get /myview?query=Keys. That should work.

Anyway, this patch needs more work to fix the Search Pages.

uditmahajan’s picture

Its not working for me too... I have a view page created on my Search Index. Facets blocks and everything is shown perfectly fine but the spinner does not disappear. Perhaps I am doing something wrong here?

I also patched my search_api_db (http://drupal.org/node/1390586#comment-5443010) and search_api (http://drupal.org/node/1390598#comment-5443016) with Damien Tournoud patches for supporting the "OR" operator. Could that be the problem here?

I also found out that my spinner continues to spin because an error is returned by the AJAX callback (Drupal.search_api_ajax.response_callback at line 89 in search_api_ajax.js), but there is no error callback defined. Some of the data is returned but with error. I even tried to debug but no exception or error was thrown there.

@ morning time - Any idea? I am trying to understand the code, perhaps you could give me some pointers here so I can get a head start. I would even love to contribute to this module as I am requiring this functionality heavily in my upcoming venture.

jaxxham’s picture

Hi, I'm not having any luck with this module either - using Search API and Facets API. I also did something with my custom module that drove my server bonkers (CPU was over 500% - must've made some mistake with Ajax...). Are there any updates coming for this module?

Thanks!

uditmahajan’s picture

Okay, I found the problem. It was more of a access callback issue then anything else. I am trying to streamline it to match the actual access on the page/view (rather than hard-coding it).
One problem I found that facet remove links do not support ajax. Again a simple javascript fix will do.
If i am able to fix all this, I will try and upload a patch.

118218’s picture

Can you help me run this module?

Here are my issues:

Before the patch in # 13

1) I can not do a search using the search box of views. Nothing happens! (Enter or click)

2) The sorting works, but not the facets. The facets load new pages.

3) Only works when I'm logged in admin.

After the patch in # 13

1) I still can not use the search box of views

2) The sorting does not work, the spinner starts but keeps running. Same for the facets.

Any idea? I use the theme Bartik and the example you provide in Search Api ajax page.

bianchie’s picture

subscribing

mitch albert’s picture

subscribing

cviccaro’s picture

I've been able to get this working on my D7 site using search api, facet api, running on solr backend. Had to do some dsm's and console.log's in each of the respective ajax files (.module and .js) to figure out why it was not working, but ultimately found the culprit to be modified block ID's that were not matching the ones stored in the system, so the search_api_ajax module was not able to locate any of the links. After I fixed this, it is working.

Working example here: http://www.jpecatalogs.com/search

Couple bugs to note, is when you kill a filter (hit the minus) it can (usually does) returns a page as if there is no search query.

My custom code is extremely simple:

/**
 * Implements hook_search_api_ajax_settings().
 */
function jpewidget_search_api_ajax_settings() {
    $spnr = 'ajax-loader-white.gif';
    $regions = array('content_right' => '#region-content-right');
    $settings = array('content' => '#content_bottom');
    $settings['regions'] = $regions;
    $settings['spinner'] = $spnr;
    $settings['scrolltarget'] = '#main';
    $settings['scrollspeed'] = 1000;
    $settings['fade'] = 1;
    $settings['opacity'] = 0.3; 
    return $settings;
}
cviccaro’s picture

Update on previous comment, I got the "minus" filter working. In search_api_ajax.js, function Drupal.search_api_ajax.navigate (starts @ line 118), change function

FROM:

Drupal.search_api_ajax.navigate = function(url) {
      if(url !== undefined) {
        YUI().use('history', function(Y) {
          history.add({
            q : Drupal.search_api_ajax.url_to_state(url)
          });
        });
      }
      return false;
    };

TO:

    Drupal.search_api_ajax.navigate = function(url) {
      var splitUrl = url.split('/');
      var aquery = window.location.pathname.replace('/search/','');
      if (splitUrl[1] == "search_api_ajax" && splitUrl[2] == "search" && splitUrl.length == 3) {
      	url = '/search_api_ajax/search/' + aquery;
      }
      
      if(url !== undefined) {
        YUI().use('history', function(Y) {
          history.add({
            q : Drupal.search_api_ajax.url_to_state(url)
          });
        });
      }
      return false;
    };

*Note*: Not sure how it will fair with multiple filters being enabled, and using the (-) on just one. Should work since the "url" var won't be undefined, though.

meji15’s picture

@cviccaro: What version did you use to get it working? Is it the origianl dev version (2011-Sep-08) or the patched on at #13?

jsacksick’s picture

I took the patch from #10 and did some modifications.
I tried with views + facetapi and it worked after those modifications.
Now, it also works with the checkbox widget of facetapi (I had to unbind the facetapi click event attached to the checkbox and I replaced it with a custom event.)
At the very end of the search_api_ajax.pages.inc module there were a call to context_get_contexts without the if (module_exists('context')) verification and causes an infinite ajax loading. Besides that verification, I'm not sure this line alone is really useful, So I removed it.
I also used drupal_http_header instead of header + replaced print json_encode by drupal_json_encode, and I think that's almost it ... We need to move on this issue maybe merge the patch and create other issues If we still have but this patch is a really great progress.

Anonymous’s picture

Thanks so much, jsacksick! Will review this very soon, after I take a good look at it. Thanks again,

Anonymous’s picture

By the way, the context lines are needed if you show Blocks through the Context module. Otherwise these blocks don't show up in the AJAX JSON (Drupal doesn't know about them). So I will add those lines back in, with module_exists() of course

multpix’s picture

original dev and #30 with Facet API works for me

thanks jsacksick,
thanks morningtime

but search_api_ranges has stopped working

peace

jsacksick’s picture

As a possible improvement, I think we can replace the delivery callback of menu items and use this instead http://api.drupal.org/api/drupal/includes!ajax.inc/function/ajax_deliver/7

Anonymous’s picture

@multipix I'll do some work on the ranges. There is an upcoming Prett Facet Paths integration, so will also update the AJAX to work with pretty paths.

Anonymous’s picture

Status: Needs review » Fixed
StatusFileSize
new32.12 KB

Ok, for now, I just wanted to get this major patch working. I've been testing extensively and it looks really good. Since the current devx was broke, I decided to go ahead and commit this. Full patch attached. The attached patch includes and updated jquery.livequery.js to latest version, which has performance improvements, not really functional changes. And some code formatting/cleanup.

Thanks for all your work and feedback @jsacksick, @multipix

We can open new issues for improvements! Thanks so far.

Committed to devx,
http://drupalcode.org/project/search_api_ajax.git/commit/dff04a8

Status: Fixed » Closed (fixed)

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