We established #1777714: Don't modify the query path to cleanly generate pretty paths. Therefore Search API committed the necessary patch in #1777710: Remove dependency on $_GET['q'] for determining base paths that changes Search API base path determination from $_GET['q'] to 'href' of menu_get_item().

Unfortunately this causes trouble for others: #1827272: Facet path can be incorrectly returned stated that when for example using panels with dynamic arguments, those should be part of the base path, but they wouldn't be using menu_get_item()'s href. So in the end, basically #1777710: Remove dependency on $_GET['q'] for determining base paths was reverted and it is up to Facet API Pretty Paths to figure out another way to handling things.

We want Search API to correctly work under the following premises:

  • base path as configured in search_api_views
  • base path as configured using panels with optional path arguments (those should be part of the base path)
  • path arguments as created by facetapi_pretty_paths (those should stay out of the base path)

Our current workaround is just applying the patch from #1777710: Remove dependency on $_GET['q'] for determining base paths in order to make pretty paths work but we don't want to rely on patching Search API in the future.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dasjo’s picture

talked to DamZ & nick_vh

DamZ suggested, this should be as easy as putting a $query_options['search_api_base_path'] = $this->view->get_path(); somewhere in searchapi_views

nick_vh showed how apachesolr handles this
http://pastebin.com/1j4Bcnpq

i have created a patch for search api that incorporates the suggestions from DamZ: #1863866: Make sure base path is set correctly for search api views
thanks for reviewing

otherwise we might put that code in some hook_views_post_execute within facetapi_pretty_paths

khiminrm’s picture

Hi! Is there a solution for Search pages module? I've made such modifications as temporary solution for our site with search page's path 'search/site':

in adapter.inc for function getSearchPath():

 if ($item['href'] == 'search/site' && isset($item['page_arguments'][1]))
		return $item['href']. '/' . $item['page_arguments'][1];
		else   return $item['href'];

in url_processor_pretty_paths.inc for function setBreadcrumb() :

    if ($keys) {
      // The last item should be text, not a link.
		if ($item['href'] == 'search/site') $breadcrumb[] = $active_items ? l($keys, $item['href']. '/' . $keys, array('query' => $query)) : check_plain($keys);     
		else
		$breadcrumb[] = $active_items ? l($keys, $item['href'], array('query' => $query)) : check_plain($keys);
    }

Maybe anyone know a method for Search pages module to get all it's paths? Then we can compare them with $item['href'] and add argument if needed.

dasjo’s picture

ad #2: have you tried the views patch from #1863866: Make sure base path is set correctly for search api views ?
edit: i have updated the views patch to use get_url() instead of get_path() in order to include views arguments.

khiminrm’s picture

No, I didn't try this patch, because I thought it is related only to Search API views not to Search pages module. Ok, I'll try it.

khiminrm’s picture

@dasjo, I've tried your patch http://drupal.org/files/1863866_search_api_views_base_path_url.patch. For my search page which is created with Search pages module (ver. 7.x-1.0-beta2 ) the patch didn't help - the facet links doesn't contain search key. And in my catalog page which is created with Search API views the current search block's links and breadcrumbs don't work - their links have a current path.

dasjo’s picture

@khiminrm: yes, sorry i didn't recognize that search api pages doesn't use search api views.
for this case, we need to figure another way to make sure that FacetapiAdapter::getSearchPath() returns the right base path.

dasjo’s picture

Title: Make sure that Search API returns reliable base paths » Fix base path issues
FileSize
9.85 KB
2.9 KB

after some further debugging, i believe the sanest way to handle things is setting the base path internally.
there are just too many things playing into this: views, search api, panels, arguments, ...

the attached patch already worked for me with recruiter job search.

second test case was creating a panel page with a search string as dynamic argument. this works as long as the search string is present, otherwise it will interpret the first pretty paths argument as search string. if you want to play around with this, find the necessary configurations exported using features in the attached zip file.

@khiminrm: i hope this approach also solves your problem, please tell me about your findings

dasjo’s picture

Status: Active » Needs review
khiminrm’s picture

@dasjo, I've tested your new patch. All work fine! Only first facet api breadcrumb on my search page doesn't contain search key in url. Other breadcrumbs contain search key. On my catalog page (search api views) the breadcrumbs are fine.

