Talk to Michael Hess about a possible approach.

Comments

mlhess’s picture

Status: Active » Needs work

The code below is called from a block hook and displays more like this results. Notice: I had to update solrphpclient with the lasted version, in order for this to work. This code is alpha and has some bugs. I need to read up on how the solrphpclient returns the morelikethis results. Also I did not the newest solrphpclient with anything other then my function below.

function mltblock_display($node) {
	$solr = & apachesolr_get_solr ( variable_get ( 'apachesolr_host', 'localhost' ), variable_get ( 'apachesolr_port', 8983 ), variable_get ( 'apachesolr_path', '/solr' ) );
	try {
		$params = array(
			'mlt' => 'true',
			'mlt.interestingTerms' => 'details',
			'fl' => '*,score',
			'rows' => 5,
			'mlt.fl' => 'body',
		// TODO: The next 2 lines should be in the block config
			'mlt.mintf' => 15,
			'mlt.mindf' => 10 
		);
		$response = $solr->search ( 'nid:' . $node, 0, 10, $params );
		//TODO: Figure out why this works
		$r =  (array) end( $response->moreLikeThis );
		$links = array();
		foreach ( $r['docs'] as $doc ) {
			$links[] = array(
				'href' => 'node/' . $doc->nid,'title' => $doc->title 
			);
		}
		return theme ( 'links', $links );
	} catch ( Exception $e ) {
		watchdog ( 'Apache Solr', $e->getMessage (), WATCHDOG_ERROR );
	}

}

robertdouglass’s picture

Thanks. This is a great start and I look forward to finding some calm time to look at it closely in the context of the ApacheSolr module.

mikejoconnor’s picture

StatusFileSize
new14.46 KB

mlhess,

Thanks for the great start. I've have the beginnings of an apachesolr moreLikeThis module together. It requires the new version of the SolrPhpClient(see issue 304388). I've tested this using Solr 1.3.0

There is still some work to be done, but I wanted to get something committed asap. Here are some limitations.

It doesn't allow for term boosting
It creates the query based on the current node you are viewing, rather than allowing the site administrator to create a custom query.

mikejoconnor’s picture

StatusFileSize
new14.47 KB

Try this one instead.....

mikejoconnor’s picture

Category: support » feature
Status: Needs work » Needs review

Switched status to code needs review, and changed the category to feature request.

robertdouglass’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Needs work

Committed a version of this to D5. Please use it to upgrade to D6.

mikejoconnor’s picture

Assigned: Unassigned » mikejoconnor

Assigning to myself

robertdouglass’s picture

This warning is showing up in my logs using the D5 version:

Invalid argument supplied for foreach() in /var/www/drupalorg/sites/solr.robshouse.net/modules/apachesolr/contrib/apachesolr_mlt/apachesolr_mlt.module on line 86.

robertdouglass’s picture

Assigned: mikejoconnor » Unassigned
Status: Needs work » Fixed

I gone and done it.

janusman’s picture

Status: Fixed » Needs review
StatusFileSize
new898 bytes

If no docs match a node, $r['docs'] is empty and the foreach in apachesolr_mlt_suggestions() fails. This happens if the current node has not yet been indexed in Solr, for example.

Here's a patch for D6:

Index: contrib/apachesolr_mlt/apachesolr_mlt.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_mlt/Attic/apachesolr_mlt.module,v
retrieving revision 1.1.4.3
diff -u -p -r1.1.4.3 apachesolr_mlt.module
--- contrib/apachesolr_mlt/apachesolr_mlt.module        26 Oct 2008 15:09:40 -0000      1.1.4.3
+++ contrib/apachesolr_mlt/apachesolr_mlt.module        29 Oct 2008 23:45:09 -0000
@@ -98,8 +98,10 @@ function apachesolr_mlt_suggestions($blo
       //TODO: Figure out why this works
       $links = array();
 
-      foreach ($r['docs'] as $doc) {
-        $links[] = l($doc->title, 'node/' . $doc->nid);
+      if (is_array($r['docs'])) {
+        foreach ($r['docs'] as $doc) {
+          $links[] = l($doc->title, 'node/' . $doc->nid);
+        }
       }
 
       $suggestions = array();
janusman’s picture

Just found out that changing the block's name in admin/build/blocks does not override the setting given in /admin/settings/apachesolr_mlt ... is this a bug?

mikejoconnor’s picture

Assigned: Unassigned » mikejoconnor

I think so. Views 1 allows the block name to be changed in admin/build/block

janusman’s picture

Assigned: mikejoconnor » Unassigned
Category: feature » bug
Status: Needs review » Active

Getting today's 6.x-1.x-dev version from CVS results in a broken MLT configuration page. It seems the get_fields_in_index() method was eliminated from Solr_Base_Query.php

The error is:

Fatal error: Call to undefined method Solr_Base_Query::get_fields_in_index() in /opt/lampp/htdocs/dev/6/sites/all/modules/apachesolr/contrib/apachesolr_mlt/apachesolr_mlt.module on line 275

And occurs when calling admin/settings/apachesolr_mlt/configure_block (Add a new MLT block).

Switching to "bug report" as this is already committed. Perhaps it should also be critical? =)

pwolanin’s picture

It was moved to the new class that extends Service.php

    $solr = apachesolr_get_solr();
    $fields = $solr->getFields();
janusman’s picture

Status: Active » Needs review
StatusFileSize
new1.3 KB

Attached is a patch for #13 for D6-dev

#11 is a mystery since (to me) it seems the code is correct.

mikejoconnor’s picture

Status: Needs review » Fixed

Resolved both issues(#10 and #13) in DRUPAL-6--1, and the issue in comment 10 in the DRUPAL-5 version.

Changing the block name in admin/build/block does override the title on in the apachesolr_mlt configuration. I'd like to look into this more, but we should track it as a seperate issue. If you are still experiencing it please open an issue and document a few things about your install, in particular what type of caching you are running.

Thanks

Status: Fixed » Closed (fixed)

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