Search Syntax

We use lunr.js as the search engine. The following description of the search syntax is adapted from the searching guide for developers.

The simplest way to search is to just type the word you are looking for:

hanging

The above will return all trails that match the term “hanging”.

Searches for multiple terms are also supported. If a trail matches at least one of the search terms, it will show in the results. The search terms are combined with OR.

hanging killed

The above example will match trails that contain either “hanging” or “killed”. Trails that contain both will score more highly and will be returned first.

Wildcards

Search supports wildcards when performing searches. A wildcard is represented as an asterisk (*) and can appear anywhere in a search term. For example, the following will match all trails with words beginning with “hang”:

hang*

This will match all trails that end with ‘ing’:

*ing

Leading wildcards, as in the above example, should be used sparingly. They can have a negative impact on the performance of a search, especially in large indexes.

Finally, a wildcard can be in the middle of a term. The following will match any trails that contain a term that begins with “k” and ends in “d”:

k*d

Fuzzy Matches

Search supports fuzzy matching search terms in trails, which can be helpful if the spelling of a term is unclear, or to increase the number of search results that are returned. The amount of fuzziness to allow when searching can also be controlled. Fuzziness is applied by appending a tilde (~) and then a positive integer to a term. The following search matches all trails that have a word within 1 edit distance of “foo”:

foo~1

An edit distance of 1 allows words to match if either adding, removing, changing or transposing a character in the word would lead to a match. For example “boo” requires a single edit (replacing “f” with “b”) and would match, but “boot” would not as it also requires an additional “t” at the end.

Term Presence

By default, search combines multiple terms together in a search with a logical OR. That is, a search for “foo bar” will match trails that contain “foo” or contain “bar” or contain both. This behaviour is controllable at the term level, i.e. the presence of each term in matching trails can be specified. By default each term is optional in a matching trail, though a trail must have at least one matching term. It is possible to specify that a term must be present in matching trails, or that it must be absent in matching trails.

To indicate that a term must be present in matching trails the term should be prefixed with a plus (+) and to indicate that a term must be absent the term should be prefixed with a minus (-). Without either prefix the term’s presence in matching trails is optional.

The below example searches for trails that must contain “foo”, might contain “bar” and must not contain “baz”:

+foo bar -baz

To simulate a logical AND search of “foo AND bar” mark both terms as required:

+foo +bar