khiminrm’s picture

#9 is fixing for me by replacing

   if ($keys) {
      // The last item should be text, not a link.
      $breadcrumb[] = $active_items ? l($keys, $item['href'], array('query' => $query)) : check_plain($keys);
    }

with

      if ($keys) {
      // The last item should be text, not a link.
      $breadcrumb[] = $active_items ? l($keys, $this->getBasePath(), array('query' => $query)) : check_plain($keys);
    }
dasjo’s picture

khiminrm: glad that this works for you and thanks for spotting the breadcrumb issue. this particular code wasn't written by me so i have to admit that i'm a bit unsure about it. your fix worked for me, so i have included it in the patch

dasjo’s picture

Status: Needs review » Fixed

i have tested this patch for a pending upgrade of Drupaljobs:

- #1863866: Make sure base path is set correctly for search api views isn't useful anymore, actually you shouldn't use it because it won't allow you to deselect facets in certain cases.
- added some logic to support the search_api_base_path settings of search_api.

committed:
http://drupalcode.org/project/facetapi_pretty_paths.git/commitdiff/3ff36...
http://drupalcode.org/project/facetapi_pretty_paths.git/commitdiff/04f1f...

hope this works for everybody :)

Anonymous’s picture

Status: Fixed » Active

I'm getting facet paths like //category/tools and it breaks the site.

<a href="//category/Boots" class="facetapi-inactive" id="facetapi-link--124">Boots <span class="count">(17)</span><span class="element-invisible"> Apply Boots filter </span></a>

The new basepath logic returns empty, so instead of /search/, I get //

Using Search API Views for my /search page

Using latest Search API 7.x-1.4 and latest FacetAPI Pretty Paths

dasjo’s picture

@morningtime: can you give the steps to reproduce the problem or provide a features export to reconstruct your setup?

Anonymous’s picture

I'll have to dive into this.

For now I can only say that public function getBasePath() returns empty. $this->basePath; is never set.

Will get you more info asap.

dasjo’s picture

$this->basePath should be set in FacetapiUrlProcessorPrettyPaths::fetchParams(), line 114 of url_processor_pretty_paths.inc

Zac_JH’s picture

Hi

I can report the same as morningtime with the basepath coming back empty. I did a complete fresh install and the facetapi module does not contain the url_processor_pretty_paths.inc

dasjo’s picture

Anonymous’s picture

HI all,

I have the same problem. Replaced inc with the one from #18 but the constructed URLs are still missing the base path/domain name. Using beta1.

I tried with and without $base_url set, doesn't make a difference.

dasjo’s picture

#18 just references the file that ships with beta1.

if you are having problems please help us debug, for example by stating your exact setup: views export, which path are you accessing ($this->fullPath) and what is assigned to $this->basePath.

jbekker’s picture

With FacetAPI Pretty Paths Beta 1, Search API 1.4, I don't get a base URL but just the arguments in the url. "//categorie/accessoires-1" instead of "/products/categorie/accessoires-1".

I would like to help, just not sure where to start with debugging.

View Export

Anonymous’s picture

OK I try my best in putting together some useful information. If you would like to know something else, just let me know.

- I use a view which uses the path "feed" and it is set as the frontpage in drupal (meaning the actual URL is "/")
- $base_url is not set

Versions

Multilingual - Internationalization  Facet API Translation (facetapi_i18n)                        Module  Not installed  7.x-1.0-beta2  
 Search                               Search facets (search_api_facetapi)                          Module  Enabled        7.x-1.2+6-dev  
 Search Toolkit                       Facet API (facetapi)                                         Module  Enabled        7.x-1.2        
 Search Toolkit                       Facet API Bonus (facetapi_bonus)                             Module  Not installed  7.x-1.1        
 Search Toolkit                       Facet API Pretty Paths (facetapi_pretty_paths)               Module  Enabled        7.x-1.0-beta1  
 Search Toolkit                       Facetapi Multiselect (facetapi_multiselect)                  Module  Not installed  7.x-1.0-beta1+ 
 

View Export

