I create custom search environment by

$query = apachesolr_drupal_query('sponsered_search', $params);

so that I can hardcode a customize filter:

function hook_search_apachesolr_query_alter($query)
{
  if($query->getName()=='sponsered_search') {
    $query->addFilter('bs_field_sponsored_search_result', 1);
  }
}

But facet API's filtering do not apply to them. Is it by design or there is some way I can also apply facets to custom environment ID?

Details of my use case:
A normal search results page, but on top of the normal search, there is a "sponsored results" section, which filter the normal results by a checkbox value.

So the above code is used to generate such "sponsored" results, as a block, attached above to normal results. But the sponsored search do not respect facets. Changing the above code to:

//default environment ID
$query = apachesolr_drupal_query('apachesolr', $params);

works. But i can no longer separate the two search and add filter to one of them.

Please suggest solutions or entry point, I can hack and patch back but I have no idea where to start with.

Comments

cpliakas’s picture

Project: Facet API » Apache Solr Search
Version: 7.x-1.0-rc4 » 7.x-1.0-beta16

This seems like an Apache Solr Search Integration support request. Punting the issue unless this turns out to be something with Facet API.

joetsuihk’s picture

Sorry about that. I have that sense this belongs to Facets API because the facets only applies to default search on a page, but not on a customized environment.

It seems Facet API pin pointed default environment somehow. But if it is not the case, sorry for putting on a wrong project.

For Solr integration team, Can anyone point me to the point where Facets API works with Solr?

Thanks.

cpliakas’s picture

joetsuihk,

Facet API has no concept of environments (or search pages in Search API's case) so I'm not sure how it would pin something to a specific environment. It is the implementing module's responsibility to determine which items can have facets applied to them. Facet API calls these "searchers". I believe in Apache Solr Search Integration's case, it maps each environment to a Facet API searcher. See the apachesolr_facetapi_searcher_info() function for where this is defined. The apachesolr_do_query() then gets the $searcher and loads the adapter from that which will determine which facets are displayed. I would check this to see if it is somehow using the default environment as opposed to the custom one you are defining.

If you do track it down it an error somewhere in Facet API I would be glad to guide you further, but lt's try this first.

Thanks,
Chris

joetsuihk’s picture

Title: Facets only support default environment? » Facets only support default "search name":apachesolr?
Status: Active » Closed (works as designed)

cpliakas,

Thanks. You are correct. Apache solr module is "designed", on purpose or not, its facets only apply to the search it provides.

First of all, in above discussion, I messed up the concept of environment ID. "search environment" contains an URL to the solr server. "search name" is a string to specify a search query, namespace, which default apachesolr module use "apachesolr".

"searchers" bring up by @cpliakas is actually concat as "[search name]@[search environment]"

apachesolr module only pin point its facets to "apachesolr@[search environment]" as in apachesolr_facetapi_searcher_info() and apachesolr_facetapi_facet_info(), so when I want to use "sponsered_search@[search environment]", those facets filters do not apply.

So in my case where I want to completely reuse the facets as sponsored results, use apachesolr as search name, and:

  $query = apachesolr_drupal_query('apachesolr', $params);
    
  $query->addParam('fq', 'bs_field_sponsored_search_result:1');

instead of using hook_query_alter().

Thanks again cpliakas, closing it as I think apachesolr team design the facets works that way on purpose, changing title to avoid confusion and for search engines sake.

cpliakas’s picture

Excellent! Thanks for posting back and detailing your findings.