eulcommon.searchutil – Utilities for searching¶
This module contains utilities for searching.
- eulcommon.searchutil.search_terms(q)¶
Takes a search string and parses it into a list of keywords and phrases.
- eulcommon.searchutil.pages_to_show(paginator, page, page_labels={})¶
Generate a dictionary of pages to show around the current page. Show 3 numbers on either side of the specified page, or more if close to end or beginning of available pages.
Parameters: - paginator – django Paginator, populated with objects
- page – number of the current page
- page_labels – optional dictionary of page labels, keyed on page number
Return type: dictionary; keys are page numbers, values are page labels
- eulcommon.searchutil.parse_search_terms(q)¶
Parse a string of search terms into keywords, phrases, and field/value pairs. Use quotes (” “) to designate phrases and field:value or field:”term term” to designated field value pairs. Returns a list of tuples where the first value is the field, or None for a word or phrase, second value is the keyword or phrase. Incomplete field value pairs will return a tuple with None for the value. For example:
parse_search_terms('grahame "frog and toad" title:willows')
Would result in:
[(None,'grahame'), (None, 'frog and toad'), ('title', 'willows')]
Django template tag to display pagination links for a paginated list of items.
- Expects the following variables:
- the current Page of a Paginator object
- a dictionary of the pages to be displayed, in the format generated by eulcommon.searchutil.pages_to_show()
- optional url params to include in pagination link (e.g., search terms when paginating search results)
- optional first page label (only used when first page is not in list of pages to be shown)
- optional last page label (only used when last page is not in list of pages to be shown)
- optional url to use for page links (only needed when the url is different from the current one)
Example use:
{% load search_utils %} {% pagination_links paged_items show_pages %}