use of org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class ElasticFullTextAsyncTest method defaultAnalyzer.
@Test
public void defaultAnalyzer() throws Exception {
IndexDefinitionBuilder builder = createIndex("analyzed_field");
builder.async("async");
builder.indexRule("nt:base").property("analyzed_field").analyzed().nodeScopeIndex();
setIndex(UUID.randomUUID().toString(), builder);
root.commit();
// add content
Tree test = root.getTree("/").addChild("test");
test.addChild("a").setProperty("analyzed_field", "sun.jpg");
root.commit();
assertEventually(() -> {
assertQuery("//*[jcr:contains(@analyzed_field, 'SUN.JPG')] ", XPATH, Collections.singletonList("/test/a"));
assertQuery("//*[jcr:contains(@analyzed_field, 'Sun')] ", XPATH, Collections.singletonList("/test/a"));
assertQuery("//*[jcr:contains(@analyzed_field, 'jpg')] ", XPATH, Collections.singletonList("/test/a"));
assertQuery("//*[jcr:contains(., 'SUN.jpg')] ", XPATH, Collections.singletonList("/test/a"));
assertQuery("//*[jcr:contains(., 'sun')] ", XPATH, Collections.singletonList("/test/a"));
assertQuery("//*[jcr:contains(., 'jpg')] ", XPATH, Collections.singletonList("/test/a"));
});
}
use of org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class ElasticContentTest method indexWithAnalyzedNodeScopeIndexProperty.
@Test
@Ignore("this test fails because of a bug with nodeScopeIndex (every node gets indexed in an empty doc)")
public void indexWithAnalyzedNodeScopeIndexProperty() throws Exception {
IndexDefinitionBuilder builder = createIndex("a").noAsync();
builder.indexRule("nt:base").property("a").analyzed().nodeScopeIndex();
Tree index = setIndex(UUID.randomUUID().toString(), builder);
root.commit();
assertThat(0L, equalTo(countDocuments(index)));
Tree content = root.getTree("/").addChild("content");
content.addChild("indexed").setProperty("a", "foo");
content.addChild("not-indexed").setProperty("b", "foo");
root.commit();
assertEventually(() -> assertThat(countDocuments(index), equalTo(1L)));
}
use of org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class ElasticContentTest method analyzedFieldWithLongValue.
@Test
public void analyzedFieldWithLongValue() throws Exception {
IndexDefinitionBuilder builder = createIndex("a").noAsync();
builder.indexRule("nt:base").property("a").analyzed();
Tree index = setIndex(UUID.randomUUID().toString(), builder);
root.commit();
assertTrue(exists(index));
assertThat(0L, equalTo(countDocuments(index)));
Tree content = root.getTree("/").addChild("content");
// max length is 32766
content.addChild("indexed1").setProperty("a", randomString(33409));
root.commit();
assertEventually(() -> assertThat(countDocuments(index), equalTo(1L)));
}
use of org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class ElasticDynamicBoostQueryTest method configureIndex.
private void configureIndex(boolean bothBoostFields) throws CommitFailedException {
NodeTypeRegistry.register(root, new ByteArrayInputStream(ASSET_NODE_TYPE.getBytes()), "test nodeType");
IndexDefinitionBuilder builder = createIndex(true, "dam:Asset", "title", "dynamicBoost");
IndexDefinitionBuilder.PropertyRule title = builder.indexRule("dam:Asset").property("title").analyzed().nodeScopeIndex();
title.getBuilderTree().setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
IndexDefinitionBuilder.IndexRule assetIndexRule = builder.indexRule("dam:Asset");
IndexDefinitionBuilder.PropertyRule dynamicBoostPropertyRule = assetIndexRule.property("dynamicBoost");
Tree dbTree = dynamicBoostPropertyRule.getBuilderTree();
dbTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
dbTree.setProperty("name", "jcr:content/metadata/.*");
dbTree.setProperty("isRegexp", true);
dbTree.setProperty("dynamicBoost", true);
if (bothBoostFields) {
IndexDefinitionBuilder.PropertyRule newDynamicBoostPropertyRule = assetIndexRule.property("dynamicBoostNew");
Tree anotherDbTree = newDynamicBoostPropertyRule.getBuilderTree();
anotherDbTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
anotherDbTree.setProperty("name", "jcr:content/metadataNew/.*");
anotherDbTree.setProperty("isRegexp", true);
anotherDbTree.setProperty("dynamicBoost", true);
}
setIndex("damAsset_" + UUID.randomUUID(), builder);
root.commit();
}
use of org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class ElasticFullTextAsyncTest method fulltextWithModifiedNodeScopeIndex.
@Test
public void fulltextWithModifiedNodeScopeIndex() throws Exception {
IndexDefinitionBuilder builder = createIndex("analyzed_field");
builder.async("async");
builder.indexRule("nt:base").property("analyzed_field").analyzed();
Tree index = setIndex(UUID.randomUUID().toString(), builder);
root.commit();
// add content
Tree test = root.getTree("/").addChild("test");
test.addChild("a").setProperty("analyzed_field", "sun.jpg");
root.commit();
assertEventually(() -> assertQuery("//*[jcr:contains(@analyzed_field, 'SUN.JPG')] ", XPATH, Collections.singletonList("/test/a")));
// add nodeScopeIndex at a later stage
index.getChild("indexRules").getChild("nt:base").getChild("properties").getChild("analyzed_field").setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true);
root.commit();
assertEventually(() -> assertQuery("//*[jcr:contains(., 'jpg')] ", XPATH, Collections.singletonList("/test/a")));
}
Aggregations