As mentioned in the support request at #1248740: How can facet blocks be displayed on non-search pages?, it might be useful to add facet blocks to non-search pages that can initiate a search. I see the interface looking something like the attached screenshot, which would be displayed on the "block" realm configuration form.

Comments

cpliakas’s picture

Status: Needs review » Postponed

The issue posted at #1252644: Remove assumption that the facets will link back to the page they are on is the corresponding thread in Facet API.

cpliakas’s picture

Status: Active » Needs review
Issue tags: +Facet API integration
StatusFileSize
new2.95 KB

The attached patch is an attempt at at least showing how I plan on approaching this. I understand there are assumptions in here, but I am unclear how this solution would look with multiple environments, search pages, etc. Any information you can provide surrounding the assumptions you see would be helpful.

After installing the patch, you can see how setting the pages will show the facet blocks although they don't work.

Thanks,
Chris

pwolanin’s picture

So, this should basically work the same as the facet browsing blocks - i.e. the query is for everythign in the index (or with e.g. just node access filters applied)?

cpliakas’s picture

Yes. Exactly the same, but with the pages being configurable.

Refineo’s picture

subscribing

cpliakas’s picture

Status: Postponed » Needs review
StatusFileSize
new3.15 KB

Latest patch, some assumptions removed. Also added a sanity check for backwards compatibility so we don't have to do a coupled release. The counterpart to this patch is posted at http://drupal.org/node/1252644#comment-4919158.

cpliakas’s picture

This is coupled with the work being done in the Facet API non-search-facets branch.

pwolanin’s picture

Status: Needs review » Needs work

So, I think this needs work to couple it to a specific search environment.

looks like these lines need to be adjusted:

$pages = drupal_strtolower(variable_get('apachesolr_search_facet_pages', ''));

$id = 'apachesolr@' . apachesolr_default_environment();

However, I'm not sure how to avoid overlapping path settings for different environments.

Refineo’s picture

Status: Needs work » Reviewed & tested by the community

