in the apachesolr_search module and in other hook_block implementations we have code like this:

    case 'view':
      if (arg(1) == 'apachesolr_search' && apachesolr_has_searched()) {

This makes it so that we can't get the facet blocks in any other context (like for facet driven navigation).

We need to make the visibility settings some other way. Perhaps the hook_block api has a way to do this.

Comments

pwolanin’s picture

Yes - this was on my list to talk to you about. On possibility - a helper function that stores a static boolean (in analogy to the has_searched helper)? Elsewhere, code that knows that we are on a search page could set it to TRUE.

Scott Reynolds’s picture

Status: Active » Needs review
StatusFileSize
new2.17 KB

Here ya go.

Why is it important to make sure its this modules search? Isn't enough to do this:

if ($response->facet_counts->facet_fields->$delta)

Not sure what motivates that arg() check specifically, so I took it out. See patch

pwolanin’s picture

Status: Needs review » Needs work

why $_REQUEST instead of $_GET?

Also, we can probably check if $response is_null(). The if above will throw warnings.

Scott Reynolds’s picture

Status: Needs work » Needs review

The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.

The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

Its more comprehensive. The patch does not use that if statement. My question was what motivates :

case 'view':
      if (arg(1) == 'apachesolr_search' && apachesolr_has_searched())

why not just

case 'view':
      if (apachesolr_has_searched())

works for me, and it is what this patch does

pwolanin’s picture

Status: Needs review » Needs work

we only every care about GET, so there is simply no reasn to use REQUEST.

Scott Reynolds’s picture

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

K fixed and found a path that I missed. The facet blocks work on my custom search page that doesn't use search api. My search page resides at group/ID/search. The facet blocks work fine there. It decouples the arg() logic from the blocks. Still don't know why orginally the apachesolr_search module had this in its block:

case 'view':
      if (arg(1) == 'apachesolr_search' && apachesolr_has_searched())

it was added for a reason, does that reason still exist? This patch removes that if statement as its not apparent to me why it is needed. If that arg() logic is there the uid facet block, for instance, only shows up on the search/apachesolr_search page.

robertdouglass’s picture

arg(1) == 'apachesolr_search' preceded the existence of apachesolr_has_searched(). This patch counts as positive and necessary cruft removal.

pwolanin’s picture

Status: Needs review » Needs work

We should either make this a class method, or refactor it into a re-usable function.

Also, you must not be patching against the code at the end of the DRUPAL-6--1 branch. the ->get_query() method no longer exists.

$path = substr($_GET['q'], 0, strpos($_GET['q'], $query->get_query()))
Scott Reynolds’s picture

I am using the alpha version, wasn't paying attention to this issue (didn't create it didn't select version). I see its been replaced with

get_query_basic();

is there a

get_query_advance();
Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new9.93 KB

Ok this patch is against DRUPAL-6--1.

Notes
1.) In the first hunk I wanted to set the $path = $_GET['q']. But I believe that would include the sort params, which is not what is desired. We want only the keys.
2.) language module had a bug, used get_query instead of get_query_basic. I didn't find an issue for this, but if there is i can reroll with that issues patch

It works well, but I probably should have added some comments around say the first hunk for that first note

Also, the breadcrumbs arn't working. I believe that before this patch they weren't working as before this change and after the $path was exactly the same. If you goto search/apachesolr_search the menu tab isn't highlighted. I believe that is caused by the breadcrumb.

David Lesieur’s picture

robertdouglass’s picture

StatusFileSize
new7.28 KB

Rerolled and tested. Seems to work. Code looks much better without those arg(1)s.

robertdouglass’s picture

StatusFileSize
new8.85 KB

Here's an untested D5 patch.

robertdouglass’s picture

StatusFileSize
new7.24 KB

The D6 patch missed one.

pwolanin’s picture

This doesn't really make sense to me - we have now totally separated the facet part from the keyword (searrch key) part, so can't we just use $_GET['q'] everywhere unless we are changing the keywords?

