We ran into an issue with Panopoly where the facet path was being incorrectly returned. In our specific case we were using panels to override the search results page at the path "search/site/%keyword". After performing a search the facet blocks all link to "search/site" instead of maintaining the keyword in the path. This is because of menu_get_item fallback option in search_api's getSearchPath() method.

I think the assumption here is that the keys URL param will always be passed, which is not necessarily the case. Additionally, it would seem that using the request_path method here is preferable, as it maintains any URL params which may have been passed.

Here's a patch which converts the menu_get_item() call to use request_path. This fixes the issue for our needs.

Comments

beeradb’s picture

Status: Active » Needs review
StatusFileSize
new596 bytes
baldwinlouie’s picture

I too am facing this issue. The patch above does in fact fix this problem.

populist’s picture

Status: Needs review » Reviewed & tested by the community

I tested this patch and also found it to solve the problem described in the original issue. At issue here is that $item['href'] will only return the non-argumentative part of the path. but using request_path() gets the full path.

drunken monkey’s picture

This change was introduced in #1777710: Remove dependency on $_GET['q'] for determining base paths. I'll ask that issue's creator if this would also work for him. Otherwise we'll have to come up with a more clever way of doing this …

aaronbauman’s picture

request_path() is the way to go.
RTBC++

closed 2 other issues as duplicates on this one:
#1829638: FacetAPI facet URLs don't include search terms from search page
#1817360: search facets link to wrong URL

HakS’s picture

This change does not work for multilingual paths, it returns:

  • [site]/en/en/search/[keyword]?f[0]=field_name%3A5
    instead of
  • [site]/en/search/[keyword]?f[0]=field_name%3A5

Curiously, it works with $_GET['q'].

populist’s picture

StatusFileSize
new596 bytes

How about using current_path()? Patch attached.

dasjo’s picture

sorry folks, i'm the one to blame for getting that change into search_api. it was due to an attempt to clean up our code for facetapi_pretty_paths: #1777714: Don't modify the query path

i don't have a clear plan on how to approach this problem, but the most important to me seems ensuring that search_api has a reliable base path that works for all scenarios. on my radar these are some factors that play into the game right now:

  • 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)
drunken monkey’s picture

Status: Reviewed & tested by the community » Needs review

Could everyone please test the patch in #7?
If no solution is found which fits all cases, I guess we can just take the approach that fits the most and urge developers with other cases to manually set the facet base path via the search_api_base_path option.

@ HakS: Is there an easy way to detect and fix this case? If request_path() works in all other cases, maybe we should just include the workaround for the one exception – especially if it's one that's more or less core functionality.

wwhurley’s picture

Tested patch #7 and it works for us.

beeradb’s picture

#7 works for me as well.

dasjo’s picture

@drunken monkey: search_api_base_path helps when mapping outgoing links, do you have an idea if/how we could handle mapping them when incoming? (see #1468922: URL aliases require workaround).

drunken monkey’s picture

Category: task » bug
Status: Needs review » Fixed

Just realized that current_path() does nothing more than return $_GET ['q'], so this would essentially just be a revert of #1777710: Remove dependency on $_GET['q'] for determining base paths. But as this seems to work for everyone (except the Pretty Facets Paths module) and the current state introduces several problems, I guess we should just do this.
Sorry, Josef, you'll have to find another solution for this. It's annoying how hard this is to do (right), but I guess it can't be helped for now.
And no, sorry, I also can't think of another solution than doing nasty things in hook_url_inbound_alter() … Maybe that's what you'll have to stick with for now. Maybe something better will come up in D8 …

Anyways, committed this now, with just using $_GET['q'] again (for clarity).

gabb’s picture

May be, I opened another issue for the same problem ... Sorry
#1849464: clicking on facet show no result
aplyed patch #7
work for us. Thanks.

agileadam’s picture

#7 applied cleanly and corrected the problem for me. Thank you.

sun-fire’s picture

#7 fix the url bug, but breaks url's in current search block for active facets (disable facet links) - they have the current url and don't work.

khiminrm’s picture

Hi! I've the same as in #16 plus the breadcrumbs on the search page don't contain search keyword.

dasjo’s picture

ad #15, #16: i think best would be opening a follow up issue with a more detailed description of the search related modules your are using & what worked in which version and what doesn't now.

khiminrm’s picture

@dasjo, Yes you are right. The problem with the module facetapi pretty paths. When I turned it off the links in current search block and in breadcrumbs work. Thanks for advice.

dasjo’s picture

if you are having trouble in combination with the Facet API Pretty Paths module, please see this issue:
#1861786: Fix base path issues

Status: Fixed » Closed (fixed)

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