Changing search results to display item and not file

My archive has a collection of school newspapers. When I do a search query, my results list the file with a link to the metadata page with an image of the pdf file. Is there a way to have the search result display the link to the item itself? The pdf plugin is installed and is working otherwise the search wouldn't find the file.

If I limit the search to items with the same query, then no results are found.

That happens because the PDF plugin stores the text on the file itself, not the item. Thus, the search results hit the file.

To change the behavior on the search results page, you'd just need to override the default page and make a small change. See this guide to overriding default theme pages. The page you'll need to copy over is /search/index.php.

When you've copied over that file to your theme, make the following change. Just before this line:

<?php set_current_record($recordType, $record); ?>

add this:

<?php
    if ($recordType == 'File') {
        $record = $record->getItem();
    }
?>

Hi Patrick,

My /search/index.php file in the default theme reads like this:

<?php
$pageTitle = __('Search Omeka ') . __('(%s total)', $total_results);
echo head(array('title' => $pageTitle, 'bodyclass' => 'search'));
$searchRecordTypes = get_search_record_types();
?>
<?php echo search_filters(); ?>
<?php if ($total_results): ?>
<?php echo pagination_links(); ?>
<table id="search-results">
<thead>
<tr>
<th><?php echo __('Record Type');?></th>
<th><?php echo __('Title');?></th>
</tr>
</thead>
<tbody>
<?php foreach (loop('search_texts') as $searchText): ?>
<?php $record = get_record_by_id($searchText['record_type'], $searchText['record_id']); ?>
<tr>
<td><?php echo $searchRecordTypes[$searchText['record_type']]; ?></td>
<td>"><?php echo $searchText['title'] ? $searchText['title'] : '[Unknown]'; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo pagination_links(); ?>
<?php else: ?>
<div id="no-results">
<p><?php echo __('Your query returned no results.');?></p>
</div>
<?php endif; ?>
<?php echo foot(); ?>

Since there wasn't a search folder in my Seasons theme, I copied the folder from the applications folder and then placed it in the seasons theme folder. Since I was only changing the index.php, I only placed that file, is that right? Anyway, since I couldn't find the piece of code for php set_current etc, I experimented and put it in several different places. Some resulted in an error message, and others simply didn't work. Any thoughts?

Thanks,
Nancy

Ah! My bad, sorry. I was looking at the soon-to-be-released version of that file. What you have done, though, is exactly right so far.

Let's try this. After

<?php $record = get_record_by_id($searchText['record_type'], $searchText['record_id']); ?>

put in:

<?php
if ($searchRecordTypes[$searchText['record_type']] == 'File') {
    $record = $record->getItem();
}
?>

No problem - when it's released I'll be one step ahead. I inserted the code and it works perfectly. Thanks!