The apachesolr_search_run() function can receive a $context variable, which contains information regarding from where the search has been executed.

When a custom apache solr search page is created, this $context variable gets a page_id string, which can be used in hook_apachesolr_query_prepare(), to add specific filters depending on the page.

When the apachesolr_panels_search_execute() function executes apachesolr_search_run(), it does not set any context variable, which is inconvenient. It would be useful to be able to specify a custom page id on the CTools Plugin pane.

Comments

alcroito’s picture

Attaching a patch that adds a page_id textfield to the settings form, which is afterwards sent as a $context variable to apachesolr_search_run().

alcroito’s picture

Status: Active » Needs review
acbramley’s picture

Status: Needs review » Needs work

Another nice sounding feature, thanks @Placinta. I'm just wondering whether it's necessary to add the extra field or if we could just use the css id from the panels configuration? If it is needed, can we make the description a bit more specific maybe describing why someone would need to put something in there. Something like:

"A machine name to be sent as context for the search function. Useful in hooks like hook_apachesolr_query_prepare() to execute specific code depending on the search page."

alcroito’s picture

The reason why I'd use a custom id instead of the generated pane id, is when I create a custom search page at

http://server/admin/config/search/apachesolr/search-pages/add

it lets you set a label and machine name for the page, and I'd like machine names to be consistent both in the apache solr panels plugin, and in the custom page. This lets me add a single if condition in hook_apachesolr_query_prepare().

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new2.02 KB

Ok, that makes sense, although I've not used solr search pages as well as solr panels before since panels provides the ability to have search pages at any path with a lot more flexibility. Because it's quite an edge case, I think it would be better to utilise the already available machine name from panels (then you can make your search page machine name the same thing). Attached a patch that does exactly that.

miroslavbanov’s picture

Status: Needs review » Needs work

For my use-case #1 works quite well. #5 - doesn't. I need to target specific search pages with a custom context "product search" and do certain query alterations. I use panelized nodes as search pages.

So, yeah - #5 doesn't work for me.

miroslavbanov’s picture

I just noticed that the patch is not made relative the the module, so it won't work with drush make.

I am uploading fixed version. Issues in #3 are not addressed.