This is a bit of an interesting issue. ATM, this module will automatically locate filefield files and files attached using drupal's native file attachment. Pushing other files is not really possible though. In my case, I want to expose documents that are stored by Ubercarts File Downloads module to be indexed. This particular use case is complicated by the fact that Ubercart doesn't use Drupal's file management at all.

The attached patch is a bit of a work in progress that takes a simple approach to solving this problem. There are 2 parts and I'm not sure its the right answer but it seems to be working so far. There is also a reference implementation using uc_file that I'm using for testing.

  1. It provides an additional hook(I used drupal_alter for simplicity) that allows other modules push file objects into the array of files to be parsed. This works pretty well and Ubercart can work around the reliance on the file fid field by providing a psuedo namespace on its fids.
  2. It relies on the file url being stored in solr. I kinda dislike this part of the patch since it means you'll have to re-index to get any Drupal filehandling changes but D6 file handling is so wonky you've got to jump through 50 hoops to do that anyways and I'm not sure it was better before.

I'm marking this as needs review but its very likely in need of work. Its a rough implementation that I'm still testing on our dev machine.

Comments

neclimdul’s picture

Title: Allow for » Allow for different file backends

woops, forgot to finish the title.

pwolanin’s picture

Status: Needs review » Needs work

I don't want to index the result of file_create_url().

A better option is to follow Drupal 7's version and we should either re-implement the Drupal 6 version, or wrap the druapl 6 version with anither function that also calls drupal_alter()

neclimdul’s picture

ok another stab. I haven't had a chance to test this but looking for conceptual feedback to make sure its the right idea.

pwolanin’s picture

looks like on the right track, but this change should use the new function too:

-        $document->url = file_create_url($file->filepath);
+        $document->url = $file->url;
neclimdul’s picture

Actually it uses it in building the output in apachesolr_attachments_apachesolr_process_results() but that line is building the document to send to solr so that result would be indexed.

Though, looking over it fresh in the morning, it should probably go back to $file->filepath? But since the next line is actually storing that maybe its not necessary... Don't know I'll float around IRC and we can talk it through if you want.

neclimdul’s picture

Updated patch built on top of #561862

rapsli’s picture

StatusFileSize
new20.24 KB

updated patch to latest head version, as it wouldn't apply anymore. Going to do some testing now, so we can get this into the module. I hope this is the goal?

csevb10’s picture

Status: Needs work » Needs review
StatusFileSize
new20.9 KB

Ok. I made a few modifications, predominately to support multisite functionality.

  • The biggest change is probably around my modifications for url storage. The patches above were using relative urls for convenience, but this means that multisite implementations by default send everyone to whichever site is originating the search rather than the originating site of the file. To keep it more inline with the node implementations and allow multisite implementations to work correctly, I've made the url absolute. I left the ability for a module to override the behavior if desired.
  • I corrected the spelling of seperate to separate
  • I protected for a few php warnings from member variables not being set (primarily description)
  • I simplified the admin theming to remove the "hack" portion of things. It was pretty theme dependent and - while making the interface cleaner - didn't seem to be something that needed to be done for all sites. The resulting interface has a tad bit more spacing, but in general looks virtually identical
  • I modified the result processing so that it returns to using the solr-saved url for the link (since this value needs to be absolute for multisite implementations) and the node url from solr for the node link (since it's available) rather than the node/ link

It'd be good now to get another set of eyes back on this (neclimdul?) to see if what I've done here still works for your use cases in production.

pwolanin’s picture

A quick pass looks reasonable - some minor comments:

 function apachesolr_attachments_get_indexable_files($node) {
-  $files = array();
+  $files['drupal'] = array();
 
   if(!empty($node->files)) {
-    $files = $node->files;
+    $files['drupal'] = $node->files;
   }
 
   $fields = apachesolr_attachments_get_cck_file_fields();
   foreach ($fields as $field) {
     if(!empty($node->$field)) {
-      $files = array_merge($files, $node->$field);
+      $files['drupal'] = array_merge($files['drupal'], $node->$field);
     }
   }
+
+  // Allow other modules to attach files to be indexed.
+  foreach (module_implements('apachesolr_attachments_files') as $module) {
+    $files[$module] = module_invoke($module, 'apachesolr_attachments_files', $node);
+  }
+

It might make more sense for this to be an alter hook?

In any case, I'd rather see $files['upload'] and $files['filefield'] than $files['drupal']

neclimdul’s picture

I think I grouped those two items into 'drupal' because they use the same backend and other parts of the code would have to be reworked to support them.

That said, that may be a argument for providing an alter hook, though personally it seems like it would be better in addition to rather than in replacement of the hook.

csevb10’s picture

StatusFileSize
new20.77 KB

Here's a version simply switching the file types.
The only issue I can see with this is that a later hook (apachesolr_attachments_url) is based off of the file type. So, if you wanted to do the same thing to filefield elements and upload module elements, you'd now need 2 separate hooks. I think that's reasonable.

If this isn't sufficient, I can roll another version switching to drupal_alter.

pwolanin’s picture

Status: Needs review » Needs work

Instead of 'file_type' maybe we should call this 'module' or or 'file_module'? It's not the file type at all.

csevb10’s picture

Status: Needs work » Needs review
StatusFileSize
new20.77 KB

Updated from file_type to file_module and modified existing text to be more logical.

pwolanin’s picture

Status: Needs review » Needs work

One significant concern. For the update function:

+    'initial' => 'drupal',

needs to be 'upload'? But some will actually be 'filefield'?

Some minor nits:

This doxygen needs better formatting:

 /**
+ * Get the indexing mode for the attachments of a given node.
+ *
+ * @param $node
+ * A node object.
+ * @return
+ * Index mode
+ */

this code comment is unneeded:

+  $form['#theme'] = 'apachesolr_attachments_content_type_settings'; // reset form theme.

?

topdillon’s picture

I am currently using 7.x-1.2. Is there any hope of this patch working for me?