Adding Categories to Simple Search Results


Is there a way I could make the simple search results show more than just "Record Type" and "Title"? I would like to add "Description" but within a certain character limit like on the Geolocation plugin results in the map balloons.


You could do this by overriding the default search results in your theme. Copy the file application/views/scripts/search/index.php into a parallel folder inside your theme: {your theme}/search/index.php

Then you can change the table however you need. For your case, you could get a snippet of 200 characters with options to the metadata function like this:

echo metadata($record, array('Dublin Core', 'Description', array('snippet'=>300));

I made the parallel file and added the code but I got some errors. First was a server error for a missing ")" and after that was fixed I received an Omeka error but it is not reporting the error in the error file in the Admin folder so I am unsure what is exactly wrong. Here is the code for my index.php page within my theme folder.

Do you have any thoughts on what might be wrong?

$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">
<th><?php echo __('Record Type');?></th>
<th><?php echo __('Title');?></th>
<th><?php echo __('Description');?></th>
<?php foreach (loop('search_texts') as $searchText): ?>
<?php $record = get_record_by_id($searchText['record_type'], $searchText['record_id']); ?>
<td><?php echo $searchRecordTypes[$searchText['record_type']]; ?></td>
<td>"><?php echo $searchText['title'] ? $searchText['title'] : '[Unknown]'; ?></td>
<td><?php echo metadata($record, array('Dublin Core', 'Description', array('snippet'=>300)));?></td>
<?php endforeach; ?>
<?php echo pagination_links(); ?>
<?php else: ?>
<div id="no-results">
<p><?php echo __('Your query returned no results.');?></p>
<?php endif; ?>
<?php echo foot(); ?>

Looks like more misplaced parens. Hopefully this does it

metadata($record, array('Dublin Core', 'Description'), array('snippet'=>300));


I am still getting an error. I changed it to development mode via the htaccess file and this is the complete error I get.

Method named getElementTexts() does not exist.

#0 /home/pna6fb9i/public_html/projects/archive/application/libraries/Omeka/Record/AbstractRecord.php(210): Omeka_Record_AbstractRecord->delegateToMixins('getElementTexts', Array)
#1 /home/pna6fb9i/public_html/projects/archive/application/views/helpers/Metadata.php(185): Omeka_Record_AbstractRecord->__call('getElementTexts', Array)
#2 /home/pna6fb9i/public_html/projects/archive/application/views/helpers/Metadata.php(185): Exhibit->getElementTexts('Dublin Core', 'Description')
#3 /home/pna6fb9i/public_html/projects/archive/application/views/helpers/Metadata.php(151): Omeka_View_Helper_Metadata->_getElementText(Object(Exhibit), 'Dublin Core', 'Description')
#4 /home/pna6fb9i/public_html/projects/archive/application/views/helpers/Metadata.php(83): Omeka_View_Helper_Metadata->_getText(Object(Exhibit), Array)
#5 [internal function]: Omeka_View_Helper_Metadata->metadata(Object(Exhibit), Array, Array)
#6 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/View/Abstract.php(350): call_user_func_array(Array, Array)
#7 /home/pna6fb9i/public_html/projects/archive/application/libraries/globals.php(1966): Zend_View_Abstract->__call('metadata', Array)
#8 /home/pna6fb9i/public_html/projects/archive/application/libraries/globals.php(1966): Omeka_View->metadata(Object(Exhibit), Array, Array)
#9 /home/pna6fb9i/public_html/projects/archive/themes/default/search/index.php(23): metadata(Object(Exhibit), Array, Array)
#10 /home/pna6fb9i/public_html/projects/archive/application/libraries/Omeka/View.php(117): include('/home/pna6fb9i/...')
#11 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/View/Abstract.php(888): Omeka_View->_run('/home/pna6fb9i/...')
#12 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Action/Helper/ViewRenderer.php(900): Zend_View_Abstract->render('search/')
#13 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Action/Helper/ViewRenderer.php(921): Zend_Controller_Action_Helper_ViewRenderer->renderScript('search/', NULL)
#14 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Action/Helper/ViewRenderer.php(960): Zend_Controller_Action_Helper_ViewRenderer->render()
#15 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#16 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Action.php(527): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#17 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('indexAction')
#18 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#19 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#20 /home/pna6fb9i/public_html/projects/archive/application/libraries/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#21 /home/pna6fb9i/public_html/projects/archive/application/libraries/Omeka/Application.php(79): Zend_Application->run()
#22 /home/pna6fb9i/public_html/projects/archive/index.php(23): Omeka_Application->run()
#23 {main}

You need to make sure you only try to make this metadata call on records that support element texts: that'd be Items, Collections, and Files.

You're getting this error because one of your search results is an Exhibit. You need to check against $searchText['record_type'] and make sure it's one of the above types before you try to call metadata.

Thank you! That worked perfectly.

Is there a way to make the simple search results sortable? (Like the browse or advanced search results?)

I understand how this works for the public site, but how do I do the same for the admin site? A lot of items we have don't have a title so there is absolutely no information at all when a simple search is done in the admin view. I'm making more and more changes to the public theme, which slowly turns it into something totally different than the admin theme. This is becoming a bit confusing for the importers/annotators.

Also (maybe not suitable for this thread), would it be possible to make some function for inclusive/exclusive search in the advanced search form?

I rephrased and expanded my question here:

Hey guys,

Is there a way to do this but listing tags associated with an item, instead of a description? (specifically within the search results table)

If I put the following, nothing appears where I've set up a new column for tags:

<?php if (metadata('searchText', 'has tags')): ?>
<?php echo tag_string('search_texts'); ?></p>
<?php endif; ?

Help would be very much appreciated!

Hi everyone,

I am also interested in adding a thumbnail to simple and advanced search results. I am having to do a lot of work modifying our theme to work with Omeka 2+. Any help would be great.

Thanks, Jen (AMNH Research Library)

The trick is that the $searchText object is different from the actual record found. The default search/index.php file digs up the actual record from the searchText. That's what you'll want to check for whether there are tags, images, or whatnot:

<?php if (metadata($record, 'has tags')): ?>