after applying the apachesolr-1252648-6.patch together with the facet api patch (http://drupal.org/files/issues/facetapi-1252644-2.patch for #1252644: Remove assumption that the facets will link back to the page they are on) ,
I got WSOD:

Array
(
    [type] => 1
    [message] => Class name must be a valid object or a string
    [file] => /***/sites/all/modules/ctools/includes/export.inc
    [line] => 1095
)

Then I restored database tables and it is corrected now. Testing further...

pwolanin’s picture

Status: Reviewed & tested by the community » Needs review

why did you change the status?

pwolanin’s picture

Status: Needs review » Needs work
cpliakas’s picture

I'm not sure how to avoid overlapping path settings for different environments.

Would it ber reasonable to change the settings to arrays keyed by the environment ID? The sticking point I had was getting the environment of the search being executed. Any input on this, or am I overthinking what needs to be done?

Thanks,
Chris

cpliakas’s picture

Status: Needs work » Needs review
StatusFileSize
new5.17 KB

Here is a re-roll of the patch against the latest 7.x-1.x code. As mentioned in #8, this patch supports per-environment settings by taking the approached suggested in #12. Note that with the latest version of Facet API, we run into issue #1379166: The Current Search Block is displayed on the search page even when no search has been executed. Depending on that issue's resolution, the fix will have to be applied here as well. Regardless, the patch is still ready for testing and feedback.

cpliakas’s picture

StatusFileSize
new5.71 KB

Added cleanup routine in hook_apachesolr_environment_delete() that removes the environment specific settings on delete.

cpliakas’s picture

Based on the resolution of the issue #1379166: The Current Search Block is displayed on the search page even when no search has been executed, there is nothing more that needs to be added to the patch in #14. The functionality could technically be implemented in another contrib project, but the changes to the ApacheSolrFacetapiAdapter::getSearchPath() would still need to be applied to prevent fatal errors.

nick_vh’s picture

Status: Needs review » Needs work
+++ b/apachesolr_search.moduleundefined
@@ -1255,6 +1293,13 @@ function apachesolr_search_apachesolr_environment_delete($server) {
+  unset($show_facets[$server['env_id']]);
+  unset($facet_pages[$server['env_id']]);

Why does the unset happen here?

Other then this it seems to be ok. Still have to test it though :-)

cpliakas’s picture

Why does the unset happen here?

It happens because the variable is an array of settings keyed by environment ID. If we didn't have this cleanup routine when the environment was deleted, the settings would still remain in the array for an environment that no longer exists. This isn't too much of an issue because there is enough defensive coding that would prevent the empty query from running, however the application would still try. If an environment with the same name was created again, the settings would be active for it which might not be the intended behavior.

Talking through this just now, would the apachesolr_environment_variable table be the best place to store these values? I stuck with the core variables table to have something that is fast, loaded on every page load anyways, and it prevents us from having to load all environments to check whether an empty query should be run.

nick_vh’s picture

Status: Needs work » Needs review

I'm not sure about performance difference. The variable get is ok but it is an extra thing to take care of when updating or uninstalling. I guess it does make sense to add it to the environment settings. This is cached and is a static variable so it probably does not hurt the performance a lot.

Maybe we should test it with apachesort benchmark? Fire up 1000 requests with variable_get, 1000 with the other one and see how fast it loads?

cpliakas’s picture

I think that makes sense. Looking through the code, apachesolr_load_all_environments() is currently NOT called on non-search pages, which is a good thing. If we did want to store the variables in the apachesolr_environment_variable table then we would have to call apachesolr_load_all_environments() on every page load. This data is cached and in a static like you said so it probably wouldn't be too much of a performance hit.

nick_vh’s picture

The results of the benchmark with the patch from cpliakas. Facets were added on a regular page with some bullshit content. No extra modules included.
Will try to change the patch now so it uses the apachesolr_environment_variables and see if it makes significant difference. I suppose we should test it with logged in users also? As mentioned here : http://www.midwesternmac.com/blogs/jeff-geerling/using-apachebench-ab-dr...

notes : no page caching was enabled, query cache for solr was enabled.

Nick-Veenhofs-MacBook-Pro:apachesolr nickveenhof$ ab -c1 -n500 http://apachesolrissues.dev/content/test-utf8
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking apachesolrissues.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests

Server Software: Apache/2.2.20
Server Hostname: apachesolrissues.dev
Server Port: 80

Document Path: /content/test-utf8
Document Length: 25000 bytes

Concurrency Level: 1
Time taken for tests: 183.454 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Total transferred: 12766500 bytes
HTML transferred: 12500000 bytes
Requests per second: 2.73 [#/sec] (mean)
Time per request: 366.908 [ms] (mean)
Time per request: 366.908 [ms] (mean, across all concurrent requests)
Transfer rate: 67.96 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 327 367 20.3 361 427
Waiting: 304 343 20.1 337 401
Total: 327 367 20.3 361 427

Percentage of the requests served within a certain time (ms)
50% 361
66% 380
75% 386
80% 388
90% 393
95% 400
98% 408
99% 413
100% 427 (longest request)

nick_vh’s picture

While I was trying to change this I actually noticed with your patch it is possible to show facets of multiple environments. I guess we should stick to "keep it simple" and only support the default environment for output. It will get very complex I suppose to figure out the correct page where the facet should go to? Working on a patch right now that reduces this complexity

nick_vh’s picture

StatusFileSize
new5.1 KB

Nick-Veenhofs-MacBook-Pro:facetapi nickveenhof$ ab -c1 -n500 http://apachesolrissues.dev/content/test-utf8
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking apachesolrissues.dev (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests

Server Software: Apache/2.2.20
Server Hostname: apachesolrissues.dev
Server Port: 80

Document Path: /content/test-utf8
Document Length: 25000 bytes

Concurrency Level: 1
Time taken for tests: 184.370 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Total transferred: 12766500 bytes
HTML transferred: 12500000 bytes
Requests per second: 2.71 [#/sec] (mean)
Time per request: 368.741 [ms] (mean)
Time per request: 368.741 [ms] (mean, across all concurrent requests)
Transfer rate: 67.62 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 326 369 32.2 365 844
Waiting: 302 344 31.5 341 820
Total: 326 369 32.2 365 844

Percentage of the requests served within a certain time (ms)
50% 365
66% 370
75% 373
80% 377
90% 391
95% 406
98% 430
99% 503
100% 844 (longest request)

With attached patch (apachesolr_environment_variable_get())
I also feel this patch is a bit cleaner. It might also impact performance since not every environment is looped now at page load

cpliakas’s picture

Thanks for the benchmark tests, Nick! Excellent, quick work as always.

The reason why I added support for multiple environments is because of Peter's comment in #8 above. The original patch actually only worked with the default environment so we are coing a bit full circle. I am definitely OK with that, just want to make sure everyone is on board.

nick_vh’s picture

I just replaced the first benchmark because it was not correct

patch #14 Time per request: 366.908 [ms] (mean)
patch #22 Time per request: 368.741 [ms] (mean)

Mine is a bit slower

I did not really read the full issue, my bad! So I guess for the pages we probably need to load all the environments and loop over those variables if we want to keep it sane?
#8 only mentions that we are coupling it to a specific environment. It did not mention we have to support all the environments at once. My latest patch fetches the default environment and checks the settings of that one. If someone is smart enough he/she would probably make a custom module and make a hook_init for their second or whatever environment and point it to a specific page.

If someone switches from default environment their configurations will also change. At least it is a step in the correct direction I guess. I'm not a big fan of the 'looping over all enviroments approach' because it could end up in an unwanted mess and maybe even in "1 multiplied with the amount of environments" solr queries per page load where the facets are shown.

cpliakas’s picture

Status: Needs review » Needs work

#8 only mentions that we are coupling it to a specific environment. It did not mention we have to support all the environments at once.

Yup. New Year's resolution, read issues more thoroughly.

I'm not a big fan of the 'looping over all enviroments approach' because it could end up in an unwanted mess

I can definitely see that.

Regarding the benchmarks, 2ms is definitely not that much, and I think with the simplicity you proposed it is warranted.

I ran the patch and I cannot seem to save the settings. I think it is because the settings are no longer arrays keyed by environment ID, but in some instances that still seems to be present.

Thanks for your detailed reviews,
Chris

cpliakas’s picture

StatusFileSize
new2.45 KB
new5.02 KB

Attached is a revised patch. I also attached an interdiff to show the changed between #26 and #22.

cpliakas’s picture

Status: Needs work » Needs review
nick_vh’s picture

Committed! This was a great commit before 2012 started!

cpliakas’s picture

Status: Needs review » Fixed

Thanks again for your feedback and testing. A couple of people have asked for this, so having it available OOB is a great option especially for e-commerce sites!

nick_vh’s picture

Status: Fixed » Closed (fixed)
nick_vh’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
StatusFileSize
new5.02 KB
drewmacphee’s picture

This doesn't seem to work correctly in a multi-environment setup. It only seems to show the first environments facets, none of the other environments facets show up.