$view = new view();
$view->name = 'feed';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_node_index';
$view->human_name = 'Feed';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Go';
$handler->display->display_options['pager']['type'] = 'infinite_scroll';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'entity';
$handler->display->display_options['row_options']['view_mode'] = 'teaser';
/* Field: Indexed Content: Node ID */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'search_api_index_node_index';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
/* Sort criterion: Indexed Content: Date created */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'search_api_index_node_index';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Indexed Content: Category */
$handler->display->display_options['arguments']['field_category']['id'] = 'field_category';
$handler->display->display_options['arguments']['field_category']['table'] = 'search_api_index_node_index';
$handler->display->display_options['arguments']['field_category']['field'] = 'field_category';
$handler->display->display_options['arguments']['field_category']['default_action'] = 'default';
$handler->display->display_options['arguments']['field_category']['default_argument_type'] = 'taxonomy_tid';
$handler->display->display_options['arguments']['field_category']['default_argument_options']['node'] = TRUE;
$handler->display->display_options['arguments']['field_category']['default_argument_options']['anyall'] = '+';
$handler->display->display_options['arguments']['field_category']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_category']['break_phrase'] = 0;
/* Contextual filter: Indexed Content: Tags */
$handler->display->display_options['arguments']['field_tags']['id'] = 'field_tags';
$handler->display->display_options['arguments']['field_tags']['table'] = 'search_api_index_node_index';
$handler->display->display_options['arguments']['field_tags']['field'] = 'field_tags';
$handler->display->display_options['arguments']['field_tags']['default_action'] = 'default';
$handler->display->display_options['arguments']['field_tags']['default_argument_type'] = 'taxonomy_tid';
$handler->display->display_options['arguments']['field_tags']['default_argument_options']['node'] = TRUE;
$handler->display->display_options['arguments']['field_tags']['default_argument_options']['anyall'] = '+';
$handler->display->display_options['arguments']['field_tags']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_tags']['break_phrase'] = 0;
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_node_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'item' => 'item',
);
/* Filter criterion: Indexed Content: Status */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'search_api_index_node_index';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = array(
  1 => '1',
);

/* Display: Feed */
$handler = $view->new_display('page', 'Feed', 'page');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
$handler->display->display_options['path'] = 'feed';
$translatables['feed'] = array(
  t('Master'),
  t('more'),
  t('Go'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('« first'),
  t('‹ previous'),
  t('next ›'),
  t('last »'),
  t('Node ID'),
  t('.'),
  t(','),
  t('All'),
  t('Feed'),
);

The object ($this before return in fetchParams):

FacetapiUrlProcessorPrettyPaths Object
(
    [filterParams:protected] => Array
        (
        )

    [pathSegments:protected] => Array
        (
        )

    [adapter:protected] => SearchApiFacetapiAdapter Object
        (
            [current_search:protected] => 
            [fields:protected] => Array
                (
                )

            [info:protected] => Array
                (
                    [label] => Search service: node index
                    [adapter] => search_api
                    [instance] => node_index
                    [types] => Array
                        (
                            [node] => node
                        )

                    [path] => 
                    [supports facet missing] => 1
                    [supports facet mincount] => 1
                    [include default facets] => 
                    [module] => search_api_facetapi
                    [name] => search_api@node_index
                    [url processor] => pretty_paths
                    [type] => node
                    [facetapi pretty paths coder] => default
                )

            [keys:protected] => 
            [facets:protected] => Array
                (
                )

            [processors:protected] => Array
                (
                )

            [queryTypes:protected] => Array
                (
                )

            [urlProcessor:protected] => FacetapiUrlProcessorPrettyPaths Object
 *RECURSION*
            [activeItems:protected] => 
            [processed:protected] => 
            [searchPath:protected] => 
            [dependenciesPassed:protected] => Array
                (
                )

            [settings:protected] => Array
                (
                )

        )

    [options:protected] => 
    [fullPath:protected] => feed
    [basePath:protected] => 
    [params:protected] => Array
        (
        )

    [filterKey:protected] => f
)
dasjo’s picture

this seems to be a problem when the url contains an uneven number of parts, because the last part will get dropped.
the attached patch should fix that problem and has been committed: http://drupalcode.org/project/facetapi_pretty_paths.git/commit/4062cd9

please report if that solves your problems

Anonymous’s picture

Perfect, #23 seems to fix the problem on my end. URLs are now generated correctly and the module is behaving nicely. :-)

Thank you!

dasjo’s picture

thanks for testing, glad it works :)

