Search in sources :

Example 1 with MongoFreeTextIndexer

use of org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer in project incubator-rya by apache.

the class MongoFreeTextIndexerIT method testSearch.

@Test
public void testSearch() throws Exception {
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI subject = new URIImpl("foo:subj");
        final URI predicate = RDFS.LABEL;
        final Value object = vf.createLiteral("this is a new hat");
        final URI context = new URIImpl("foo:context");
        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement));
        f.flush();
        assertEquals(Sets.newHashSet(), getSet(f.queryText("asdf", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat new", EMPTY_CONSTRAINTS)));
    }
}
Also used : Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) URIImpl(org.openrdf.model.impl.URIImpl) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Example 2 with MongoFreeTextIndexer

use of org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer in project incubator-rya by apache.

the class MongoFreeTextIndexerIT method testContextSearch.

@Test
public void testContextSearch() throws Exception {
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI subject = new URIImpl("foo:subj");
        final URI predicate = new URIImpl(RDFS.COMMENT.toString());
        final Value object = vf.createLiteral("this is a new hat");
        final URI context = new URIImpl("foo:context");
        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement));
        f.flush();
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
        assertEquals(Sets.newHashSet(), getSet(f.queryText("hat", new StatementConstraints().setContext(vf.createURI("foo:context2")))));
    }
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) URIImpl(org.openrdf.model.impl.URIImpl) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Example 3 with MongoFreeTextIndexer

use of org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer in project incubator-rya by apache.

the class MongoFreeTextIndexerIT method testRestrictPredicatesSearch.

@Test
public void testRestrictPredicatesSearch() throws Exception {
    conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, "pred:1,pred:2");
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        // These should not be stored because they are not in the predicate list
        f.storeStatement(new RyaStatement(new RyaURI("foo:subj1"), new RyaURI(RDFS.LABEL.toString()), new RyaType("invalid")));
        f.storeStatement(new RyaStatement(new RyaURI("foo:subj2"), new RyaURI(RDFS.COMMENT.toString()), new RyaType("invalid")));
        final RyaURI pred1 = new RyaURI("pred:1");
        final RyaURI pred2 = new RyaURI("pred:2");
        // These should be stored because they are in the predicate list
        final RyaStatement s3 = new RyaStatement(new RyaURI("foo:subj3"), pred1, new RyaType("valid"));
        final RyaStatement s4 = new RyaStatement(new RyaURI("foo:subj4"), pred2, new RyaType("valid"));
        f.storeStatement(s3);
        f.storeStatement(s4);
        // This should not be stored because the object is not a literal
        f.storeStatement(new RyaStatement(new RyaURI("foo:subj5"), pred1, new RyaURI("in:validURI")));
        f.flush();
        assertEquals(Sets.newHashSet(), getSet(f.queryText("invalid", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(), getSet(f.queryText("in:validURI", EMPTY_CONSTRAINTS)));
        final Set<Statement> actual = getSet(f.queryText("valid", EMPTY_CONSTRAINTS));
        assertEquals(2, actual.size());
        assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s3)));
        assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s4)));
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Example 4 with MongoFreeTextIndexer

use of org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer in project incubator-rya by apache.

the class MongoFreeTextIndexerIT method testDelete.

@Test
public void testDelete() throws Exception {
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI subject1 = new URIImpl("foo:subj");
        final URI predicate1 = RDFS.LABEL;
        final Value object1 = vf.createLiteral("this is a new hat");
        final URI context1 = new URIImpl("foo:context");
        final Statement statement1 = vf.createStatement(subject1, predicate1, object1, context1);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement1));
        final URI subject2 = new URIImpl("foo:subject");
        final URI predicate2 = RDFS.LABEL;
        final Value object2 = vf.createLiteral("Do you like my new hat?");
        final URI context2 = new URIImpl("foo:context");
        final Statement statement2 = vf.createStatement(subject2, predicate2, object2, context2);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement2));
        f.flush();
        f.deleteStatement(RdfToRyaConversions.convertStatement(statement1));
        assertEquals(Sets.newHashSet(statement2), getSet(f.queryText("Do you like my new hat?", EMPTY_CONSTRAINTS)));
        // Check that "new" didn't get deleted from the term table after "this is a new hat"
        // was deleted since "new" is still in "Do you like my new hat?"
        assertEquals(Sets.newHashSet(statement2), getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
        f.deleteStatement(RdfToRyaConversions.convertStatement(statement2));
        assertEquals(Sets.newHashSet(), getSet(f.queryText("this is a new hat", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(), getSet(f.queryText("Do you like my new hat?", EMPTY_CONSTRAINTS)));
    }
}
Also used : Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) URIImpl(org.openrdf.model.impl.URIImpl) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)4 RyaURI (org.apache.rya.api.domain.RyaURI)4 MongoFreeTextIndexer (org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer)4 Test (org.junit.Test)4 Statement (org.openrdf.model.Statement)4 URI (org.openrdf.model.URI)3 Value (org.openrdf.model.Value)3 ValueFactory (org.openrdf.model.ValueFactory)3 URIImpl (org.openrdf.model.impl.URIImpl)3 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)3 RyaType (org.apache.rya.api.domain.RyaType)1 StatementConstraints (org.apache.rya.indexing.StatementConstraints)1