Hide last authors
Vincent Massol 1.1 1 #startfloatingbox()
2 *Contents*
3 #toc ("2" "3" "")
4 #endfloatingbox()
5
6 1 Lucene Search Query Help
7
8 #info("Need more informations ? see the [lucene website>http://lucene.apache.org/java/docs/queryparsersyntax.html]")
9
10 1.1 Terms
11
12 A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases.
13
14 * A Single Term is a single word such as "test" or "hello".
15 * A Phrase is a group of words surrounded by double quotes such as "hello dolly".
16
17 #info("Multiple terms can be combined together with Boolean operators to form a more complex query (see below).")
18
19 1.1 Wildcard Searches
20
21 Lucene supports single and multiple character wildcard searches within single terms (not within phrase queries).
22
23 * To perform a single character wildcard search use the "?" symbol.
24 * To perform a multiple character wildcard search use the "*" symbol.
25
26 The single character wildcard search looks for terms that match that with the single character replaced. For example, to search for "text" or "test" you can use the search:
27
28 {code}
29 te?t
30 {code}
31
32 Multiple character wildcard searches looks for 0 or more characters. For example, to search for test, tests or tester, you can use the search:
33
34 {code}
35 test*
36 {code}
37
38 You can also use the wildcard searches in the middle of a term.
39
40 {code}
41 te*t
42 {code}
43
44 #warning("Note: You cannot use a * or ? symbol as the first character of a search.")
45
46 1.1 Boolean Operators
47
48 Boolean operators allow terms to be combined through logic operators. Lucene supports AND, "+", OR, NOT and "-" as Boolean operators(Note: Boolean operators must be ALL CAPS).
49
50 The OR operator is the default conjunction operator. This means that if there is no Boolean operator between two terms, the OR operator is used. The OR operator links two terms and finds a matching document if either of the terms exist in a document. This is equivalent to a union using sets. The symbol || can be used in place of the word OR.
51
52 To search for documents that contain either "jakarta apache" or just "jakarta" use the query:
53
54 {code}
55 "jakarta apache" jakarta
56 {code}
57
58 or
59
60 {code}
61 "jakarta apache" OR jakarta
62 {code}
63
64 1.1.1 AND
65
66 The AND operator matches documents where both terms exist anywhere in the text of a single document. This is equivalent to an intersection using sets. The symbol && can be used in place of the word AND.
67
68 To search for documents that contain "jakarta apache" and "Apache Lucene" use the query:
69
70 {code}
71 "jakarta apache" AND "Apache Lucene"
72 {code}
73
74 1.1.1 +
75
76 The "+" or required operator requires that the term after the "+" symbol exist somewhere in a the field of a single document.
77
78 To search for documents that must contain "jakarta" and may contain "lucene" use the query:
79
80 {code}
81 +jakarta lucene
82 {code}
83
84 1.1.1 NOT
85
86 The NOT operator excludes documents that contain the term after NOT. This is equivalent to a difference using sets. The symbol ! can be used in place of the word NOT.
87
88 To search for documents that contain "jakarta apache" but not "Apache Lucene" use the query:
89
90 {code}
91 "jakarta apache" NOT "Apache Lucene"
92 {code}
93
94 Note: The NOT operator cannot be used with just one term. For example, the following search will return no results:
95
96 {code}
97 NOT "jakarta apache"
98 {code}
99
100 1.1.1 -
101
102 The "-" or prohibit operator excludes documents that contain the term after the "-" symbol.
103
104 To search for documents that contain "jakarta apache" but not "Apache Lucene" use the query:
105
106 {code}
107 "jakarta apache" -"Apache Lucene"
108 {code}
109
110 1.1.1 Grouping
111
112 Lucene supports using parentheses to group clauses to form sub queries. This can be very useful if you want to control the boolean logic for a query.
113
114 To search for either "jakarta" or "apache" and "website" use the query:
115
116 {code}
117 (jakarta OR apache) AND website
118 {code}
119
120 This eliminates any confusion and makes sure you that website must exist and either term jakarta or apache may exist.
121
122 1.1.1 Field Grouping
123
124 Lucene supports using parentheses to group multiple clauses to a single field.
125
126 To search for a title that contains both the word "return" and the phrase "pink panther" use the query:
127
128 {code}
129 title:(+return +"pink panther")
130 {code}
131
132 1.1 Escaping Special Characters
133
134 Lucene supports escaping special characters that are part of the query syntax. The current list special characters are
135
136 {code}
137 + - && || ! ( ) { } [ ] ^ " ~ * ? : \
138 {code}
139
140 To escape these character use the \ before the character. For example to search for (1+1):2 use the query:
141
142 {code}
143 \(1\+1\)\:2
144 {code}
145
146 1.1 Searchable fields
147
148 XWiki documents contain wiki content and meta-information, lucene indexes such information in fields.
149
150 1.1.1 wiki
151
152 In a wiki farm you can specify a wiki to search in with the "wiki:" prefix.
153
154 Look for the word "test" in the wiki "mywiki":
155 {code}
156 test AND wiki:mywiki
157 {code}
158
159 1.1.1 title
160
161 Look for documents with title "Welcome to your wiki":
162 {code}
163 title:"Welcome to your wiki"
164 {code}
165
166 1.1.1 name
167
168 Look for documents named "WebHome":
169 {code}
170 name:WebHome
171 {code}
172
173 1.1.1 lang
174
175 Look for "Voila" in french documents :
176 {code}
177 Voila AND lang:fr
178 {code}
179
180 1.1.1 type
181
182 Type of a document: "attachment", "wikipage" or "objects", used to control presentation of searchresults.
183
184 Look for "test" in attachments :
185 {code}
186 test AND type:attachment
187 {code}
188
189 1.1.1 filename
190
191 Look for attachments with a filename starting by "test":
192 {code}
193 filename:test*
194 {code}
195
196 1.1.1 object
197
198 The "object:" prefix allow to search for pages containing objects from a specific class.
199
200 Look for comments containing the word "test":
201 {code}
202 test AND object:XWiki.XWikiComments
203 {code}
204
205 1.1.1 author
206
207 Look for documents last modified by XWiki.Admin:
208 {code}
209 author:XWiki.Admin
210 {code}
211
212 1.1.1 date
213
214 Date format: yyyyMMddHHmm
215
216 Look for documents last modified on 2009/07/08:
217 {code}
218 date:20090708*
219 {code}
220
221 1.1.1 creator
222
223 Look for documents created by XWiki.Admin:
224 {code}
225 creator:XWiki.Admin
226 {code}
227
228 1.1.1 creationdate
229
230 Date format: yyyyMMddHHmm
231
232 Look for documents created on 2009/07/08:
233 {code}
234 creationdate:20090708*
235 {code}
236
237

Get Connected