I have been working on creating query exclusions, specifically for content types. This version is preliminary, and accesses the metadata for the bundle names via variables.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ayang’s picture

Not totally happy with how everything looks right now, but it works!

Nick_vh’s picture

Just improved it a bit in order to apply the patch more easily.
I suggest you check out the git module and use git diff to create the diffs

Nick_vh’s picture

Some code format problems :

sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.module
apachesolr_multisitesearch.module
Line 139: Control statements should have one space between the control keyword and opening parenthesis
return($query_bundle_names);
(This should actually be return $query_bundle_names)

sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.admin.inc
apachesolr_multisitesearch.admin.inc
Line -1: @file block missing (Drupal Docs)
Line 75: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE
'#multiple' => true,

You should also handle error situations because I tried it and the content types returned empty so I had an empty select list. There is also no description above the select list to tell you what it exactly does?

Could you also explain the TODO item in the code?

ayang’s picture

Hi Nick,

Thanks for the feedback. Regarding the TODO statement, the code doesn't allow for any filtering for content from specific sites, just all of the sites as a collective. I am planning on adding another tier for the select list to allow for filtering a specific content type from a specific site.

ayang’s picture

Here is the updated code. It won't render the section of the form if there are no content types present in the metadata and adds a clear button to the query exclusion form.

Nick_vh’s picture

Status: Needs review » Needs work
+++ b/apachesolr_multisitesearch.admin.incundefined
@@ -59,10 +64,67 @@ function apachesolr_multisitesearch_settings() {
+  if ($form['query_exclusions']['exclusion_options']['#post']['op'] == t('Clear all exclusions')) {

I'm not sure if this is the way to go? You might want to use form_state instead of form

+++ b/apachesolr_multisitesearch.admin.incundefined
@@ -59,10 +64,67 @@ function apachesolr_multisitesearch_settings() {
+  elseif (isset($form['query_exclusions']['exclusion_options']['#value']) && !empty($form['query_exclusions']['exclusion_options']['#value'])) {

Same here, can you use form_state or not? If not no worries. Also empty is sufficient enough so you can remove isset

+++ b/apachesolr_multisitesearch.admin.incundefined
@@ -59,10 +64,67 @@ function apachesolr_multisitesearch_settings() {
+    $matches = array_intersect_key($query_exclusion_options, $form['query_exclusions']['exclusion_options']['#value']);

Is there a more performant way to do this?

+++ b/apachesolr_multisitesearch.admin.incundefined
@@ -59,10 +64,67 @@ function apachesolr_multisitesearch_settings() {
+    drupal_set_message('<strong>No content</strong> will be excluded from search.');

ew, html in a drupal_set_message. Never fun ;-)

+++ b/apachesolr_multisitesearch.moduleundefined
@@ -109,6 +109,36 @@ function apachesolr_multisitesearch_apachesolr_process_results(&$results, Drupal
+  if (isset($sites) && !empty($sites)) {

Better check if it is an array and not empty

+++ b/apachesolr_multisitesearch.moduleundefined
@@ -109,6 +109,36 @@ function apachesolr_multisitesearch_apachesolr_process_results(&$results, Drupal
+      foreach ($value['sm_multisite_meta_bundles'] as $bundle_name) {

check if the value is effectively not empty

+++ b/apachesolr_multisitesearch.moduleundefined
@@ -128,6 +158,21 @@ function apachesolr_multisitesearch_apachesolr_query_alter(DrupalSolrQueryInterf
+  if (isset($excluded_bundles) && !empty($excluded_bundles)) {

only empty is enough

ayang’s picture

Hi Nick,

Thanks for the continued feedback. Here's the next rendition, built off your notes and cleaned up a bit.

Nick_vh’s picture

Just to confirm, you could not use form_state compared to form object?

Nick_vh’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev

we need this fix first in 7.x-1.x actually

Nick_vh’s picture

Hm,, committing it first for 6.x-3.x

included patch is for 6.x-3.x and was committed. Thanks Andrew! (but I did change $form to $form_state and fixed some non-encapsulated strings so they are within a t() function now)

Nick_vh’s picture

Committed to 7.x-1.x also

Nick_vh’s picture

Status: Needs work » Closed (fixed)