Currently this module doesn't play nice with Facet API Pretty Paths

It would be great if it did. Not sure if this requires changes in this module, FAPP or both.

It currently receives no 'pretty paths' and when one range facet is applied it causes all the facet links to act as if no facet is applied (remove links link to the base search, add links link to the base search + just that one facet).

CommentFileSizeAuthor
#36 1511144-text-widget.patch2.1 KBstockliasteroid
#22 1511144-22.patch3.12 KBAnonymous (not verified)
#9 1511144-9.patch879 bytesAnonymous (not verified)
#6 1511144-6.patch3.88 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Shadlington’s picture

Issue summary: View changes

Extra info

Shadlington’s picture

Cross-posted at facet api pretty paths: #1511148: Please make compatible with Search API Ranges

giorgio79’s picture

Facet API Pretty Paths just implemented pluggability so this module can integrate with it..#1431682: Plan & implement pluggability

Anonymous’s picture

I support this feature, will have a look at that pluggability. If anyone is working on a patch, let us know.

Anonymous’s picture

Category: bug » feature
Anonymous’s picture

Status: Active » Needs review

Please help out over here:
http://drupal.org/node/1511148#comment-6166790

Closing this one.

Anonymous’s picture

FileSize
3.88 KB

Attaching a patch! Apply the patch and refresh the Drupal cache.

dasjo’s picture

hi morningtime,

glad to see you are using the coders plugin system for pretty paths!

one questions: how does SearchApiRangesCoderRanges differ from the base FacetApiPrettyPathsCoderDefault?
i can't see any differences in the current implementation and would suggest that you only override the methods that actually differ.
FacetApiPrettyPathsCoderTaxonomy is built in a similar way.

Anonymous’s picture

Alright, that's a good idea. I don't really need a separate Class. Will remove it

Anonymous’s picture

FileSize
879 bytes

This simpler patch should do the trick. No need for a separate coder file.

Anonymous’s picture

Status: Needs review » Fixed
dasjo’s picture

Status: Fixed » Active

hi,

again, i'm curious: why do you need to alter the facet info anyways? i suppose, the facetapi pretty paths module's default behavior would suffice to have it work if you don't implement a custom coder.

Haza’s picture

Priority: Normal » Critical
Status: Active » Needs work

This commit/patch add 2 times

+function search_api_ranges_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {

and results in

 PHP Fatal error:  Cannot redeclare search_api_ranges_facetapi_facet_info_alter() (previously declared in /xxx/modules/contrib/search_api_ranges/search_api_ranges.module:53) in /xxx/modules/contrib/search_api_ranges/search_api_ranges.module on line 76

This commit should be reverted. (and fixed ;) )

Anonymous’s picture

Status: Needs work » Fixed

@dasjo, (I think) because Search Api Ranges uses its own FacetAPi widget_links.inc with a different Controller Class.

@haza OK, I fixed the duplicate,
http://drupalcode.org/project/search_api_ranges.git/commit/5f847a9

Status: Fixed » Closed (fixed)

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

khiminrm’s picture

Please, help. Doesn't work for me. I've tried both dev and stable versions of the module, but "Pretty path alias" doesn't replace default field alias in the url. Have tried for different types of fields: taxonomy, decimal. Maybe I missed something. What should I check to find a solution? With dsm function I see that the code $facet['facetapi pretty paths coder'] = 'default'; applied to my facet block with slider widget.

khiminrm’s picture

I've did some research and found that the form in slider has action url without Pretty path alias for current facet. Is this correct? Because facets based on link widget already have url with pretty path aliases.

khiminrm’s picture

