This may be a noobie question, but I have looked high and low for the answer, so it may be usepful to have this in the forum.
I have a site with thousands of items that refer to street addresses. On my resource template I have a special field for sort order which is the street name concatenated with a zero padded house number, so that 3 Cambridge street comes before 1000 Cambridge St.
Youāre looking to change the sorting for this one what page? Just the browse pages?
One common solution to this is to use the Navigation config to do it, as you can add parameters to the Browse page entries there, which let you set sorting. You look like youāre not really doing browses in the navigation so this might not be the route for you. Similarly sorting can be set in the Browse preview blocks which it looks like youāre using in a few places, and also in any manual links to browse pages that you might be using.
These all involve just putting in the query string for the sorting into the URL. To change the default thatās used when thereās no query string, that currently involves a module. We have an upcoming feature in the pipeline to allow changing default sorting just through the admin interface, though.
Thank you John.
Sorry my question was not clear. What I would like to find is the location where I can change the query that is used by the Omeka-S search tool. If I could change the sort order in this query, that would be great. But it would also be great if I could cause it only to search on items having a particular resource template ā or other sorts of filters.
After some more looking around. I now understand that SearchController.php is involved. I gather from the page on Theme Modifications That themes donāt override controllers (like what you said.) Iāll try making module that hacks SearchController.php. Any other hints you can provide are welcome.
Iām glad to hear that you are working on configurations for the search interfaces. Iāll take a look at the AdvanceSearch module, too.
I figured out that it is possible to change the default search query including the query expression and order-by settings in a theme without creating a new module.
Copy: omeka-s/applicastion/view/common/search-form.phtml
to: omeka-s/themes/yourtheme/view/common
Edit the html form to add hidden fields that define a search query. The default query is āfulltext_searchā here is my form statement that changes the search expression to ātitle containsā and the default search order to my custom property: cdash:maplot.
<?php
$translate = $this->plugin('translate');
// A lot of lines are removed here since we know in advance that our custom search returns only items.
// Notice that the controller and action here have been modified below to go directly to the Item/Browse
// action. Since our search returns only items we can simplify the route.
$searchAction = $this->url('site/resource', ['controller' => 'item', 'action' => 'browse'], true);
// This line captures the user's search string if it already exists in the url parameters, so that it can
// show up in the text box.
$searchValue = $this->escapeHtml($this->params()->fromQuery('property[0][text]', ''));
?>
<!-- Here we build a query predominantly of hard-coded values in hidden form fields. -->
<form action="<?php echo $this->escapeHtml($searchAction); ?>" id="search-form">
<input type="text" name="property[0][text]" value="<?php echo $searchValue; ?>"
placeholder="<?php echo $translate('Title Contains'); ?>"
aria-label="<?php echo $translate('Title Contains'); ?>">
<!-- Make sure that the Sort_By field is listed in th Item Browse -->
<input type="hidden" name="sort_by" data-name="sort_by" value="cdash:mapLot">
<input type="hidden" name="sort_order" data-name="sort_order" value="asc">
<input type="hidden" name='property[0][joiner]' value='and' >
<input type="hidden" name='property[0][property]' value='1' >
<input type="hidden" name='property[0][type]' value='in' >
<input type="hidden" name='resource_template_id[]' value='7'>
<button type="submit"><?php echo $translate('CDASHSearch'); ?></button>
</form>
If your order-by property is not included in the drop-down menu on the search page, you will need to copy: omeka-s/application/view/omeka/site/item/browse.phtml
to: omeka-s/themes/yourtheme/omeka/site/item/browse.phtml
and edit the SortHeadings.
Handy tools and references: Omeka-S ApI Query documentation
Use Advanced search to look at how searches translate to URL parameters.
Use a URL decoder to translate the query parameters to readable text.
Keep playing with your search-form.phtml until the URL produced and the search behavior are what you want.