Hi! I have a content type "product", in wich I have a taxonomy term field of vocabulary "product_avaliability"(terms: avaliable (tid=84), not avaliable(tid=85)). I need the block "More like this" to display only nodes with value "avalible" for the field avaliability.
I tried such queries :
field_product_avaliability:avaliable
field_product_avaliability:84
avaliable
84
But the block doesn't show results.
Is there any documentation about the query language in Apache Solr Integration module? Any suggestions on the right query in my case?

Comments

khiminrm’s picture

I have noticed an error in Recent log messages:

"400" Status: Bad Request: Bad RequestApache Tomcat/6.0.24 - Error report

HTTP Status 400 - org.apache.lucene.queryParser.ParseException: Cannot parse ':"field_product_availability:84"': Encountered " ":" ": "" at line 1, column 0.
Was expecting one of:
<NOT> ...
"+" ...
"-" ...
"(" ...
"*" ...
<QUOTED> ...
<TERM> ...
<PREFIXTERM> ...
<WILDTERM> ...
"[" ...
"{" ...
<NUMBER> ...
<TERM> ...
"*" ...

Any ideas?

khiminrm’s picture

Maybe the problem is in ':' added by module before my query?

vabue’s picture

subscribe

khiminrm’s picture

Category: support » bug
pwolanin’s picture

Status: Active » Fixed

Yes, ":" is a special character in lucene syntax.

The field names in the index DO NOT match the field names in the DB, so not of your filters above will work.

However, the simple filter tid:84 should work.

pwolanin’s picture

Category: bug » support
khiminrm’s picture

Category: support » bug
Status: Fixed » Active

Sorry, but the filter tid:84 doesn't work and I have the same error in Recent log messages:
"400" Status: Bad Request: Bad RequestApache Tomcat/6.0.24 - Error report HTTP Status 400 - org.apache.lucene.queryParser.ParseException: Cannot parse ':"tid:84"': Encountered " ":" ": "" at line 1, column 0.
....

jpmckinney’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

I think khiminrm is saying that the apachesolr module is inserting the ":". And I think it is due to

$query->addFilter('', $custom_filters);

in apachesolr_mlt_suggestions. Fixed in patch.

pwolanin’s picture

Maybe we need some other cleanup of that MLT code too?

For the custom search pages I think it's taking a comma-separated list.

jpmckinney’s picture

Wouldn't it work as-is if it were a space-separated list instead?

pwolanin’s picture

No, since you can have a query with e.g. (X OR Y) groupings that contain spaces, or range queries with spaces.

khiminrm’s picture

Status: Needs review » Active
khiminrm’s picture

Status: Active » Needs review
khiminrm’s picture

I've aplied the patch, inputed tid:84 in the Additioanl Query field. The error message doesn't appear. But the block 'More like this' doesn't show anything.

jpmckinney’s picture

StatusFileSize
new1.29 KB

@pwolanin: K. It occurs to me that if there is a range query anywhere in the string, we should not double quote. Included that fix in the patch.

@khiminrm: Did you enable the Solr filter for the taxonomy product_availability?

khiminrm’s picture

@jpmckinney: Yes, I enabled filter for the taxonomy product_availability in the block settings. I even tried to enable filter "All taxonomy term names". After aplying the new patch - no results with filter tid:84. Without tid:84 the block shows links to the nodes with tid 84 or tid 85. My nodes have other terms from different vocabularies, not just 84 or 85 from vocabulary Availability. Maybe the problem is in this?
I tried facet filter block for vocabulary Availability in site's search results and It worked fine.

jpmckinney’s picture

It sounds like there are more bugs in the "more like this" feature that we need to fix. I don't have time to look into it right now, though.

nick_vh’s picture

Version: 7.x-1.0-beta7 » 7.x-1.x-dev
Status: Needs review » Needs work
janchojnacki’s picture

After changing

$filter['#value'] = '"' . $filter['#value'] . '"';

to this:

$filter['#value'] = $filter['#value'];

It was working for me, in addition to patch

janchojnacki’s picture

StatusFileSize
new1.33 KB

So, I upload valid patch for me. Unless somebody can tell me why there are needed quotation marks in
$filter['#value'] = '"' . $filter['#value'] . '"';

nick_vh’s picture

+++ Solr_Base_Query.phpundefined
@@ -121,17 +121,23 @@ class SolrFilterSubQuery {
-    $prefix = empty($filter['#exclude']) ? '' : '-';
+    $prefix = '';
     if ($filter['#local']) {
-      $prefix = '{!' . $filter['#local'] . '}' . $prefix;
+      $prefix .= '{!' . $filter['#local'] . '}';
+    }
+    if (!empty($filter['#exclude'])) {
+      $prefix .= '-';

This seems wrong to me?
Are you sure the exclude has to appear after the local parameter?

+++ Solr_Base_Query.phpundefined
@@ -121,17 +121,23 @@ class SolrFilterSubQuery {
-    if (preg_match('/[ :]/', $filter['#value']) && !preg_match('/^[\[\{]\S+ TO \S+[\]\}]$/', $filter['#value']) && !preg_match('/^["\(].*["\)]$/', $filter['#value'])) {
-      $filter['#value'] = '"' . $filter['#value'] . '"';
+    if (preg_match('/[ :]/', $filter['#value']) && !preg_match('/[\[\{]\S+ TO \S+[\]\}]/', $filter['#value']) && !preg_match('/^["\(].*["\)]$/', $filter['#value'])) {
+      $filter['#value'] = $filter['#value'];

Also, I don't see the need in changing these regular expressions? If the only thing you want is to remove the name and only set the value you shouldn't need those changes right?

blazindrop’s picture

I had the same issue today with our related content block (powered by MLT) was bringing content in from other sites (we have one index for all sites). The same error was raised as in #1.

I stumbled upon this issue after reading through some code and see there was a @todo for handling comma-separated custom filters. Here's my initial thought:

     if ($custom_filters = $settings['mlt_custom_filters']) {
       // @todo - fix the settings form to take a comma-delimited set of filters.
-      $query->addFilter('', $custom_filters);
+      // mlt_custom_filters are comma delimited, name:value pairs.
+      $filters = explode(',', $custom_filters);
+      foreach ($filters as $filter) {
+         list($key,$val) = explode(':', $filter);
+         $query->addFilter($key, $val);
+      }
     }

Certain fields in SOLR require quotes (like string) whereas text fields don't (if you're doing a search and don't want a literal match). If the field you're filtering by requires quotes, just place them into the custom filter input box vs. fussing with a regex on the code side.

Negation logic can be added to the code above without much effort.

My two (maybe only one, heh) cents....

nick_vh’s picture

Could you please make this a real patch? And also describe a test case where the original code fails and the modified one succeeds?

nick_vh’s picture

Category: bug » feature
kevinquillen’s picture

Issue summary: View changes

Same issue, tried to add a filter from the MLT config to show results only for date created in a certain range (which is on the description in the form field). No matter what I enter, no results come back, and the server returns a ''bad request'' error from including the ds_created:[DATE TO DATE] filter. If I remove it, it works fine.

jason_purdy’s picture

I'm also running into this issue. I have a custom field in my solr index and whenever I try to filter based on the field, it creates a bad request because of the colon at the beginning.