Advanced search

Is there any way we can limit the specific fields in the advanced search page to only some of the DC fields and not all?

See http://omeka.org/codex/Recipes/Removing_Fields_from_Advanced_Search

It worked in previous versions of Omeka, although I don't know if it works in the current version.

Thanks for the link Andy.
The file application/views/scripts/items/advanced-search.php does not exist anymore in the Omeka 2. version.

I suppose it's the search-form.php now.

I copied the code in the beginning of this file but the page returns an error message "Fatal error: Call to undefined function js()..."

Did anyone here update this code for the new version of Omeka?

If you're using Omeka 2.0 or higher, you'll need to update any use of the js() function to use the newer js_tag() function.[*]

The default code for that file appears to be using js_tag already, so you may have accidentally copied from a pre-2.0 version?

[*] See: http://omeka.org/codex/Updating_Plugins_For_2.0 and http://omeka.readthedocs.org/en/latest/Reference/libraries/globals/js_tag.html

I am also trying to limit the individual fields shown in the advanced search drop-down menu. I fiddled with it a bit today and I succeeded in being able to hide a GROUP of metadata elements (either Dublin Core or Item Type Metadata) but not individual elements.

The trick with copying the code from the recipe Andy linked to is that you need to paste it near the end of the search-form.php file. You'll notice at the end of the search-form.php file there is some code within script tags. Find the last </script> tag, which should be at the very end of the document, and paste the following code (copied from the recipe, but without the opening and closing script tags) right before it:


jQuery(document).ready(function () {
var blackListGroups = [
"Item Type Metadata",
"Contribution Form"
];
var blackListElements = [
"Contributor",
"Coverage",
"Format",
"Identifier",
"Language",
"Relation",
"Rights",
"Source",
"Type"
];
jQuery.each(blackListGroups, function (index, value) {
jQuery("#advanced-0-element_id optgroup[label='" + value + "']").remove();
});
jQuery.each(blackListElements, function (index, value) {
jQuery("#advanced-0-element_id option[label='" + value + "']").remove();
});
});

However, at least for me (I'm running Omeka 2.1.1), this only hid the Item Type Metadata elements, or the Dublin Core elements if I change "Item Type Metadata" to "Dublin Core." Hiding the individual elements does not work, and I don't know why. So for now, you may as well just use the following shortened code (I also took out "Contribution Form" because I'm not sure what that is, and taking it out doesn't appear to change anything) if you want to hide a group of elements:


jQuery(document).ready(function () {
var blackListGroups = [
"Dublin Core"
];

jQuery.each(blackListGroups, function (index, value) {
jQuery("#advanced-0-element_id optgroup[label='" + value + "']").remove();
});
});

I hope this helps as a temporary solution. Anyway, as I am also trying to hide individual metadata elements, I too am hoping someone might be able to shed some light on this issue. Thank you Andy and ebellempire for your help thus far!

I've tried your code and it seems to work for some fields (type, format, source) but not for the others.

We can also try to bonly blacklist elements and not groups with thw code below but the result is the same...

jQuery(document).ready(function () {

var blackListElements = [
"Contributor",
"Coverage",
"Format",
"Identifier",
"Language",
"Relation",
"Rights",
"Source",
"Type"
];

jQuery.each(blackListElements, function (index, value) {
jQuery("#advanced-0-element_id option[label='" + value + "']").remove();
});
});

John could probably help here :)

