Sort and next/previous search results

After spending a few days on the forum and online, I need your advice. I am an archivist, not an IT person, but am dealing with getting our collection pages streamlined (http://arpc65.arm.ac.uk/omeka/).

Could you advise on what code to use to sort 'search results' by f.e. identifier, title, date? All the sort commands I found on the Forum and tried sort the entire database, not just the search result. I am unsure where to insert sort_field!

Also, when entering search results on item level, next/previous buttons go to the next item in the entire database, not the next in the search result. How can I change that (if at all)? I have seen the recipe posted recently, but that goes over my head!

Below is my current items - show.php

Are there any glaring and obvious omissions that you could point out?

<?php head(array('title' => item('Dublin Core', 'Title'), 'bodyid'=>'items','bodyclass' => 'show item')); ?>

<div id="primary">

	<h1><?php echo item('Dublin Core', 'Title'); ?></h1>

	<!-- The following returns all of the files associated with an item. -->
	<div id="itemfiles" class="element">
		<div class="element-text">
		    <?php
		    if (item_has_thumbnail())
					{
					echo '<p><em>Click thumbnail for full size image(s)</em></p>';
					$file = loop_files_for_item();
					echo display_file($file, array('linkAttributes' => array('rel' => 'lightbox[gallery]')));
					while($file = loop_files_for_item()):
					if ($file->has_derivative_image):
   					echo display_file($file, array('linkAttributes' => array('rel' => 'lightbox[gallery]', 'class' => 'hiddenfile')));
   					endif;
endwhile;}
			else
				{
				echo display_files_for_item();
				}
			?>
		</div>
	</div>

<!-- end item-metadata -->

      	<!--  The following function prints all the the metadata associated with an item: Dublin Core, extra element sets, etc. See http://omeka.org/codex or the examples on items/browse for information on how to print only select metadata fields. -->

    	<?php echo custom_show_item_metadata(); ?>

	<!-- If the item belongs to a collection, the following creates a link to that collection. -->
	<?php if (item_belongs_to_collection()): ?>
        <div id="collection" class="element">
            <h3>Collection</h3>
            <div class="element-text"><p><?php echo link_to_collection_for_item(); ?></p></div>
        </div>
    <?php endif; ?>

	<?php echo plugin_append_to_items_show(); ?>

	<ul class="item-pagination navigation">
	<li id="previous-item" class="previous">
		<?php echo link_to_previous_item('← Previous Item'); ?>
	</li>
	<li id="next-item" class="next">
		<?php echo link_to_next_item('Next Item →'); ?>
	</li>
	</ul>

</div><!-- end primary -->

<?php foot(); ?>

Those same sorting parameters will work fine if it's simply added to the search URL.

If you want to force a particular sorting for searches, you could put a hidden form input (or a select, if you want users to pick their sorting) on the Advanced Search page. You could do the same thing on your browse page, as long as you keep the big query string for the search and just add the sort_field and sort_dir params.

As for the next/previous buttons, you're basically on top of the state of things there. Your alternatives are to use the built-in behavior, which ignores any active search, or the recipe way, which involves changing the browse page and show pages to pass along those searching and sorting parameters.

Additionally you could add sorting links to your public browse page that are like the links of the admin browse page. If you go to the Admin Browse File starting at line 128 you'll see:

<?php
            $browseHeadings[__('Title')] = 'Dublin Core,Title';
            $browseHeadings[__('Creator')] = 'Dublin Core,Creator';
            $browseHeadings[__('Type')] = null;
            $browseHeadings[__('Public')] = 'public';
            $browseHeadings[__('Featured')] = 'featured';
            $browseHeadings[__('Date Added')] = 'added';
            echo browse_headings($browseHeadings); ?>

This is what lets you sort your search results in the admin screen. It selects the fields you want to search, and then prints out the links using echo browse_headings($browsHeadings);. I am using just the sort by date feature on my browse page, so on my browse page I have something like:

<?php $browseHeadings['Sort by Date'] = 'Dublin Core,Date';
  echo browse_headings($browseHeadings); ?>

But I'm guessing it could also include:

<?php $browseHeadings['Sort by Date'] = 'Dublin Core,Date';
      $browseHeadings[__('Title')] = 'Dublin Core,Title';
      $browseHeadings[__('Identifier') ='Dublin Core,Identifier';
  echo browse_headings($browseHeadings); ?>

Although I'm not sure how it would display multiple links on the public browse page. You might have to adjust the spacing. Also I'm not sure why the admin side has the ___ before the name.

Thank you both for your replies! I have tried Andy's suggestions, but that does not give me the result I am after.

I would like to go with John's suggestion to have a select in the advanced search page, if I would know where to implement them. I have double checked the advanced search page, but the sort already seems to be there...

<div class="inputs">
				<?php
				//If the form has been submitted, retain the number of search fields used and rebuild the form
				if(!empty($_GET['advanced'])) {
					$search = $_GET['advanced'];
				}else {
					$search = array(array('field'=>'','type'=>'','value'=>'', array('sort_field'=>'Dublin Core,Identifier')));
				}

I do not quite understand why it is not working. Adding another select myself makes things worse, i.e. error page.

Would you be able to pinpoint where I need to add the select in the php below? I would really appreciate that (after having spent the last 3 hours trying out your suggestions...)

Thanks!

<?php
if (!$isPartial): // If we are using the partial view of this search form.

head(array('title'=>'Advanced Search', 'bodyclass' => 'advanced-search', 'bodyid' => 'advanced-search-page'));
?>

<h1>Search Collections</h1>

<div id="primary">
<?php endif; ?>
<?php if (!$formActionUri): ?>
    <?php $formActionUri = uri(array('controller'=>'items', 'action'=>'browse')); ?>
    <?php echo js('jquery'); ?>
<script type="text/javascript" charset="utf-8">
  jQuery.noConflict();
  jQuery(document).ready(function() {
      var blackListElements = new Array();
      blackListElements[0] = "Coverage";
      blackListElements[1] = "Creator";
      blackListElements[2] = "Language";
       blackListElements[3] = "Rights";
        blackListElements[4] = "Source";
         blackListElements[5] = "Subject";
          blackListElements[6] = "Type";
           blackListElements[7] = "1st Author Initials";
            blackListElements[8] = "1st Author Surname";
             blackListElements[9] = "2nd Author Initials";
            blackListElements[10] = "2nd Author Surname";
                blackListElements[11] = "3rd Author Initials";
            blackListElements[12] = "3rd Author Surname";
                blackListElements[13] = "Atlas Cat";
            blackListElements[14] = "Author Ref";
             blackListElements[15] = "BCC";
                blackListElements[16] = "Bibliography";
            blackListElements[17] = "Biographical Text";
            blackListElements[18] = "Birth Date";
                blackListElements[19] = "Birthplace";
            blackListElements[20] = "Bit Rate/Frequency";
              blackListElements[21] = "CC";
            blackListElements[22] = "Compression";
                blackListElements[23] = "Date Published";
            blackListElements[24] = "Date Received";
             blackListElements[25] = "Death Date";
                blackListElements[26] = "Director";
            blackListElements[27] = "Duration";
            blackListElements[28] = "Edition";
                blackListElements[29] = "Email Body";
            blackListElements[30] = "Event Type";
               blackListElements[31] = "Flag";
            blackListElements[32] = "Interviewee";
                blackListElements[33] = "Interviewer";
            blackListElements[34] = "From";
             blackListElements[35] = "ISBN";
                blackListElements[36] = "Lesson Plan Text";
            blackListElements[37] = "Local URL";
            blackListElements[38] = "Location";
                blackListElements[39] = "Maker";
            blackListElements[40] = "Materials";
               blackListElements[41] = "Misc Info";
            blackListElements[42] = "Name";
                blackListElements[43] = "Number of Attachments";
            blackListElements[44] = "Number of parts";
             blackListElements[45] = "Objectives";
                blackListElements[46] = "Occupation";
            blackListElements[47] = "Original Format";
            blackListElements[48] = "Participants";
                blackListElements[49] = "Physical Dimensions";
            blackListElements[50] = "Producer";
               blackListElements[51] = "Published";
            blackListElements[52] = "Standards";
                blackListElements[53] = "Storage id";
            blackListElements[54] = "Subject Line";
             blackListElements[55] = "Subject Ref";
                blackListElements[56] = "Text";
            blackListElements[57] = "Time Summary";
            blackListElements[58] = "";
                blackListElements[59] = "To";
            blackListElements[60] = "Transcription";
             blackListElements[61] = "UBSC";
                blackListElements[62] = "UDCS";
            blackListElements[63] = "URL";
            blackListElements[64] = "Image url";
            blackListElements[65] = "Level of description";
            blackListElements[66] = "Relation";
            blackListElements[67] = "Format";
      for (var i = 0; i < blackListElements.length; i++){
           jQuery("#advanced-0-element_id option[label='" +
blackListElements[i] + "']").remove();
      }
  });
</script>
<?php endif; ?>

<form <?php echo _tag_attributes($formAttributes); ?> action="<?php echo html_escape($formActionUri); ?>" method="get">

	<div id="search-narrow-by-fields" class="field">

		<div class="label">Narrow by Specific Fields</div>

			<div class="inputs">
				<?php
				//If the form has been submitted, retain the number of search fields used and rebuild the form
				if(!empty($_GET['advanced'])) {
					$search = $_GET['advanced'];
				}else {
					$search = array(array('field'=>'','type'=>'','value'=>'', array('sort_field'=>'Dublin Core,Identifier')));
				}

				//Here is where we actually build the search form
				foreach ($search as $i => $rows): ?>
					<div class="search-entry">	

					<?php
					//The POST looks like =>
					// advanced[0] =>
						//[field] = 'description'
						//[type] = 'contains'
						//[terms] = 'foobar'
					//etc
					echo select_element(
						array('name'=>"advanced[$i][element_id]"),
						@$rows['element_id'],
						null,
						array('record_types'=>array('Item', 'All'), 'sort'=>'alpha')); ?>

					<?php
						echo select(
							array('name'=>"advanced[$i][type]"),
							array('contains'=>'contains', 'does not contain'=>'does not contain', 'is empty'=>'is empty', 'is not empty'=>'is not empty'),
							@$rows['type']
						);
					?>

					<?php
						echo text(
							array('name'=>"advanced[$i][terms]", 'size'=>20),
							@$rows['terms']);
					?>

					<button type="button" class="remove_search" disabled="disabled" style="display: none;">-</button>
					</div>
				<?php endforeach; ?>
			</div>
			<button type="button" class="add_search">Add a Field</button>

		</div>

	<?php is_admin_theme() ? fire_plugin_hook('admin_append_to_advanced_search') : fire_plugin_hook('public_append_to_advanced_search'); ?>
	<div>
	    <input type="submit" class="submit submit-medium" name="submit_search" id="submit_search_advanced" value="Search" />
    </div>
</form>

<?php echo js('search'); ?>
<script type="text/javascript">
    jQuery(document).ready(function () {
        Omeka.Search.activateSearchButtons();
    });
</script>
<?php if (!$isPartial): ?>
    </div> <!-- Close 'primary' div. -->
    <?php foot(); ?>
<?php endif; ?>

That Dublin Core,Identifier part you posted isn't normally part of the advanced search page, and it wouldn't really do anything there anyway.

All you'd need to do for the "dropdown" method I mentioned would be to make a HTML select element, and have option elements for each field you want to sort by. If you make the name of the select "sort_field" and make sure to put it inside the form, it should just work.

John, I am sorry to waste your time. Since your post I have tried to make the html select element and I can't make it work. I cannot find any examples that will show me explicitly what part of the select element that is already there needs to be replaced with what I need.

This is what I have got so far:

<?php
					//The POST looks like =>
					// advanced[0] =>
						//[field] = 'description'
						//[type] = 'contains'
						//[terms] = 'foobar'
						//[sort_field] = 'description'
					//etc
					echo select_element(
						array('name'=>"advanced[$i][element_id]"),
						@$rows['element_id'],
						null,
						array('record_types'=>array('Item', 'All'), 'sort'=>'alpha')); ?>

					<?php
						echo select(
							array('name'=>"advanced[$i][type]"),
							array('contains'=>'contains', 'does not contain'=>'does not contain', 'is empty'=>'is empty', 'is not empty'=>'is not empty'),
							@$rows['type']
						);
					?>

					<?php
						echo text(
							array('name'=>"advanced[$i][terms]", 'size'=>20),
							@$rows['terms']);
					?>
					<?php echo select_element(
						array('name'=>"advanced[$i][element_id]"),
						@$rows['element_id'],
						array('Identifier'=>'Identifier', 'Title' =>'Title', 'Date'=>'Date')); ?>

It's the end of my day. I hope that on Wednesday I will see the light!

You really don't need PHP code to do this, so don't just try to copy and paste something from that page.

By "select element" I was just referring to a plain HTML <select> tag. If you put something like <select name="sort_field">...</select> inside the form. You would put <option> tags for each sorting type you want inside the <select> tags.