use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method refreshIndexDefinition.
@Test
public void refreshIndexDefinition() throws Exception {
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
idxb.indexRule("nt:base").property("foo").propertyIndex();
Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
idxb.build(idx);
Tree rootTree = root.getTree("/");
rootTree.addChild("a").setProperty("foo", "bar");
rootTree.addChild("b").setProperty("bar", "bar");
root.commit();
String query = "select * from [nt:base] where [foo] = 'bar'";
assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", asList("/a"));
Tree barProp = root.getTree("/oak:index/test1/indexRules/nt:base/properties").addChild("bar");
barProp.setProperty("name", "bar");
barProp.setProperty("propertyIndex", true);
root.commit();
query = "select * from [nt:base] where [bar] = 'bar'";
assertThat(explain(query), not(containsString("lucene:test1(/oak:index/test1)")));
//Instead of reindex just refresh the index definition so that new index definition gets picked up
root.getTree("/oak:index/test1").setProperty(LuceneIndexConstants.PROP_REFRESH_DEFN, true);
root.commit();
//Plan would reflect new defintion
assertThat(explain(query), containsString("lucene:test1(/oak:index/test1)"));
assertFalse(root.getTree("/oak:index/test1").hasProperty(LuceneIndexConstants.PROP_REFRESH_DEFN));
//However as reindex was not done query would result in empty set
assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", Collections.<String>emptyList());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class IndexNodeTest method createNRTIndex.
private static NodeState createNRTIndex() {
IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
idx.indexRule("nt:base").property("foo").propertyIndex();
idx.async("async", "sync");
return idx.build();
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class IndexCommandIT method createLuceneIndex.
private void createLuceneIndex(boolean asyncIndex) throws IOException, RepositoryException {
IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
if (!asyncIndex) {
idxBuilder.noAsync();
}
idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
Session session = fixture.getAdminSession();
Node fooIndex = getOrCreateByPath("/oak:index/fooIndex", "oak:QueryIndexDefinition", session);
idxBuilder.build(fooIndex);
session.save();
session.logout();
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class AggregateTest method propOneLevelNamedDirect.
@Test
public void propOneLevelNamedDirect() throws Exception {
IndexDefinitionBuilder builder = new IndexDefinitionBuilder();
builder.indexRule("nt:folder").property("jcr:content/a").ordered(PropertyType.TYPENAME_LONG).propertyIndex().property("jcr:content/b").ordered(PropertyType.TYPENAME_LONG).propertyIndex();
IndexDefinition defn = new IndexDefinition(root, builder.build(), "/foo");
Aggregate ag = defn.getApplicableIndexingRule("nt:folder").getAggregate();
NodeBuilder nb = newNode("nt:folder");
nb.child("jcr:content").setProperty("a", 1);
nb.child("jcr:content").setProperty("b", 1);
LuceneDocumentMaker maker = new LuceneDocumentMaker(defn, defn.getApplicableIndexingRule("nt:folder"), "/bar");
Document doc = maker.makeDocument(nb.getNodeState());
DefaultIndexWriterFactory writerFactory = new DefaultIndexWriterFactory(Mounts.defaultMountInfoProvider(), null, null);
LuceneIndexWriter writer = writerFactory.newInstance(defn, EMPTY_NODE.builder(), false);
writer.updateDocument("/bar", doc);
writer.close(100);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class HybridIndexClusterIT method prepareTestData.
@Override
protected void prepareTestData(Session s) throws RepositoryException {
nswb1.register(JournalPropertyService.class, new LuceneJournalPropertyService(1000), null);
nswb2.register(JournalPropertyService.class, new LuceneJournalPropertyService(1000), null);
IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
idx.indexRule("nt:base").property("foo").propertyIndex();
idx.async("async", "sync");
Node idxNode = JcrUtils.getOrCreateByPath("/oak:index/fooIndex", "oak:QueryIndexDefinition", s);
idx.build(idxNode);
Node a = JcrUtils.getOrCreateByPath("/a", "oak:Unstructured", s);
a.setProperty("foo", "x");
s.save();
runAsyncIndex(w1);
}
Aggregations