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
@@ -9,9 +9,9 @@ In addition to the standard FullText Index, which uses the SB-Tree index algorit
9
9
10
10
**Syntax**:
11
11
12
-
```sql
13
-
CREATE INDEX <name>ON<class-name> (prop-names) FULLTEXT ENGINE LUCENE
14
-
```
12
+
<pre>
13
+
orientdb> <codeclass="lang-sql userinput">CREATE INDEX <name> ON <class-name> (prop-names) FULLTEXT ENGINE LUCENE</code>
14
+
</pre>
15
15
16
16
The following SQL statement will create a FullText index on the property `name` for the class `City`, using the Lucene Engine.
17
17
@@ -26,68 +26,53 @@ orientdb> <code class="lang-sql userinput">CREATE INDEX City.name_description ON
26
26
FULLTEXT ENGINE LUCENE</code>
27
27
</pre>
28
28
29
+
The default analyzer used by OrientDB when a Lucene index is created id the [StandardAnalyzer](https://lucene.apache.org/core/6_3_0/core/org/apache/lucene/analysis/standard/StandardAnalyzer.html).
29
30
30
31
### Analyzer
31
32
32
-
This creates a basic FullText Index with the Lucene Engine on the specified properties. In the even that you do not specify the analyzer, OrientDB defaults to [StandardAnalyzer](http://lucene.apache.org/core/4_7_0/analyzers-common/org/apache/lucene/analysis/standard/StandardAnalyzer.html).
33
-
34
-
In addition to the StandardAnalyzer, you can also create indexes that use different analyzer, using the `METADATA` operator through [`CREATE INDEX`](SQL-Create-Index.md).
35
-
36
-
<pre>
37
-
orientdb> <codeclass="lang-sql userinput">CREATE INDEX City.name ON City(name) FULLTEXT ENGINE LUCENE METADATA
From version 2.1.16 it is possible to provide a set of stopwords to the analyzer to override the default set of the analyzer:
33
+
In addition to the StandardAnalyzer, full text indexes can be configured to use different analyzer by the `METADATA` operator through [`CREATE INDEX`](SQL-Create-Index.md).
44
34
35
+
Configure the index on `City.name` to use the `EnglishAnalyzer`:
45
36
<pre>
46
-
orientdb> <codeclass="lang-sql userinput">CREATE INDEX City.name ON City(name) FULLTEXT ENGINE LUCENE METADATA
You can query the Lucene FullText Index using the custom operator `LUCENE` with the [Query Parser Syntax](http://lucene.apache.org/core/5_4_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description) from the Lucene Engine.
183
+
You can query the Lucene FullText Index using the custom operator `LUCENE` with the [Query Parser Syntax](http://lucene.apache.org/core/6_3_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description) from the Lucene Engine.
195
184
196
185
<pre>
197
186
orientdb> <codeclass='lang-sql userinput'>SELECT FROM V WHERE name LUCENE "test*"</code>
198
187
</pre>
199
188
200
189
This query searches for `test`, `tests`, `tester`, and so on from the property `name` of the class `V`.
190
+
The query can use proximity operator _~_, the required (_+_) and prohibit (_-_) operators, phrase queries, regexp queries:
191
+
192
+
<pre>
193
+
orientdb> <codeclass='lang-sql userinput'>SELECT FROM Article WHERE content LUCENE "(+graph -rdbms) AND +cloud"</code>
194
+
</pre>
201
195
202
-
### Working with Multiple Fields
196
+
197
+
### Working with multiple fields
203
198
204
199
In addition to the standard Lucene query above, you can also query multiple fields. For example,
205
200
206
201
<pre>
207
202
orientdb> <codeclass="lang-sql userinput">SELECT FROM Class WHERE [prop1, prop2] LUCENE "query"</code>
208
203
</pre>
209
204
210
-
In this case, if the word `query` is a plain string, the engine parses the query using [MultiFieldQueryParser](http://lucene.apache.org/core/4_7_0/queryparser/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.html) on each indexed field.
205
+
In this case, if the word `query` is a plain string, the engine parses the query using [MultiFieldQueryParser](http://lucene.apache.org/core/6_3_0/queryparser/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.html) on each indexed field.
211
206
212
207
To execute a more complex query on each field, surround your query with parentheses, which causes the query to address specific fields.
213
208
214
209
<pre>
215
-
orientdb> <codeclass="lang-sql userinput">SELECT FROM CLass WHERE [prop1, prop2] LUCENE "(prop1:foo AND prop2:bar)"</code>
210
+
orientdb> <codeclass="lang-sql userinput">SELECT FROM Article WHERE [content, author] LUCENE "(content:graph AND author:john)"</code>
211
+
</pre>
212
+
213
+
Here, the engine parses the query using the [QueryParser](http://lucene.apache.org/core/6_3_0/queryparser/org/apache/lucene/queryparser/classic/QueryParser.html)
214
+
215
+
### Numeric and date range queries
216
+
217
+
If the index is defined over a numeric field (INTEGER, LONG, DOUBLE) or a date field (DATE, DATETIME), the engine supports [range queries](http://lucene.apache.org/core/6_3_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Range_Searches)
218
+
Suppose to have a `City` class witha multi-field Lucene index defined:
219
+
220
+
<pre>
221
+
orientdb> <codeclass="lang-sql userinput">
222
+
CREATE CLASS CITY EXTENDS V
223
+
CREATE PROPERTY CITY.name STRING
224
+
CREATE PROPERTY CITY.size INTEGER
225
+
CREATE INDEX City.name ON City(name,size) FULLTEXT ENGINE LUCENE
226
+
</code>
216
227
</pre>
217
228
218
-
Here, hte engine parses the query using the [QueryParser](http://lucene.apache.org/core/4_7_0/queryparser/org/apache/lucene/queryparser/classic/QueryParser.html)
229
+
Then query using ranges:
230
+
231
+
<pre>
232
+
orientdb> <codeclass="lang-sql userinput">
233
+
SELECT FROM City WHERE [name,size] LUCENE 'name:cas* AND size:[15000 TO 20000]'
234
+
</code>
235
+
</pre>
236
+
237
+
Ranges can be applied to DATE/DATETIME field as well. Create a Lucene index over a property:
238
+
239
+
<pre>
240
+
orientdb> <codeclass="lang-sql userinput">
241
+
CREATE CLASS Article EXTENDS V
242
+
CREATE PROPERTY Article.createdAt DATETIME
243
+
CREATE INDEX Article.createdAt ON Article(createdAt) FULLTEXT ENGINE LUCENE
244
+
</code>
245
+
</pre>
246
+
247
+
Then query to retrieve articles published only in a given time range:
248
+
249
+
<pre>
250
+
orientdb> <codeclass="lang-sql userinput">
251
+
SELECT FROM Article WHERE createdAt LUCENE '[201612221000 TO 201612221100]'</code>
252
+
</pre>
253
+
254
+
219
255
220
256
### Retrieve the Score
221
257
222
-
When the lucene index is used in a query, the results set carries a context variable for each record rappresenting the score.
258
+
When the lucene index is used in a query, the results set carries a context variable for each record representing the score.
223
259
To display the score add `$score` in projections.
224
260
225
261
```
@@ -228,7 +264,7 @@ SELECT *,$score FROM V WHERE name LUCENE "test*"
228
264
229
265
## Creating a Manual Lucene Index
230
266
231
-
Beginning with version 2.1, the Lucene Engine supports index creation without the need for a class.
267
+
The Lucene Engine supports index creation without the need for a class.
0 commit comments