Return nodes instead of files itself
groenm - September 24, 2009 - 05:07
| Project: | Search Files |
| Version: | 6.x-2.0-beta4 |
| Component: | Search File API |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
Hi,
Currently this module returns links to the files itself in the search results. In some of my projects the nodes to which the files are attached contain metadata on the file. When doing a full text search, it is not possible to get to this metadata, as the search results only include a link to the file and there is no way to navigate from the file to the node to which the file is attached.
Is it possible to optionally return the nodes the files from the search result are attached to instead of the files themselves? Alternatively, is it possible to not only return a link to the file, but also a link to the node the file is attached to?
Thanks,
Groen

#1
I would also like this feature. Tracking.
#2
Sounds useful. Sub +1.
#3
I was browsing search_files recently, and found this issue.
You can theme a search result via Drupal's core php template file, search-result.tpl.php.
#4
Probably you are right, but I think a theme is not the proper place to implement such functionality. And someone with the right knowledge to implement this in the theme is probably also capable of addressing the issue in the model itself.
Groen
#5
I don't think that this is something that could/should merely be handled via theming. From my perspective, it's related to another current issue:
http://drupal.org/node/507298
The attachment search results that people see needs to obey node and field access the way that core search does, so having information about the parent node object with the record is an important part of the functionality.
#6
Re #4, I do think this is exactly a theme issue. The goal is to have flexible display options, and this is what search-result.tpl.php (or a theme function in template.php) is for. The module returns the necessary data to display whatever the site wants it to.
Re #5, Theming the results isn't really related to the security issue. The search method should handle access, not the output, although you could do this. The output/theming is independent of the actual search file/attachment results. You have an array of results that get themed via a template file.
#7
Here is why I think it is related; the same bit of the code is in question in both cases (
search_files_attachments.moduleL125):<?php// Load results.
$results = array();
foreach ($find as $item) {
// Build the node body.
$file = db_fetch_object(db_query("
SELECT f.*, d.data, u.nid
FROM {files} AS f
JOIN {upload} AS u
USING(fid)
INNER JOIN {search_dataset} AS d
ON f.fid = d.sid
WHERE fid = %d
", $item->sid));
$node = node_load($file->nid);
$realpath = realpath($file->filepath);
if (is_file($realpath)) {
$fileinfo = (object)pathinfo($realpath);
$results[] = array(
'link' => url($file->filepath),
'title' => $file->filename,
'user' => theme('username', $node),
'date' => $file->timestamp,
'type' => check_plain(search_files_helper_name($fileinfo->extension)),
'node' => $node,
'score' => $item->score / $total,
'extra' => array(l(t('Node'), "node/" . $node->nid)),
'snippet' => search_excerpt($keys, $file->data),
);
}
}
?>
node_load()happens, so the node link does get passed on to theming, contrary to what I originally thought... but the node object itself does not, and has no bearing on whether, or how, data gets added to the$resultsarray. In my opinion, as these are node attachments, a better approach would treat the node object itself as the main matter; which would impact both which results get included and what default structure they have (link, title, snippet) when passed along to theming.Also, I don't think a "node listing" versus "file listing" option is an unreasonable feature to include in the module UI.
#8
+1
Having only a link to the node is a bit more work for the user, because when he arrives at the node first he then has to find the right attachement which can be difficult when there are more then one attached files. On the other hand by forcing the user to arrive at the file via the node you would also elegantly work around the bug I reported here: http://drupal.org/node/598136
At the moment the direct file link is useless for me, because it doesn't work with private file system setting. Then I rather prefer that the node link becomes the primary way to arrive at the file.
#9
This was bugging me, so I fixed it. There is now an additional administrative option under admin/settings/search_files/attachments/settings that allows you to chose whether to return links to files and use file titles (default), or return links and titles to nodes. Give it a try and let me know how it works! This is against 6.x-2.0-beta4.
#10
I tested my last patch again, and I botched the direct download link for the file. Here it is, but fixed.
#11
Thanks for your help.
I gave it a quick try yesterday, but apparently I am running a dev version which is no longer up to date. I will give it another try this weekend.
Mark
#12
It appears to work. I think our versions 6.x-2.0-beta4 are not the same though, because running the patch failed. Don't know how that can have happened. Manually applying the changes worked though. I got the search page with both the title of the node and the link to the PDF.
Thanks a lot!
Mark