use of com.enonic.xp.index.IndexConfig in project xp by enonic.
the class IndexConfigFactoryTest method default_full.
@Test
public void default_full() throws Exception {
IndexConfigDocument config = create(" {" + "\"default\": {\n" + " \"decideByType\": true,\n" + " \"enabled\": true,\n" + " \"nGram\": false,\n" + " \"fulltext\": false,\n" + " \"includeInAllText\": false,\n" + " \"path\": true,\n" + " \"indexValueProcessors\": [],\n" + " \"languages\": []\n" + " }" + "}");
assertTrue(config instanceof PatternIndexConfigDocument);
final PatternIndexConfigDocument patternIndexConfigDocument = (PatternIndexConfigDocument) config;
final IndexConfig defaultConfig = patternIndexConfigDocument.getDefaultConfig();
assertEquals(true, defaultConfig.isDecideByType());
assertEquals(true, defaultConfig.isEnabled());
assertEquals(false, defaultConfig.isnGram());
assertEquals(false, defaultConfig.isFulltext());
assertEquals(false, defaultConfig.isIncludeInAllText());
assertEquals(true, defaultConfig.isPath());
}
use of com.enonic.xp.index.IndexConfig in project xp by enonic.
the class XmlNodeParser method parseIndexConfigs.
private IndexConfigDocument parseIndexConfigs(final DomElement root) {
final PatternIndexConfigDocument.Builder builder = PatternIndexConfigDocument.create();
final String analyzer = root.getChildValue("analyzer");
if (analyzer != null) {
builder.analyzer(analyzer);
}
final IndexConfig defaultConfig = parseIndexConfig(root.getChild("defaultConfig"));
if (defaultConfig != null) {
builder.defaultConfig(defaultConfig);
}
parsePathIndexConfigs(builder, root.getChild("pathIndexConfigs"));
parseAllTextIndexConfig(builder, root.getChild("allTextIndexConfig"));
return builder.build();
}
use of com.enonic.xp.index.IndexConfig in project xp by enonic.
the class XmlNodeParser method parseIndexConfig.
private IndexConfig parseIndexConfig(final DomElement root) {
final IndexConfig.Builder builder = IndexConfig.create().decideByType(root.getChildValueAs("decideByType", Boolean.class, false)).enabled(root.getChildValueAs("enabled", Boolean.class, false)).fulltext(root.getChildValueAs("fulltext", Boolean.class, false)).nGram(root.getChildValueAs("nGram", Boolean.class, false)).includeInAllText(root.getChildValueAs("includeInAllText", Boolean.class, false));
final DomElement indexValueProcessors = root.getChild("indexValueProcessors");
if (indexValueProcessors != null) {
for (DomElement indexValueProcessor : indexValueProcessors.getChildren()) {
builder.addIndexValueProcessor(IndexValueProcessors.get(indexValueProcessor.getValue()));
}
}
final DomElement languages = root.getChild("languages");
if (languages != null) {
for (DomElement language : languages.getChildren()) {
builder.addLanguage(language.getValue());
}
}
return builder.build();
}
use of com.enonic.xp.index.IndexConfig in project xp by enonic.
the class XmlNodeSerializerTest method doCreateNode.
private Node doCreateNode(final Instant instant) {
final PropertyTree propertyTree = new PropertyTree();
propertyTree.addString("myString", "myStringValue");
propertyTree.addString("myString", "myStringValue2");
propertyTree.addString("myEmptyString", "");
propertyTree.addBoolean("myBoolean", true);
propertyTree.addDouble("myDouble", 123.1);
propertyTree.addLong("myLong", 111L);
propertyTree.addXml("myXml", "<car><color>Arctic Grey<color><car>");
propertyTree.addString("myHtmlEncoded", "<p><a href=\"/naringsliv/tema/forsikrings-og-pensjonspakker\" data-event=\"{"event_category": "button", "event_action": "click","event_label": "se-php"}\">Se pakkene her</a></p>");
propertyTree.addGeoPoint("myGeoPoint", GeoPoint.from("8,4"));
// Date & Time
propertyTree.addInstant("myInstant", instant);
propertyTree.addLocalTime("myLocalTime", LocalTime.of(21, 42, 0));
propertyTree.addLocalDate("myLocalDate", LocalDate.of(2014, 11, 28));
propertyTree.addLocalDateTime("myLocalDateTime", LocalDateTime.of(2014, 11, 28, 21, 0, 0, 0));
// Links and ref
propertyTree.addReference("myRef", Reference.from("abcd"));
propertyTree.addLink("myLink", Link.from("/root/parent/child"));
// Binary refs
propertyTree.addBinaryReference("myBinaryRef1", BinaryReference.from("image.jpg"));
propertyTree.addBinaryReference("myBinaryRef2", BinaryReference.from("image2.jpg"));
// Property-set
final PropertySet mySubset = propertyTree.addSet("mySet");
mySubset.setString("myString", "myStringValue");
mySubset.setBoolean("myBoolean", true);
// Property-set in set
final PropertySet mySubSubset = mySubset.addSet("mySet");
mySubSubset.setString("myString", "myStringValue");
mySubSubset.setBoolean("myBoolean", true);
// Null values
propertyTree.addString("myString", null);
propertyTree.addBoolean("myBoolean", null);
propertyTree.addDouble("myDouble", null);
propertyTree.addLong("myLong", null);
propertyTree.addXml("myXml", null);
propertyTree.addGeoPoint("myGeoPoint", null);
propertyTree.addInstant("myInstant", null);
propertyTree.addLocalTime("myLocalTime", null);
propertyTree.addLocalDate("myLocalDate", null);
propertyTree.addLocalDateTime("myLocalDateTime", null);
propertyTree.addReference("myRef", null);
propertyTree.addLink("myLink", null);
propertyTree.addBinaryReference("myBinaryRef2", null);
propertyTree.addSet("nullSet", null);
// Index configs
final IndexConfig indexConfig = IndexConfig.create().enabled(true).fulltext(true).nGram(true).decideByType(false).includeInAllText(true).addIndexValueProcessor(IndexValueProcessors.HTML_STRIPPER).addLanguage("en").build();
final PatternIndexConfigDocument.Builder indexConfigDocumentBuilder = PatternIndexConfigDocument.create();
indexConfigDocumentBuilder.analyzer("no");
indexConfigDocumentBuilder.add("mydata", indexConfig);
indexConfigDocumentBuilder.addAllTextConfigLanguage("en");
// Permissions
final Permission createPermission = Permission.CREATE;
final Permission publishPermission = Permission.PUBLISH;
final PrincipalKey systemPrincipalKey = PrincipalKey.from("role:system.admin");
final PrincipalKey cmsPrincipalKey = PrincipalKey.from("role:cms.admin");
final AccessControlEntry systemAccessControlEntry = AccessControlEntry.create().principal(systemPrincipalKey).allowAll().build();
final AccessControlEntry cmsAccessControlEntry = AccessControlEntry.create().principal(cmsPrincipalKey).allow(createPermission).deny(publishPermission).build();
final AccessControlList accessControlList = AccessControlList.of(systemAccessControlEntry, cmsAccessControlEntry);
return Node.create().id(NodeId.from("abc")).name(NodeName.from("my-node-name")).parentPath(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).nodeType(NodeType.from("content")).data(propertyTree).indexConfigDocument(indexConfigDocumentBuilder.build()).permissions(accessControlList).inheritPermissions(false).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(BinaryReference.from("image.jpg"), "a")).add(new AttachedBinary(BinaryReference.from("image2.jpg"), "b")).build()).build();
}
use of com.enonic.xp.index.IndexConfig in project xp by enonic.
the class NodeStoreDocumentFactory method addNodeDataProperties.
private void addNodeDataProperties(final IndexItems.Builder builder) {
PropertyVisitor visitor = new PropertyVisitor() {
@Override
public void visit(final Property property) {
if (!isNullOrEmpty(property.getString())) {
final IndexConfig configForData = node.getIndexConfigDocument().getConfigForPath(property.getPath());
if (configForData == null) {
throw new RuntimeException("Missing index configuration for data " + property.getPath());
}
builder.add(property, node.getIndexConfigDocument());
addReferenceAggregation(property);
}
}
private void addReferenceAggregation(final Property property) {
if (property.getType().equals(ValueTypes.REFERENCE)) {
builder.add(NodeIndexPath.REFERENCE, property.getValue(), createDefaultDocument(IndexConfig.MINIMAL));
}
}
};
visitor.traverse(this.node.data());
}
Aggregations