morningtime, roodoo, jbekker - would be great if you can provide feedback as well. i'd like to roll another beta soon, so people don't run into this bug

Zac_JH’s picture

Patch from #23 applied and it works perfectly, thanks for the quick turn around dasjo - great job.

Thanks genox for getting info too.

jbekker’s picture

Works for me as well!

Anonymous’s picture

Status: Active » Reviewed & tested by the community

#23 solved my issue!

Anonymous’s picture

#23 works for me as well! Thanks!

dasjo’s picture

Status: Reviewed & tested by the community » Fixed

good to hear. this has been fixed in beta2:
http://drupal.org/node/1896740

please help me keep the issue queue clean open follow ups as separate issues :)

Anonymous’s picture

Thanks. I have just installed the Beta2 but I see a different behavior, maybe not related to this patch. Now the facet value is in the following format "termname-id". So for example if I want to filter for "Football" in the group "Sports" the URL is in the format : /sports/football-12

is this the correct behavior? Am i missing something?

dasjo’s picture

connor23, please open a separate issue and explain you behavior before and how it has changed.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

up

dasjo’s picture

Issue summary: View changes
Status: Closed (fixed) » Active
geerlingguy’s picture

Another note: on one site using the Apache Solr Search Integration module (not Search API), facet links are broken after this module's alpha9 release for searches where no keyword is entered.

For alpha 9 and earlier, if a user enters no keyword on a custom search page like '/search/recipe', the facetapi links would be something like:

/search/recipe//facet_field/value

But with beta 1 and later, the links would be something like:

/search/recipe/facet_field/value

The Apache Solr search integration module seems to use that third URL parameter as the 'keyword' value, so not having an extra slash in there breaks that module's usage with Facet API Pretty Paths. It looks like a lot of the base path logic inside url_processor_pretty_paths.inc changed with this patch/beta1, and I can't find a quick/simple way to patch it and get it working again.

geerlingguy’s picture

Status: Active » Needs review
FileSize
490 bytes

Here's a patch that seems to fix the base path issues for me (using Apache Solr Search Integration module). It pre-constructs the base path using getSearchPath(), which was done up to beta1, but was discarded. I don't think this will fix all the other problems related to this particular issue, but at least it allows me to use the latest version of the module instead of alpha9 :)

dasjo’s picture

i'd like to see if we can get this fixed during drupalcon amsterdam.

anyone willing to share what they are currently using?

  • facet api pretty paths version + patches
  • search api or apache solr module version + patches
  • search set up (do you use a default search, do you use views, contextual filters, panels etc to build your search? anything related to your setup that affects the paths is important to mention)
kopeboy’s picture

search_api 7.x-1.13
search_api_solr 7.x-1.6
search_api_facetapi 7.x-1.13
facetapi 7.x-1.5
facetapi_pretty_paths 7.x-1.1

Using only Views pages of 3 different Search indexes (on Pantheon's apache solr server), with no contextual filters nor Content panes or Contexts cause I wasn't able to make them work :/ but of course, they would be much needed.

torgosPizza’s picture

We're using:
Acquia Search for Solr 7.x-2.14
Apachesolr 7.x-1.7
FacetAPI 7.x-1.3
FacetAPI Pretty Paths 7.x-1.1+1-dev
(Apachesolr Views 7.x-1.0-beta3 but only on one page)

This combination seems to work pretty well for me!

jcisio’s picture

Status: Needs review » Reviewed & tested by the community

Apachesolr 7.x-1.7
FacetAPI 7.x-1.3

Could we commit first then fix for Search API later?

dasjo’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

thanks you everybody for your feedback & thanks for the patch geerlingguy!

as i don't want to break things for either search api, apachesolr users and we haven't found a clear strategy on fixing the base path issues yet, i decided to take a more flexible approach to this.

#2413319: Add base path provider plugins makes this configurable and allows developers to create their own base path strategies using plug-ins.

would love to get your feedback there.