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.

Comments

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

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

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?

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.

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.

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

Hi Nick,

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

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

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

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

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)

Committed to 7.x-1.x also

Status:Needs work» Closed (fixed)