I'm running Omeka version 2.1.3 and the following code is working for me. This solution differs from the other solutions I've seen because you specify the DC metadata elements you want to include, not the ones you want to exclude. (Since we're using Qualified Dublin Core, listing the elements to include is much easier than listing the ones to exclude.) The changes are to search-form.php. The modified copy goes into the themes/your_theme/items folder.


    jQuery(document).ready(function () {
        var showDCTerms = [    // This is a list of all of the DC metadata elements we want to display
        'Contributor',
        'Date',
        'Description',
        'Has Part',
        'Identifier',
        'Subject',
        'Title'
        ];
    // Loop through the DC metadata elements in the HTML one by one
       var foundsw;
       jQuery("optgroup[label='Dublin Core'] > option").each ( function (index, element) {
        currentTerm = jQuery(this).text();         //Grab name of the current DC element in HTML e.g. Subject
        foundsw = false;
        for (i=0 ; i < showDCTerms.length ; i++) {
            if ( showDCTerms[i] == currentTerm ) {
                foundsw = true;
                break;
            }
        }
        if ( !foundsw ) {                           // Is the current DC element a keeper?
            jQuery(this).remove();                // No, remove it from the HTML
        }
    });                                           // end each loop
    jQuery( "optgroup[label='Item Type Metadata']" ).remove();  // Don't display item type metadata elements
    });

The code slynch posted works as advertised, hooray! Thanks for the helpful commenting, too.

However, I want to take it one step further--is it possible to suppress the element set name? I want to show Dublin Core elements, but I don't want the phrase "Dublin Core" to appear before they are listed.

(The element set names are already suppressed on show.php, so there's some concern that having them in the search form will be "confusing.")

Since this is such a common request, plans are for the the upcoming Omeka 2.2 to just include a checkbox to remove the element set name heading.

In the meantime, themes can easily remove that by including an edited common/record-metadata.php that simply omits the line that prints the heading.

Hmm, I hide the headings in show.php through record-metadata.php, but they are still showing in the search dropdown. Instead of deleting the line, I have it set as a conditional.


<?php if ($setName != ('Dublin Core' or 'Text Item Type Metadata')): ?>
<h2><?php echo html_escape(__($setName)); ?></h2>
<?php endif; ?>

Ah this is my reading comprehension failing me, I'm talking about show.php which of course you already mentioned.

For the search dropdown, removing those means removing the <optgroup>. I can't think of any way to do that in javascript other than selecting the options inside <optgroup> elements, moving those to directly under the select, then removing the <optgroup>.

This brings up an interesting question to me: If we have a setting that hides the element set headings, should we also be suppressing those <optgroups> from the advanced search?

In my opinion, yes--element set headings should be hidden everywhere.

I agree with that. If they are able to be hidden one place they should be hidden everywhere...at least in the public view of the site.

This is an issue I was starting to think about. One the public search, I felt the organization by metadata type and name would scare many public users away from using the search.

Most people coming to our site are not going to know what Dublin Core means.

I simply removed the DC names from the show.php view since Tom favors a compact display and I prefer leaving the labels off because I feel people know what the information means without them. A visitor to our site reads 27mi B&W 16mm and they already know that its a film, that it has a duration, color and format. They go without saying.

I'm sure I'll be back to this thread :)

This conversation also reminds me I've been letting some helpful code languish unreleased. Jim Safley contributed an update to the Hide Elements plugin that adds the option to hide elements from the items advanced search dropdown.

I've finally gotten around to releasing that as version 1.2 of Hide Elements. For anyone in this thread already using Hide Elements, this should make it much easier to keep the search form in sync with what you're showing elsewhere.

As for people currently using the Javascript solutions posted here, removing the optgroups (the bold sub-groupings of elements) there should be fairly simple. Inside the jQuery(document).ready callback where the rest of the work is happening, adding this should do the trick:

jQuery('.search-entry optgroup').replaceWith(function () {
    return jQuery(this).children();
});

Works as advertised, thanks!

The code below removes both the group headings ('Dublin Core' or 'Item Type Medata') and removes elements defined in the blacklist (in this case: contributor and creator). I used John's code to remove the headings.

Just replace the javascript at the bottom of search-form.php with this.

jQuery(document).ready(function () {
        Omeka.Search.activateSearchButtons();   

        jQuery('.search-entry optgroup').replaceWith(function () {
            return jQuery(this).children();
        });

        var blackListElements = [
        "Contributor",
        "Creator"
        ];

        jQuery.each(blackListElements, function (index, value) {
            jQuery(".advanced-search-element option").filter(function(){
                if(jQuery(this).text() == value)
                {jQuery(this).remove();}
            });
        });
    });