Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Full Text Index

SDIPro edited this page Jul 19, 2015 · 10 revisions

Lucene Full Text Index

A full text index can be created using the OrientDB SQL syntax as written here. You must specify the index engine to use to enable 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

An 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 the 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 field surround your query with () parentheses, to use specific fields.

Example:

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

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

Create a manual Lucene Index

Starting from 2.1, the plugin supports index creation without the need of a class

To create a manual index use this syntax

CREATE INDEX <name> FULLTEXT ENGINE LUCENE  [<key-type>] [METADATA {<metadata>}]

Example

create index Manual FULLTEXT ENGINE LUCENE STRING,STRING

You can then insert values in the index as follows:

insert into index:manual (key,rid) values(['Enrico','Rome'],#5:0)

and query the index:

select from index:manual where key LUCENE 'Enrico'