robertdouglass’s picture

You might be right, Peter.

mikejoconnor’s picture

StatusFileSize
new6.31 KB

Here is an updated patch. The current patch throws errors if you don't have a search query.

Although this seems to be working for me right now, I wonder how well it will if I try to use faceted terms as part of a url callback, for custom search driven nav pages.

pokadan’s picture

I need to display the facets as if i have searched for something on a non search page.

Anyone to point me in the right direction ? Do you do a $response = $solr->search(...) and then call apachesolr_facet_block with the response and initial query?

Any comments appreciated..
Thanks

mikejoconnor’s picture

Poka_dan,

Take a look at the Project module. It has some great code for generating searches for general navigation pages.

Once you get a page callback performing searches, apply the patch in comment # 17, and provide some feedback.

pokadan’s picture

Thanks mikejoconnor,

I managed to do it in my own module by displaying my own blocks and replicating some of the apachesolr_search.module code with some modiffs(where the search query is set and others).

Thanks again.

mikejoconnor’s picture

Status: Needs review » Reviewed & tested by the community

I've tested this in two sites, and it seems to be working well. It would be nice to have a little more feedback from anyone else using this.

mikejoconnor’s picture

Status: Reviewed & tested by the community » Needs review

Didn't mean to change the status

Scott Reynolds’s picture

Title: Dependence on arg(1) logic prevents reusing facets code » Re-Work get_path() so that the facet blocks can be used outside the search page
Status: Needs review » Needs work

With the commit of #254565: Integrate with Views front-end this no patch no longer applies. That commit created a method on Solr_Base_Query called get_path(). This logic now needs to reside there. So its a much smaller patch. I imagine the exact same logic can be applied from this patch in that method.

pwolanin’s picture

we could probably do this as part of #432946: Query class and sort cleanups

David Lesieur’s picture

StatusFileSize
new896 bytes

Re-applied the same logic to the new get_path() method.

David Lesieur’s picture

Status: Needs work » Needs review
pwolanin’s picture

I was thinking, perhaps, that the base path would be set when the object is instantiated, rather then here you're doing it repeatedly on demand.

David Lesieur’s picture

StatusFileSize
new6.04 KB

Makes sense... Since using $_GET['q'] at this level does not feels perfectly clean, this new patch also adds a way to explicitly pass on the path. I guess it would be better to use this parameter when possible. I have renamed the $querypath member to $keys to avoid any confusion.

This patch alone is not sufficient to have facet blocks anywhere; it is just an intermediate step.

pwolanin’s picture

Kind of feels like $_GET['q'] should not appear anywhere inside the class.

David Lesieur’s picture

StatusFileSize
new5.79 KB

With this patch, the caller of apachesolr_drupal_query() is now responsible for defining the base path. In the case of apachesolr_search.module, it is always 'search/' . arg(1).

pwolanin’s picture

looks pretty good at first glance, but will need to test it.

David Lesieur’s picture

pwolanin’s picture

committed to 6.x - do we need any follow-up in terms of the interface definition?

pwolanin’s picture

Status: Needs review » Fixed
Scott Reynolds’s picture

glad to see my substr strpos logic die :-D very cool

David Lesieur’s picture

Perhaps we'd like get_base_path()/set_base_path() methods?

Status: Fixed » Closed (fixed)

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

emackn’s picture

So, If i'm using 6.1.x-dev, how do I change the search path from 'search/apachesolr_search/xxxx' from 'what-I-want/xxx' ?

From looking at the code, I don't see how this is easily doable. Am I missing something simple?

#327833: Allow Override of Core Search Path - /search was marked as a duplicate, but I don't see how anything done in this thread fixes that issue.

Just found this, #524366: Custom Search Path. It's for 6.2.x-dev, but does seem to map out what needs to change.

emackn’s picture

I manually applied the changes from #524366: Custom Search Path and got my search url from
'search/apachesolr_search/xxx'
to
'search/what-i-want/xxx'