OrientDB Manual 1.7.8

Lucene Full Text Index

Full text index can be created using the OrientDB SQL syntax as written here. Specify the index engine to use the lucene full text capabilities.

Syntax:

CREATE INDEX <name> ON <class-name> (prop-names) FULLTEXT ENGINE LUCENE

Example

create index City.name on City (name) FULLTEXT ENGINE LUCENE

Index can also be created on n-properties:

Example:

create index City.name_description on City (name,description) FULLTEXT ENGINE LUCENE

This will create a basic lucene index on the properties specified. If the analyzer is not specified, the default will be the StandardAnalyzer. To use a different analyzer use the field analyzer in the metadata JSON object in the CREATE INDEX syntax.

Example:

create index City.name on City (name) FULLTEXT ENGINE LUCENE METADATA {"analyzer":"org.apache.lucene.analysis.en.EnglishAnalyzer"}

The Index can also be created with the Java Api. Example:

OSchema schema = databaseDocumentTx.getMetadata().getSchema();
OClass oClass = schema.createClass("Foo");
oClass.createProperty("name", OType.STRING);
oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name"});

How to query a Full Text Index

The full text index can be queried using the custom operator LUCENE using the Query Parser Syntax of Lucene. Example:

select * from V where name LUCENE "test*"

will look for test, tests or tester etc..

Working with multiple field

To query multiple fields use this special syntax:

select * from Class where [prop1,prop2] LUCENE "query"

If query is a plain string the engine will parse the query using MultiFieldQueryParser on each indexed field.

To execute a more complex query on each fields surround your query with () parenthesis, to address specific field.

Example:

select * from Class where [prop1,prop2] LUCENE "(prop1:foo AND props2:bar)"

With this syntax the engine parse the query using the QueryParser.