The Metadata Plugin
Metadata Management for Manila
 
Site last updated
2/24/2006; 12:33:21 PM
 
Home

Why

Features

FAQ

Updates

Documentation

Download

Developers

Bugs

Feedback

Discuss

Planned
Features

 
 

The metaSearchForm and metaSearchResults macros

Author:   John VanDyk  
Posted: 8/3/2001; 4:51:39 PM
Topic: The metaSearchForm and metaSearchResults macros
Msg #: 820 (top msg in thread)
Prev/Next: 819/821
Reads: 6523

metaSearchForm

The metaSearchForm macro returns a search form suitable for searching metadata.

Syntax: metaDataMacros.searchForm(metaTypeList,closeForm:false,paired:false,showandor:false)

It takes four parameters (the last three are optional). The first parameter is a comma-delimited string of meta types and the other parameters are all booleans controlling the way the form is generated. If only one meta type is given, a hidden field is generated (why would you make the user choose from a list of one meta type to search?). If more than one meta type is given, a dropbox containing the meta types will be generated so that the user can choose which meta type to search.

If the first parameter is left blank, a dropbox containing all indexed, enabled meta types will be generated.

The second parameter is a boolean that tells it whether or not to close the form. You might not want it to close the form because you might want to add your own fields to the form.

Here's how you call it:

{metaDataMacros.metaSearchForm()}

Here's how you call it if you don't want it to close the form:

{metaDataMacros.metaSearchForm(closeForm:"false")}

Here's how you would call it if you wanted to give the user the option of searching the keywords and description meta types, and didn't want to close the form:

{metaDataMacros.metaSearchForm("keywords,description",closeForm:"false")}

You don't have to use the metaSearchForm macro to generate the form. You can look at the form that the macro produces and just copy the HTML. In fact, I'm expecting that most of the time that's what you'll want to do.

The target page for this macro (i.e., the one referenced by the action attribute in your form) must have the metaSearchResults macro on it. If you don't provide this, the metaSearchForm macro will do its best to direct you to the default search results page, which resides at yoursite/metasearch.

Remember the options for the query() Macro? You can include the options as hidden fields in your search form, and they will apply to the results.

For example, suppose you wanted to use the constrainBy parameter to allow the user to search the keywords and description fields, but only in the Gossip section of your site. You'd set up your form like this:

{metaDataMacros.metaSearchForm("keywords,description","false")}
<input type="hidden" name="constrainBy" value="section=gossip"></form>

You can also pass the option parameters directly to the metaSearchResults() macro. Options in hidden form fields override options passed as parameters. That way you can have a search page that returns results in a default format that you choose and yet have certain search pages that deviate from the default format.

If you'd like to have a search form that searches all metadata fields in your site, set the value of metatypetosearch to an empty string explicitly. For example:

<form method="get" name="metasearch" action="/metasearch/search">
<input type="hidden" name="mtts" value="">
<input type="text" name="searchterm">
<input type="submit" name="Search" value="Search">
</form>

Note that the action for the form may be different for your installation; use the metaSearchForm macro first and look at the HTML source to determine the action.

The field mtts stands for "metatype to search."

Full-text indexing

Here's a common scenario in full-text indexing, where you want to search the contents of the builtin meta types body and subject and collect hits from either one. First I entered the metaSearchForm macro and took note of the form it built, specifically the action parameter since this can change depending on how your Manila site is set up (specifically, whether it's on its own domain or not). Then I modified the form to look like this:

<form method="get" name="metasearch" action="http://zelotes.ent.iastate.edu/metadata/metasearch/search">
<input type='hidden' name='mtts' value='body,subject'>
<input type='hidden' name='searchtype' value='OR'>
<input type='hidden' name='sortdirection' value='reversesort'>
<input type="text" name="searchterm">
<input type="submit" name="Search" value="Search">
</form>

The first line is copied verbatim from the form that metaSearchForm built. The second line tells the metadata plugin to search in both the body and subject meta types. The third line tells it that the value I'm searching for may occur in the body meta type OR the subject meta type. The fourth line tells it to reverse the sort order of the results, thus putting the newest entries first. The last two lines produce the text entry box and the Search button. You can search this site by entering a value in the form below:

Paired Searching

Maybe you want to be able to search in multiple meta types at the same time, looking for pairs of values. For example, maybe you want to find all pages where the keywords meta type contains ketchup and the state meta type contains Virginia. I call this paired searching, since you're looking for meta type-meta value pairs.

The easiest way to do this is to just define the parameter paired to be true when you build the form:

{metaDataMacros.metaSearchForm("keywords,Section",paired:"true")}

keywords
section

Now you have to think about how the different fields relate to each other. Should the results be AND'd together between fields or OR'd? Of course, we give you both choices.

If multiple meta types are presented and the user enters information in just one of the fields, we assume that the user doesn't really mean "show me all the pages where this particular field contains this value AND all the other fields are blank." Most of the time what the user wants is the pages where that meta type-meta value pair is matched, regardless of what's in the other fields. So we ignore blank fields.

If two or more meta type-meta value pairs are present, we default to AND searching.

You can specify which kind of search you want by adding a hidden field to your form with the name searchtype and the value AND or OR.

<input type="hidden" name="searchtype" value="AND">

Or you can have the metaSearchForm macro generate fields for you to make choices about how the results from each expression will be added to the global results. To do this, use the showandor parameter:

{metaDataMacros.metaSearchForm("keywords,Section",paired:"true",showandor:"true")}

keywords
Section

Remember that this only applies to each meta type-meta value pair. The value of each field can contain a boolean expression, such as green or blue.

metaSearchResults

The metaSearchResults macro must be present on the page that is the target of the action attribute in your search form. If you're using the metaSearchForm macro to generate your form, it points to the default search results page that the Metadata Plugin provides.

You can put the search results on any page you want. You are not limited to the default search results page. But in order for this to work, two things must happen:

  • The metaSearchResults macro must exist on the target page
  • The action attribute of your search form must point to the target page (obviously).

The easiest way to do the latter is to generate your search form with the metaSearchForm macro, then copy the HTML that it generates, editing the action attribute.

Syntax:

metaDataMacros.metaSearchResults(sortBy:"score",
header:"<table cellpadding:'3'>",
footer:"</table>",
beforeItem:"<tr><td>",
afterItem:"</td><td>7/29/02; 10:46:05 AM</td></tr>",
maxItems:nil,
includeSelf:"includeself",
sortDirection:"",
constrainBy:"",
dateformat:"shortstring",
adrFormatter:@metaDataSuite.keyIndex.qry_formatResults)

See the documentation for the query macro for an explanation of each of these parameters.

If you use checkboxes to determine the value of a meta type, the metaSearchResult macro will do an OR search on the values. If you want to override this, define a hidden form field with the value and. Here's an example which would work on the first pair (that is, mtts1 and st1):

<input type='hidden' name='st1searchtype' value='and'>


This page last updated Monday, July 29, 2002 at 10:46:05 AM. (6523)