I am having some difficulty with case-insensitive indexing and queries
using OrientDB 2.0 and the Java API.
The first, and most important issue, is that when I attempt to create a
case-insensitive index, queries still seem to behave in a case-sensitive
manner.
This is demonstrated in the test case below. The first query, where the
query value exactly matches the property value (including casing),
correctly returns the vertex. The second query, where the query value
matches the property value *except for casing*, returns an empty result set.
Second, how does one query by vertex type with the Java API? There were
some other posts in this group that suggested OrientQuery.labels() or
has("@class", MY_TYPE), but that fails, as demonstrated by the third query
in my test.
Thanks in advance for any help that you might be able to offer!
===
package com.mycompany.mind.test;
import com.orientechnologies.orient.core.collate.OCaseInsensitiveCollate;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.*;
import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
public
class OrientDBTest
{
private static final String DB_PATH="test.odb";
private static final String MY_INDEX="MyIndex";
private static final String MY_TYPE="MyType";
private static final String MY_PROPERTY="MyProperty";
private static final String MY_VALUE="MyValue";
@Test
public void caseInsensitiveIndex()
throws IOException
{
// Open database
OrientGraphFactory graphFactory=this.openDatabase();
// Create schema
this.buildSchema(graphFactory);
// Insert a vertex
OrientGraph graph=graphFactory.getTx();
Vertex vertex=graph.addVertex(OrientDBTest.MY_TYPE);
Assert.assertNotNull("Null vertex.", vertex);
vertex.setProperty(OrientDBTest.MY_PROPERTY, OrientDBTest.MY_VALUE);
graph.commit();
// Query with exact matching case
graph=graphFactory.getTx();
Iterable<Vertex> vertices=graph.query().has(OrientDBTest.MY_PROPERTY,
OrientDBTest.MY_VALUE).vertices();
Assert.assertNotNull("Null result from query.", vertices);
Assert.assertTrue("Empty result set from query.",
vertices.iterator().hasNext());
graph.shutdown();
/*
// Query with mismatched case
graph=graphFactory.getTx();
vertices=graph.query().has(OrientDBTest.MY_PROPERTY,
OrientDBTest.MY_VALUE.toLowerCase()).vertices();
Assert.assertNotNull("Null result from query.", vertices);
Assert.assertTrue("Empty result set from query.",
vertices.iterator().hasNext());
graph.shutdown();
*/
// Query by label
graph=graphFactory.getTx();
OrientGraphQuery oQuery= (OrientGraphQuery) graph.query();
vertices=oQuery.has(OrientDBTest.MY_PROPERTY,
OrientDBTest.MY_VALUE).has("@class", OrientDBTest.MY_TYPE).vertices();
Assert.assertNotNull("Null result from query.", vertices);
Assert.assertTrue("Empty result set from query.",
vertices.iterator().hasNext());
graph.shutdown();
// Close database
graphFactory.close();
}
private
OrientGraphFactory openDatabase()
throws IOException
{
File dbFile=new File(OrientDBTest.DB_PATH);
if (dbFile.exists())
{
FileUtils.deleteDirectory(dbFile);
}
return new OrientGraphFactory("plocal:"+ OrientDBTest.DB_PATH);
}
private
void buildSchema(OrientGraphFactory graphFactory)
{
OrientGraphNoTx graph=graphFactory.getNoTx();
OrientVertexType vertexType=graph.createVertexType(OrientDBTest.MY_TYPE);
OrientVertexType.OrientVertexProperty
property=vertexType.createProperty(OrientDBTest.MY_PROPERTY, OType.STRING);
property.setCollate(new OCaseInsensitiveCollate());
property.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
graph.shutdown();
}
}
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.