I just realized that the MoreLikeThis functionality is no longer working (completely) when updating to Solr 4.x. I've debugged a bit and reported my findings, since I think it's a Solr problem, in this Apache Solr issue.

However, since I don't know how quick the Apache Solr team usually is in fixing bugs (and since I can't be sure at the moment that it actually is one), and since we don't allow versions of 4.3+ at the moment anyways, I guess we should work around this in our module for now.

Comments

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new1.83 KB

Patch attached. It simply doesn't add integer, float and date fields to the mlt.fl parameter.

drunken monkey’s picture

Added a note to the README.txt and committed.

However, I'm setting this back to "active" as we should probably find a better solution for this. After all, taxonomy terms are usually one of the major sources for MLT queries, and since they are indexed as integers they won't be available anymore for Solr 4 now.

One way to do this would be to add a setting to the server, which would automatically add string versions of all indexed integer, float and date values to the Solr index, and then replace the field prefix accordingly if a MLT query uses these fields.
Other ideas would also be welcome.

drunken monkey’s picture

Status: Needs review » Active
owen barton’s picture

One workaround that I just used that (I think!) is working is to add a specific MLT aggregate field to the index, and add the taxonomy (and other high signal) fields to that.

drunken monkey’s picture

The Apache Solr issue seems to be "won't fix", as – according to the most recent comment a few days ago – this is a Lucene limitation now. Therefore, I guess the only thing we could think about is to implement such a workaround directly in our module. I.e., index copies of all integer, float and date fields as strings or other data types that work. We could also make this a server option, so only people who want to use MLT would have the (minor) overhead.

rattusrattus’s picture

Issue summary: View changes

I'm using the approach outlined in #4 and it seems to be working here though it is an effort to have to duplicate all term fields as compound fields.

danielstrum’s picture

Hi Folks,
Thanks for the great module. I have just moved a site and am now forced to use Solr 4. Are there any plans to fox this so that MLT works with Solr4?
Thanks in advance.

drunken monkey’s picture

As outlined, it wouldn't be too difficult to add a workaround for this problem to the module. However, I currently don't have any time for working (unpaid) on D7 features (or minor bugs such as this), with the D8 port taking up most of my free time and my D7 modules only receiving important bug fixes (or features others develop).

So, if you want this, you'll either have to code it yourself or pay someone to do it for you. I'd definitely review a patch, if provided.

danielstrum’s picture

Hi dm... I should have added a comment here. I got this working using the latest dev version and the patch I found here:
https://www.drupal.org/node/1868434

Thanks for your response.

BarisW’s picture

Status: Active » Needs work

It seems that the patch in #1 already has been committed. However, this makes that matching content on terms doesn't work anymore. I'm not sure why this has been added, because matching on term id's works perfectly fine in Solr 4.x

For my project I 'fixed' it with the following piece of code, but I think this should be fixed in Search API Solr instead.

<?php
/**
 * Alter the Solr query so that the MLT on taxonomy terms works.
 *
 * An MLT view on taxonomy term fields does not work, because integer mlt
 * parameters are not added. We alter the query to add the appropriate
 * parameters again.
 *
 * See service.inc in the search_api_solr module from line 866.
 */
function MY_MODULE_search_api_solr_query_alter(&$call_args, &$query) {
  $query_options = $query->getOptions();
  switch ($query_options['search id']) {
    case 'search_api_views:you_might_also_like:block':
      $call_args['params']['qt'] = 'mlt';
      $call_args['params']['mlt.fl'] = 'im_field_tags,im_field_topics';
      break;
  }
}
?>
drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new2.18 KB

I'm not sure why this has been added, because matching on term id's works perfectly fine in Solr 4.x

Huh, you're (partially) right, it really seems they've fixed that now. It's definitely broken in 4.0.0, though, so we can't just remove the workaround. However, you can just manually set the Solr version number to 5.x in the Search API server settings – that should have no effect other than removing that workaround.

It seems it was fixed in this issue, since it starts working with versions higher than Solr 4.6.0. So as a general "solution", we can probably just check more closely for only the versions affected.

Also, while checking for this bug, I found out that Solr 5.x now throws a NullPointerException if you try to activate facets in an MLT request. So there's yet another Solr bug we have to work around.
I've also created a Solr issue for it.

Patch for both of these attached, please test!

drunken monkey’s picture

Status: Needs review » Fixed

Committed.

  • drunken monkey committed 18e90d8 on 7.x-1.x
    Issue #2004596 by drunken monkey: Fixed workarounds for MLT problems.
    

Status: Fixed » Closed (fixed)

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