Wiki source code of Lucene Search Query Help

Last modified by Djebloun Sidali on 2014/02/23 15:55

Hide last authors
Eduard Moraru 7.1 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
Vincent Massol 2.1 4
5 {{info}}
Vincent Massol 6.2 6 Need more informations? See the [[lucene website>>http://lucene.apache.org/java/docs/index.html]]. More specifically look for the "Query Syntax" documentation entry for the Lucene Core version matching the version used in your XWiki installation (to find the version used by XWiki look for ##lucene-core-x.y.z.jar## in the XWiki's ##/WEB-INF/lib## folder. For example for XWiki Enterprise 2.6 uses Lucene Core 2.9.3 which means the Lucene Query Syntax can be found [[here>>http://lucene.apache.org/java/2_9_3/queryparsersyntax.html]].
Vincent Massol 2.1 7 {{/info}}
Vincent Massol 1.1 8
Vincent Massol 3.1 9 = Terms =
Vincent Massol 1.1 10
11 A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases.
12
13 * A Single Term is a single word such as "test" or "hello".
14 * A Phrase is a group of words surrounded by double quotes such as "hello dolly".
15
Vincent Massol 2.1 16 {{info}}
17 Multiple terms can be combined together with Boolean operators to form a more complex query (see below).
18 {{/info}}
Vincent Massol 1.1 19
Vincent Massol 3.1 20 = Wildcard Searches =
Vincent Massol 1.1 21
22 Lucene supports single and multiple character wildcard searches within single terms (not within phrase queries).
23
24 * To perform a single character wildcard search use the "?" symbol.
Vincent Massol 2.1 25 * To perform a multiple character wildcard search use the "*" symbol.
Vincent Massol 1.1 26
27 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:
28
Vincent Massol 2.1 29 {{code}}
Vincent Massol 1.1 30 te?t
Vincent Massol 2.1 31 {{/code}}
Vincent Massol 1.1 32
33 Multiple character wildcard searches looks for 0 or more characters. For example, to search for test, tests or tester, you can use the search:
34
Vincent Massol 2.1 35 {{code}}
Vincent Massol 1.1 36 test*
Vincent Massol 2.1 37 {{/code}}
Vincent Massol 1.1 38
39 You can also use the wildcard searches in the middle of a term.
40
Vincent Massol 2.1 41 {{code}}
Vincent Massol 1.1 42 te*t
Vincent Massol 2.1 43 {{/code}}
Vincent Massol 1.1 44
Vincent Massol 2.1 45 {{warning}}
46 Note: You cannot use a * or ? symbol as the first character of a search.
47 {{/warning}}
Vincent Massol 1.1 48
Vincent Massol 3.1 49 = Boolean Operators =
Vincent Massol 1.1 50
Vincent Massol 2.1 51 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).
Vincent Massol 1.1 52
53 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.
54
55 To search for documents that contain either "jakarta apache" or just "jakarta" use the query:
56
Vincent Massol 2.1 57 {{code}}
Vincent Massol 1.1 58 "jakarta apache" jakarta
Vincent Massol 2.1 59 {{/code}}
Vincent Massol 1.1 60
61 or
62
Vincent Massol 2.1 63 {{code}}
Vincent Massol 1.1 64 "jakarta apache" OR jakarta
Vincent Massol 2.1 65 {{/code}}
Vincent Massol 1.1 66
Vincent Massol 3.1 67 == AND ==
Vincent Massol 1.1 68
69 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.
70
71 To search for documents that contain "jakarta apache" and "Apache Lucene" use the query:
72
Vincent Massol 2.1 73 {{code}}
Vincent Massol 1.1 74 "jakarta apache" AND "Apache Lucene"
Vincent Massol 2.1 75 {{/code}}
Vincent Massol 1.1 76
Vincent Massol 3.1 77 == + ==
Vincent Massol 1.1 78
79 The "+" or required operator requires that the term after the "+" symbol exist somewhere in a the field of a single document.
80
81 To search for documents that must contain "jakarta" and may contain "lucene" use the query:
82
Vincent Massol 2.1 83 {{code}}
Vincent Massol 1.1 84 +jakarta lucene
Vincent Massol 2.1 85 {{/code}}
Vincent Massol 1.1 86
Vincent Massol 3.1 87 == NOT ==
Vincent Massol 1.1 88
89 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.
90
91 To search for documents that contain "jakarta apache" but not "Apache Lucene" use the query:
92
Vincent Massol 2.1 93 {{code}}
Vincent Massol 1.1 94 "jakarta apache" NOT "Apache Lucene"
Vincent Massol 2.1 95 {{/code}}
Vincent Massol 1.1 96
97 Note: The NOT operator cannot be used with just one term. For example, the following search will return no results:
98
Vincent Massol 2.1 99 {{code}}
Vincent Massol 1.1 100 NOT "jakarta apache"
Vincent Massol 2.1 101 {{/code}}
Vincent Massol 1.1 102
Vincent Massol 3.1 103 == - ==
Vincent Massol 1.1 104
Vincent Massol 2.1 105 The "-" or prohibit operator excludes documents that contain the term after the "-" symbol.
Vincent Massol 1.1 106
107 To search for documents that contain "jakarta apache" but not "Apache Lucene" use the query:
108
Vincent Massol 2.1 109 {{code}}
Sergiu Dumitriu 10.1 110 "jakarta apache" -"Apache Lucene"
Vincent Massol 2.1 111 {{/code}}
Vincent Massol 1.1 112
Vincent Massol 3.1 113 == Grouping ==
Vincent Massol 1.1 114
115 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.
116
117 To search for either "jakarta" or "apache" and "website" use the query:
118
Vincent Massol 2.1 119 {{code}}
Vincent Massol 1.1 120 (jakarta OR apache) AND website
Vincent Massol 2.1 121 {{/code}}
Vincent Massol 1.1 122
123 This eliminates any confusion and makes sure you that website must exist and either term jakarta or apache may exist.
124
Vincent Massol 3.1 125 == Field Grouping ==
Vincent Massol 1.1 126
127 Lucene supports using parentheses to group multiple clauses to a single field.
128
129 To search for a title that contains both the word "return" and the phrase "pink panther" use the query:
130
Vincent Massol 2.1 131 {{code}}
Vincent Massol 1.1 132 title:(+return +"pink panther")
Vincent Massol 2.1 133 {{/code}}
Vincent Massol 1.1 134
Vincent Massol 3.1 135 = Escaping Special Characters =
Vincent Massol 1.1 136
137 Lucene supports escaping special characters that are part of the query syntax. The current list special characters are
138
Vincent Massol 2.1 139 {{code}}
Vincent Massol 1.1 140 + - && || ! ( ) { } [ ] ^ " ~ * ? : \
Vincent Massol 2.1 141 {{/code}}
Vincent Massol 1.1 142
Eduard Moraru 7.1 143 To escape these character use "\" (backslash) before the character. For example to search for (1+1):2 use the query:
Vincent Massol 1.1 144
Vincent Massol 2.1 145 {{code}}
Vincent Massol 1.1 146 \(1\+1\)\:2
Vincent Massol 2.1 147 {{/code}}
Vincent Massol 1.1 148
Vincent Massol 3.1 149 = Searchable fields =
Vincent Massol 1.1 150
Eduard Moraru 8.1 151 XWiki documents contain wiki content and meta-information. Lucene indexes such information in fields.
Vincent Massol 1.1 152
Vincent Massol 3.1 153 == wiki ==
Vincent Massol 1.1 154
155 In a wiki farm you can specify a wiki to search in with the "wiki:" prefix.
156
157 Look for the word "test" in the wiki "mywiki":
158
Vincent Massol 2.1 159 {{code}}
160 test AND wiki:mywiki
161 {{/code}}
Vincent Massol 1.1 162
Vincent Massol 3.1 163 == title ==
Vincent Massol 2.1 164
Vincent Massol 1.1 165 Look for documents with title "Welcome to your wiki":
Vincent Massol 2.1 166
167 {{code}}
Vincent Massol 1.1 168 title:"Welcome to your wiki"
Vincent Massol 2.1 169 {{/code}}
Vincent Massol 1.1 170
Vincent Massol 3.1 171 == name ==
Vincent Massol 1.1 172
173 Look for documents named "WebHome":
Vincent Massol 2.1 174
175 {{code}}
Vincent Massol 1.1 176 name:WebHome
Vincent Massol 2.1 177 {{/code}}
Vincent Massol 1.1 178
Djebloun Sidali 16.2 179 == space ==
180
Djebloun Sidali 16.3 181 Name of the space the document belongs to
Djebloun Sidali 16.2 182
183 Look for the word "test" in the space "Blog":
184
185 {{code}}
Djebloun Sidali 16.4 186 test AND space:Blog
Djebloun Sidali 16.2 187 {{/code}}
188
189 == exactspace ==
190
Djebloun Sidali 16.7 191 exactspace is untokenized for exact matches.
Djebloun Sidali 16.2 192
Djebloun Sidali 16.6 193 If we have two spaces, "Main" and "The Main Space", trying to get results from the "Main" space will also include results from the "The Main Space" space. The "exactspace" field will allow to have exact matches on the space name.
Djebloun Sidali 16.5 194
Djebloun Sidali 16.2 195 Look for the word "test" in the space "Blog":
196
197 {{code}}
198 test AND exactspace:Blog
199 {{/code}}
200
Vincent Massol 3.1 201 == lang ==
Vincent Massol 1.1 202
203 Look for "Voila" in french documents :
Vincent Massol 2.1 204
205 {{code}}
Vincent Massol 1.1 206 Voila AND lang:fr
Vincent Massol 2.1 207 {{/code}}
Vincent Massol 1.1 208
Vincent Massol 3.1 209 == type ==
Vincent Massol 1.1 210
211 Type of a document: "attachment", "wikipage" or "objects", used to control presentation of searchresults.
212
Xavier Richard 12.1 213 Look for "test" in attachments:
Vincent Massol 2.1 214
215 {{code}}
Vincent Massol 1.1 216 test AND type:attachment
Vincent Massol 2.1 217 {{/code}}
Vincent Massol 1.1 218
Xavier Richard 13.1 219 Look for "test" in pages but exclude attachments containing the word test:
Xavier Richard 12.1 220
221 {{code}}
222 test AND -type:attachment
223 {{/code}}
224
Vincent Massol 3.1 225 == filename ==
Vincent Massol 1.1 226
Sergiu Dumitriu 10.1 227 Look for attachments with a filename starting with "test":
Vincent Massol 2.1 228
229 {{code}}
Vincent Massol 1.1 230 filename:test*
Vincent Massol 2.1 231 {{/code}}
Vincent Massol 1.1 232
Sergiu Dumitriu 11.1 233 == mimetype ==
234
235 Look for attachments with a certain MIME type. Examples:
236
237 * Search for PDFs only: {{code language="none"}}mimetype:application/pdf{{/code}}
238 * Search for all attachments except images: {{code language="none"}}type:attachment -mimetype:image/*{{/code}}
239
Vincent Massol 3.1 240 == object ==
Vincent Massol 1.1 241
242 The "object:" prefix allow to search for pages containing objects from a specific class.
243
244 Look for comments containing the word "test":
Vincent Massol 2.1 245
246 {{code}}
Vincent Massol 1.1 247 test AND object:XWiki.XWikiComments
Vincent Massol 2.1 248 {{/code}}
Vincent Massol 1.1 249
Vincent Massol 3.1 250 == author ==
Vincent Massol 1.1 251
252 Look for documents last modified by XWiki.Admin:
Vincent Massol 2.1 253
254 {{code}}
Vincent Massol 1.1 255 author:XWiki.Admin
Vincent Massol 2.1 256 {{/code}}
Vincent Massol 1.1 257
Vincent Massol 3.1 258 == date ==
Vincent Massol 1.1 259
260 Date format: yyyyMMddHHmm
261
262 Look for documents last modified on 2009/07/08:
Vincent Massol 2.1 263
264 {{code}}
Vincent Massol 1.1 265 date:20090708*
Vincent Massol 2.1 266 {{/code}}
Vincent Massol 1.1 267
Vincent Massol 3.1 268 == creator ==
Vincent Massol 1.1 269
270 Look for documents created by XWiki.Admin:
Vincent Massol 2.1 271
272 {{code}}
Vincent Massol 1.1 273 creator:XWiki.Admin
Vincent Massol 2.1 274 {{/code}}
Vincent Massol 1.1 275
Vincent Massol 3.1 276 == creationdate ==
Vincent Massol 1.1 277
278 Date format: yyyyMMddHHmm
279
280 Look for documents created on 2009/07/08:
Vincent Massol 2.1 281
282 {{code}}
Vincent Massol 1.1 283 creationdate:20090708*
Vincent Massol 2.1 284 {{/code}}
Eduard Moraru 8.1 285
286 == Searching for fields in XWiki objects ==
287
288 Beside Lucene's XWiki specific index fields, querying for documents based on the property values of contained XWiki objects is also possible.
289
Eduard Moraru 9.1 290 Look for the profile page of a user who's first name is 'Administrator'.
291
Eduard Moraru 8.1 292 {{code}}
293 XWiki.XWikiUsers.first_name:'Administrator'
294 {{/code}}
Sergiu Dumitriu 10.1 295
296 Look for all users or groups, except the group template:
297
298 {{code}}
299 +(object:XWiki.XWikiUsers object:XWiki.XWikiGroups) -name:XWikiGroupTemplate
300 {{/code}}
Mircea Staicu 13.2 301
302 Looking for documents by a value which is stored in a DatabaseTree property in an object. As a mention, the searched value can be wrapped inside round paranthesis or single / double quotes
303
304 {{code}}
305 +Space.Class.databaseTreeProperty:(searchedValue)
306 {{/code}}
Mircea Staicu 14.2 307
308 If you would like to add a logical disjunction to the above use case, you can do it like this:
309
310 {{code}}
311 +Space.Class.databaseTreeProperty:(searchedValue OR anotherSearchedValue)
312 {{/code}}
313
314 This will return all documents which contain in the object's property value either searchedValue or anotherSearchedValue

Get Connected