Hi Guys, just want to share this patch that I created, At first I thought the problem was my custom filter entry but when I dig inside there was a problem on the line that adds filter from custom filter field. This fixes the custom filter or ADDITIONAL QUERY field not working for MLT blocks settings.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, Fix-custom-filter-on-mlt-blocks-settings.patch, failed testing.

dzieyzone’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, Fix-custom-filter-on-mlt-blocks-settings.patch, failed testing.

travismark’s picture

Revised patch.

travismark’s picture

Title: MLT / Apache Solr recommendations Block fix for custom filter or ADDITIONAL QUERY field » Raw Code

--- a/sites/all/modules/apachesolr/apachesolr_search.module
+++ b/sites/all/modules/apachesolr/apachesolr_search.module
@@ -604,7 +604,11 @@

if ($custom_filters = $settings['mlt_custom_filters']) {
// @todo - fix the settings form to take a comma-delimited set of filters.
- $query->addFilter('', $custom_filters);
+ $custom_filters = explode(',',$custom_filters);
+ foreach ($custom_filters as $custom_filter){
+ list($filter_index, $filter_value) = explode(":",$custom_filter);
+ $query->addFilter($filter_index, $filter_value);
+ }
}

travismark’s picture

Title: Raw Code » Final patch for review :)
FileSize
689 bytes
Nick_vh’s picture

Title: Final patch for review :) » Apache Solr recommendations Block fix for custom filter or ADDITIONAL QUERY field
Status: Needs work » Needs review
Nick_vh’s picture

Status: Needs review » Needs work
+++ b/apachesolr_search.moduleundefined
@@ -604,7 +604,11 @@
+      foreach ($custom_filters as $custom_filter){
+      	list($filter_index, $filter_value) = explode(":",$custom_filter);

Please use two spaces instead of a tab.

We might also want to validate the filter before we send it to addFilter. See validFilterValue in solr_base_query.php

Nick_vh’s picture

Category: bug » feature

This is not a bug, it's a feature request. It works perfectly without this. Hoping to get some more response from people in this issue

travismark’s picture

Hi Nick, Yeah I agree.. just in case some devs need this feature they might stumble in this ticket tand have idea how to make it work. Thanks for you help! :)

travismark’s picture

Status: Needs work » Closed (works as designed)
Nick_vh’s picture

Status: Closed (works as designed) » Needs work

Well, you don't need to close it just yet ;-)

jrreid’s picture

This works for me. In fact without it the custom filters don't seem to work for me on the latest 7.x-1.x when I was creating/testing #2017135: Add token for local site hash value. The @todo a few lines up can probably also be removed as this handles that.

pwolanin’s picture

Version: 7.x-1.0-beta16 » 7.x-1.x-dev
wulff’s picture

Category: Feature request » Bug report
Issue summary: View changes
Status: Needs work » Needs review
FileSize
949 bytes

I've been trying to add a date filter to one of our MLT blocks, to make sure that the block only contains fairly recent content:

ds_created:[2008-01-01T00:00:01Z TO *]

With the current version of the module, this results in the following parameter being added to the query string (url decoded):

fq=:"ds_created:[2014-01-01T12:00:00Z TO *]"

This does not seem to work as intended.

After applying a cleaned-up version of the patch in #6, the following parameter is added to the query string (url decoded):

fq=ds_created:[2014-01-01T12:00:00Z TO *]

This seems to work as intended.

I have attached an updated patch.

darvanen’s picture

Using the recently updated 7.x-1.7 module, custom filters weren't working **at all**. This patch (#15) fixed it for me.

Den Tweed’s picture

Had same problem with custom filter not working, patch #15 fixed this.

darvanen’s picture

Status: Needs review » Reviewed & tested by the community

Changing status to RTBC as #15 now has 3 confirmed uses with no constructive feedback after 9 months. Has been in production for at least 2 months here with no bugs found.

Nick_vh’s picture

Seems reasonable for me. Will add it to the next release :)

maxocub’s picture

+1

nareshbw’s picture

Used patch # 15 it is working fine for me .

edjeavons’s picture

Patch #15 has solved the problem for me as well. Thank you.

  • wulff authored d92b5d6 on 7.x-1.x
    Issue #1596308 by travismark, wulff:  Apache Solr recommendations Block...
janusman’s picture

Status: Reviewed & tested by the community » Fixed

Fixed

Status: Fixed » Closed (fixed)

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