The search application allows the user to enter a query and retrieve results from across the site. Results are produced by the application’s providers, and may determine results in whatever manner they choose.
Search providers may access an index for the entire site, or be application-specific. An institution may have a Google Search Appliance from which results are retrieved, or alternatively they may wish searches for ISBNs to go straight to a library catalogue page.
- form (optional, defaults to a built-in form): A Django form to use when searching
- query_expansion_file: A file to use for query expansion
- providers: A list of providers of search results
Sample:
Application('molly.apps.search', 'search', 'Search',
providers = [
Provider('molly.apps.search.providers.ApplicationSearchProvider'),
Provider('molly.apps.search.providers.GSASearchProvider',
search_url = 'http://googlesearch.oucs.ox.ac.uk/search',
domain = 'm.ox.ac.uk',
params = {
'client': 'oxford',
'frontend': 'mobile',
},
title_clean_re = r'm\.ox \| (.*)',
),
],
query_expansion_file = os.path.join(project_root, 'data', 'query_expansion.txt'),
display_to_user = False,
),
This search provider retrieves results from a GSA as XML. Results are augmented using get_metadata().
Options:
- search_url: The URL of the GSA
- domain: The domain of your deployment (used to restrict search results to)
- params (optional, defaults to nothing): Optional parameters to pass with the search request
- title_clean_re (optional, defaults to nothing): A regular expression to tidy up page titles when returned
params are added to the query string of the URL used when fetching request from the GSA. Further information about valid parameters can be found in the Google Seach Appliance documentation.
Where provided, title_clean_re is a regular expression containing a single group (i.e. paranthesised expression). If the title of a page as returned by the GSA matches the regular expression, it is substituted with the matched group. This can be used to remove common elements of titles.
Providers should extend the BaseSearchProvider interface:
BaseSearchProvider also provides the following utility methods you may find useful in your implementations:
Individual search results are represented as dictionaries where the following keys have particular meanings:
This application defines just one view:
Presents a single-field form to the user, and where a query has been submitted retrieves results from all configured search providers.
Results from multiple providers are presented in the order they were configured, i.e. the topmost configured provider’s results are given precedence. Where more than one provider returns the same result, metadata are combined (with the location given by its first occurance) and only one result is displayed.
This view renders to the search/index.html template, passing a SearchForm instance as form and (where a search has been performed) a list of results as results.