Hi,

I've been playing with this all day, but for some reason cannot seem to get the facets to appear in the URL in the correct order.

For example, I have four facets blocks (make, model, offer type, body type (for a car sales website)).

The weights are set to:
Make - 0 // needs to appear first
Model - 1 // needs to appear second
Offer Type - 2 // I don't care where this appears
Body Type - 2 // I don't care where this appears

If I select items from those assets in the order listed above, I get a URL like this:
example.com/search/make/bmw-23/model/325-45/offer_type/used-21/body_type/coupe-76

But, if I choose the "body_type" facet first, then choose the "make" facet, I get a URL like this:
example.com/search/body_type/coupe-76/make/bmw-23

I had thought that setting the weights would mean that "make" would always come out first and "model" next, no matter what order the facets were selected.

Comments

markconroy created an issue. See original summary.

strykaizer’s picture

Correct, this is still a todo for now.

in FacetsPrettyPathsUrlProcessor::buildUrls (line 134), we need sort by facet weight before building the url.

markconroy’s picture

Thanks for that reply. Much appreciated.

I'll be using this feature on the site I am working on, so happy to contribute a patch if we get this solved.

b.lammers’s picture

StatusFileSize
new1.79 KB

Hi,

I took the liberty of taking a look at this issue and creating a patch for it.
Please review and consider

b.lammers’s picture

Status: Active » Needs review
strykaizer’s picture

Hi Bart,

Thanks for this, haven't tested,but it looks pretty clean!
I'll review asap and commit.

strykaizer’s picture

StatusFileSize
new2.47 KB
new2.83 KB

@b.lammers Thanks again! Works fine.

I changed the patch a bit to have a fallback sort on facet name when no weights are set, to prevent rendering urls like "/color/green/size/large/color/blue". This way the urls will always reflect the order as visible on the facets overview (similar to e.g. core's taxonomy, which is by default sorted by name, when no weights are set).

I'm open for suggestions though ;)

b.lammers’s picture

Nice addition. Don't think the mixing of facets as in your example would occur because they are processed in a foreach per facet, but sorting them alphabetically is clean nonetheless.

strykaizer’s picture

@b.lammers Oh, right, forgot about that grouped facet array.

Only thing I'm still wondering about is if we should also sort the pretty_path_aliasses alphabetically to ensure there's only 1 url used per combination. If I remember correctly search_api does not support caching atm, but if they start supporting it, having 1 unique url per combination will definitly improve caching hits.

I'll leave that for later. Before I commit this, I want to do some performance tests to see how much time is spend sorting and if/how we can optimize this.

  • StryKaizer committed 1f8aff2 on 8.x-1.x
    Issue #2938931 by StryKaizer, b.lammers: Facet Weight for URL Not Taking...
strykaizer’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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