Creating Lucene index programmatically

Is it possible to create Lucene index for two fields using Java API?

oClass.createIndex("Person.firstName_lastName", "FULLTEXT", null, null, "LUCENE", new String[] { "firstName", "lastName"})

Caused by: com.orientechnologies.orient.core.index.OIndexException: Index with type FULLTEXT and algorithm LUCENE does not exist.

Hi @Toseek

are you running in embedded mode?

Did you include orientdb-lucene in your pom.xml?

Thanks

I use external OrientDB and that code works for one field. Like just for “firstName”. e.g.:

oClass.createIndex("Person.firstName", "FULLTEXT", null, null, "LUCENE", new String[] { "firstName"})

But looks like does not support two or more…

Of course I can avoid that using SQL: CREATE INDEX …
But question is still open for me.

Hi @Toseek

which version are you using?

OrientDB: 3.0.27 (Community)

Hi @Toseek

do you have a reproducer?

I’ve tried to reproduce this but i was unable to.

Here the test case that i did

OrientDB docDb = new OrientDB(....);
ODatabasePool pool = new ODatabasePool(docDb ...);

try (final ODatabaseSession session = pool.acquire()) {

        final OClass person = session.createClassIfNotExist("Person", OClass.VERTEX_CLASS_NAME);

        if (!person.existsProperty("firstName")) {
            person.createProperty("firstName", OType.STRING);
        }

        if (!person.existsProperty("lastName")) {
            person.createProperty("lastName", OType.STRING);
        }

        final OIndex<?> index = person.getClassIndex("Person.firstName_lastName");

        if (index == null) {
            person.createIndex("Person.firstName_lastName", "FULLTEXT", null, null, "LUCENE", new String[]{ "firstName", "lastName" });
        }
    }

As result:

com.orientechnologies.orient.core.index.OIndexException: Index with type FULLTEXT and algorithm LUCENE does not exist.

and here it’s remote:.. right?

Yes. Like:

new OrientDB("remote:localhost", "user", "pass", OrientDBConfig.defaultConfig())

Hi @Toseek

please include orientdb-lucene in your pom.xml and it will solve the issue

<dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-lucene</artifactId>
            <version>3.0.27</version>
</dependency>

and if you are deploying a single fat jar use this strategy

http://orientdb.com/docs/3.0.x/gettingstarted/Tutorial-Installation.html#building-a-single-executable-jar-with-orientdb

Let me know if this helps

Thanks

Thank you, it works with that dependency. Probably it would be good to update OrientDb documentation. Because it is not so clear why app should have such dependency to create index on remote instance.