Maybe the solution would be to add Pretty path alias to $variables array in widget_links.inc file and use it in the search_api_ranges_block_view_form_submit function to build the path for drupal_goto function?
I have made some modifications in my local copy of the Search API ranges module and have some success.
I am not very strong in php and facet api. So dont judge me strongly.
I've added to widget_links.inc:
To get Pretty path alias for current facet


 $facet_current =$this->facet->getFacet();
 $facet_adapter = $this->facet->getAdapter();
 $facet_settings_global = $facet_adapter->getFacetSettingsGlobal($facet_current);
  $facet_settings_global = (array)$facet_settings_global;
  $facet_pretty_path_alias = $facet_settings_global['settings']['pretty_paths_alias'];

    $variables = array(
     /*  'range_field' => rawurlencode($this->facet['field alias']), */
      'range_field' => rawurlencode($facet_pretty_path_alias),
...

And in search_api_ranges.module:

if (module_exists('facetapi_pretty_paths'))$range_field = $range_field . '/';
else $range_field = $range_field . ':';
  $query = $range_field . '[' . $values['range-from'] . ' TO ' . $values['range-to'] . ']';
 $new_path = $path.'/'.$params['f'][0];
 /*  drupal_goto($_GET['q'], array('query' => array($params))); */
   drupal_goto($new_path); 

It works for me. But when I change ranges in slider for the second time, the path contains facet alias twice but the widget is still working.
First time after applying slider: http://mysite/catalog/videocard/price/[249 TO 1550]
Second time: http://mysite/catalog/videocard/price/price/[249 TO 979]

khiminrm’s picture

Status: Closed (fixed) » Needs review
Anonymous’s picture

You're right, we need to read the 'pretty path alias'. I couldn't figure out how to do that yet.
I'll have a look at this soon as possible.

khiminrm’s picture

@morningtime Hello. Thanks for your response! I've written in #17 how I get it in widget_links.inc:

 $facet_current =$this->facet->getFacet();
 $facet_adapter = $this->facet->getAdapter();
 $facet_settings_global = $facet_adapter->getFacetSettingsGlobal($facet_current);
  $facet_settings_global = (array)$facet_settings_global;
  $facet_pretty_path_alias = $facet_settings_global['settings']['pretty_paths_alias'];

But I think that this code may be shorter and simpler.

dasjo’s picture

i think the best solution would be if you could rely on generic facetapi functions in order to determine the paths. so no custom hacking would be required

Anonymous’s picture

FileSize
3.12 KB

A patch attached, try it out?

I found the path alias like this

    if (module_exists('facetapi_pretty_paths')) {
      $processor = new FacetapiUrlProcessorPrettyPaths($this->facet->getAdapter());
      $range_field = $processor->getFacetPrettyPathsAlias($this->facet->getFacet());
    }
khiminrm’s picture

I've just tested. Works! Thanks! Strange '?' in the end of the url, but it works with other facets. Great work!

khiminrm’s picture

I've noticed some strange behavior. It worked until copying tpl.php file or theme function for slider to my theme and flushing all caches. After applyng a patch I had urls like price/[245 TO 5000]?, price[245 TO 5000]/price[245 TO 2000]&? and all worked. Now I have one segment for multiple using of price slider and after using other facet the url became price/manufacture/asus/price/[245 TO 5000]. I've restored changes in my theme and clear cache, but no succes. I am testing further... Maybe I am doing something wrong.

khiminrm’s picture

Have found my problem: I had dsm function in my tpl file for views page. Slider works good when I removed this function.

khiminrm’s picture

One more issue when I applied the patch http://drupal.org/node/1539472#comment-6157996. When I use slider and other facet have wrong url: price/manufacture/asus/price/[245 TO 5000]. How to solve this? I need that patch for my site too.

khiminrm’s picture

Found temporary solution: replaced $_GET['q'] = $item['href'].'/'.$search; with

$_GET['q'] = $item['href'];
      if (arg(0)=='search')$_GET['q'] = $item['href'].'/'.$search;

in url_processor_pretty_paths.inc after applying that patch

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Ok thanks for testing. Will apply this patch, so we can go from there.

Anonymous’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

giorgio79’s picture

Status: Closed (fixed) » Active

This does not seem to work for me with i18n and locale installed, and getting htmlencoded paths like this

mysite.com/en/en/price/%5B6959%20TO%2026499%5D?

There is still a question mark added at the end.

The module worked fine with 1.3.

Anonymous’s picture

Hi, I think the html encoded path is correct, spaces will be %20 and brackets will be like %5B, %5D. The brackets aren't arrays like ?f[0] so that's why I think they are encoded correctly.

Let's see about the i18n paths indeed.

doliveros’s picture

Hello morningtime,

Although the range slider widget is compatible with pretty paths, I believe the link widget is not, as I'm still getting the previous query format: shop?f[0]=search_api_aggregation_1%3A[20 TO 30].

Do you think that applying #29 patch's code to widget_links.inc would solve the problem?

Thanks a lot.

doliveros’s picture

Status: Active » Needs work

Hello again, morningtime.

I've managed to get the link / range price facets working, and while I was at it, I discovered a strange behaviour / bug that should be noted:

I had 3 ranges: 0-50, 50-100 and 100-200, but only the 0-50 range was showing up. After some debugging, I found out the number of elements used to populate the ranges ($element = &$this->build[$this->facet['field alias']];) where getting hard-limited by the facet's configuration "Hard Limit: Display no more than this number of facet items."

I had it at 15, thinking the maximum number of range facets would be topped at 15. After setting the facet's hard limit to unlimited, the three filters appeared normally.

By the way, I got it working with the following code (Not sure how to create a patch file. You'll recognise these parts on "widget_links.inc" anyway):

+    $range_field = $this->facet['field alias'];

+    // Get facet path field/alias
+    if (module_exists('facetapi_pretty_paths')) {
+      $processor = new FacetapiUrlProcessorPrettyPaths($this->facet->getAdapter());
+      $range_field = $processor->getFacetPrettyPathsAlias($this->facet->getFacet());
+    };

    // Prepare variables for min/max query
    $variables = array(
      'element' => $element,
      'index' => $index,
+     'range_field' => $range_field,
      'query' => $query,
      'prefix' => $this->settings->settings['prefix'],
      'suffix' => $this->settings->settings['suffix'],
    );

and

+    // Replace ':' with '/'
+    if (module_exists('facetapi_pretty_paths')) {
+      foreach($element as $key => $e){
+        if (isset($e['#query']['f'])){
+          $element[$key]['#query']['f'] = str_replace(':', '/', $e['#query']['f']);
+        }
+      }
+    };

    // Sets each item's theme hook, builds item list.
    $this->setThemeHooks($element);
+   $items_build = $this->buildListItems($element);

+    // Replace ?f[0]= with /
+    if (module_exists('facetapi_pretty_paths')) {
+      foreach($items_build as $key => $build){
+        $items_build[$key]['data'] = str_replace('?f[0]=', '/', $build['data']);
+      }
+    }
    $element = array(
      '#theme' => 'item_list',
+     '#items' => $items_build,
      '#attributes' => $this->build['#attributes'],
    );
  }

It's probably not the best way to handle it, quite dirty, but did the job. Now I'm not sure why the selected price range always have the class "facetapi-inactive".

khiminrm’s picture

#34 works for me

stockliasteroid’s picture

FileSize
2.1 KB

Here's #34 as a patch...

Anonymous’s picture

Status: Needs work » Fixed

Thanks. #34 is now commited in the patch of #36. Committed to the dev-x branch.
http://drupalcode.org/project/search_api_ranges.git/commit/e56ae3d

Status: Fixed » Closed (fixed)

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

khiminrm’s picture

Hello! I found the bug in the code. See there https://drupal.org/node/2049977
I think the problem is in redefining $range_field before sending variables to the functions search_api_ranges_generate_ranges_simple and search_api_ranges_generate_ranges_advanced.
I think we must first execute these function to get $element and then do replace paths. I'm trying to do that now. I will write if I'll have any luck.

dasjo’s picture

Status: Closed (fixed) » Needs review

i'd recommend opening a follow up issue and maybe add a link here, as this one has already been committed

khiminrm’s picture

Status: Needs review » Closed (fixed)

@dasjo, ok. I'm closing this issue. All further comments will be there https://drupal.org/node/2049977.
I've noticed that DavidOliveros wrote about this bug in #34:

Now I'm not sure why the selected price range always have the class "facetapi-inactive".

khiminrm’s picture

Issue summary: View changes

More

Exploratus’s picture

Issue summary: View changes

still a problem

errev’s picture

Still is working no good.
Problems with the links that should be invisible but instead are displaying!