You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# NOTE: Using multi line matching here will not help either if the pattern itself is in the middle broken/spaned to multiple lines, so using whitespace replacements now inside the patter to handle this, see above!
Copy file name to clipboardExpand all lines: doc/site-internal/lunr_search_help.md
+12-12
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,15 @@ Please visit the original Lunar site for more information.
13
13
The simplest way to start is to pass the text on which you want to search into the search field:
14
14
15
15
```javascript
16
-
'foo'
16
+
foo
17
17
```
18
18
19
19
The above will return details of all documents that match the term “foo”. Although it looks like a string, the search method parses the string into a search query. This supports special syntax for defining more complex queries.
20
20
21
21
Searches for multiple terms are also supported. If a document matches at least one of the search terms, it will show in the results. The search terms are combined with OR.
22
22
23
23
```javascript
24
-
'foo bar'
24
+
foo bar
25
25
```
26
26
27
27
The above example will match documents that contain either “foo” or “bar”. Documents that contain both will score more highly and will be returned first.
@@ -37,21 +37,21 @@ For example, let’s say you’re indexing a collection of documents about JavaS
37
37
Lunr 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 documents with words beginning with “foo”:
38
38
39
39
```javascript
40
-
'foo*'
40
+
foo*
41
41
```
42
42
43
43
This will match all documents that end with ‘oo’:
44
44
45
45
```javascript
46
-
'*oo'
46
+
*oo
47
47
```
48
48
49
49
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.
50
50
51
51
Finally, a wildcard can be in the middle of a term. The following will match any documents that contain a term that begins with “f” and ends in “o”:
52
52
53
53
```javascript
54
-
'f*o'
54
+
f*o
55
55
```
56
56
57
57
It is also worth noting that, when a search term contains a wildcard, no stemming is performed on the search term.
@@ -65,51 +65,51 @@ To indicate that a term must be present in matching documents the term should be
65
65
The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”:
66
66
67
67
```javascript
68
-
'+foo bar -baz'
68
+
+foo bar -baz
69
69
```
70
70
71
71
To simulate a logical AND search of “foo AND bar” mark both terms as required:
72
72
73
73
```javascript
74
-
'+foo +bar'
74
+
+foo +bar
75
75
```
76
76
77
77
## Fields
78
78
79
79
By default, Lunr will search all fields in a document for the query term, and it is possible to restrict a term to a specific field. The following example searches for the term “foo” in the field title:
80
80
81
81
```javascript
82
-
'title:foo'
82
+
title:foo
83
83
```
84
84
85
85
The search term is prefixed with the name of the field, followed by a colon (:). The field must be one of the fields defined when building the index. Unrecognised fields will lead to an error.
86
86
87
87
Field-based searches can be combined with all other term modifiers and wildcards, as well as other terms. For example, to search for words beginning with “foo” in the title or with “bar” in any field the following query can be used:
88
88
89
89
```javascript
90
-
'title:foo* bar'
90
+
title:foo* bar
91
91
```
92
92
93
93
## Boosts
94
94
95
95
In multi-term searches, a single term may be important than others. For these cases Lunr supports term level boosts. Any document that matches a boosted term will get a higher relevance score, and appear higher up in the results. A boost is applied by appending a caret (^) and then a positive integer to a term.
96
96
97
97
```javascript
98
-
'foo^10 bar'
98
+
foo^10 bar
99
99
```
100
100
101
101
The above example weights the term “foo” 10 times higher than the term “bar”. The boost value can be any positive integer, and different terms can have different boosts:
102
102
103
103
```javascript
104
-
'foo^10 bar^5 baz'
104
+
foo^10 bar^5 baz
105
105
```
106
106
107
107
## Fuzzy Matches
108
108
109
109
Lunr supports fuzzy matching search terms in documents, 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 documents that have a word within 1 edit distance of “foo”:
110
110
111
111
```javascript
112
-
'foo~1'
112
+
foo~1
113
113
```
114
114
115
115
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.
0 commit comments