What if I wanted to allow users to search by facets without having initially searched by a keyword (My terminology might not be correct here, but by keyword I mean the text usually entered into the search box)

For example... A normal search for the word 'electronics' followed by filtering on a facet would create the following url on my site...

example-com/search/luceneapi_node/electronics?category[808]=808

What would be the url if the user didn't type 'electronics' but could start their search by selecting a facet to filter by?

I tried experimenting by removing the word 'electronics' from the above url but that doesn't work.

An example scenario might be where the user initially performs a keyword search, then select some facets to filter on, but then decide to remove their keyword search just leaving the facets they've selected, before entering another keyword, etc. etc.

Comments

cpliakas’s picture

I know exactly what you mean, and we actually implemented this on a site recently. The problem lies within the search_view() function in modules/search/search.pages.inc. If no search keys are passed (i.e. the electronics portion of the query string), then no search is executed. Since the "facets" are part of the query string and not part of the keywords as they are in the core search, searching only by facet is technically an empty search.

How we got around this was by adding a custom separate "realm" that built the facets with links that would set the keywords. For example, clicking on the facet for category 808 would link to example-com/search/luceneapi_node/category:808. This facet realm is only exposed on empty searches, and once the search is executed, the regular facets appear allowing for your regular drill down. It is a bit clunky, but I am opposed to adding a hook_menu_alter() implementation to add a custom search_view() function. Also, Lucene isn't designed to return all results in a set, so displaying the facet counts is best done via SQL query anyways. As you can see it is a simple request with a complex solution :-). I have to check with my employer, but it is possible I can release the code we used to accomplish this.

Thanks,
Chris

cpliakas’s picture

Version: 6.x-2.0-alpha2 » 6.x-2.x-dev
Assigned: Unassigned » cpliakas
Category: support » task

I got permission from commonplaces to release code used on one of our clients sites. It will take a little time to release, but a solution is available. Changing to a task for me to release the code.

cpliakas’s picture

Priority: Minor » Normal

Change of philosophy. I think that it is important to get this into the core module. It will also force me to write more efficient code in terms of calculating facet counts and lists. I don't particularly like the technique of creating a separate facet realm for facets that initiate search queries. There will be a series of checkboxes that allow the user to configure when the facets are displayed.

cpliakas’s picture

Status: Active » Fixed

Completed in commit #276970. Facets can now be displayed on empty search or on any other page to initiate a search. This is configurable in the admin settings.

Status: Fixed » Closed (fixed)

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