Search in sources :

Example 1 with IndexConfig

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());
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) PathIndexConfig(com.enonic.xp.index.PathIndexConfig) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) Test(org.junit.jupiter.api.Test)

Example 2 with IndexConfig

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();
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) PathIndexConfig(com.enonic.xp.index.PathIndexConfig) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument)

Example 3 with IndexConfig

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();
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) PathIndexConfig(com.enonic.xp.index.PathIndexConfig) DomElement(com.enonic.xp.xml.DomElement)

Example 4 with IndexConfig

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=\"{&quot;event_category&quot;: &quot;button&quot;, &quot;event_action&quot;: &quot;click&quot;,&quot;event_label&quot;: &quot;se-php&quot;}\">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();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexConfig(com.enonic.xp.index.IndexConfig) PropertyTree(com.enonic.xp.data.PropertyTree) Permission(com.enonic.xp.security.acl.Permission) PropertySet(com.enonic.xp.data.PropertySet) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) PrincipalKey(com.enonic.xp.security.PrincipalKey) AttachedBinary(com.enonic.xp.node.AttachedBinary)

Example 5 with IndexConfig

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());
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) Property(com.enonic.xp.data.Property) PropertyVisitor(com.enonic.xp.data.PropertyVisitor)

Aggregations

IndexConfig (com.enonic.xp.index.IndexConfig)11 PathIndexConfig (com.enonic.xp.index.PathIndexConfig)3 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)3 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 IndexValueProcessor (com.enonic.xp.index.IndexValueProcessor)2 AttachedBinary (com.enonic.xp.node.AttachedBinary)2 AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Test (org.junit.jupiter.api.Test)2 Property (com.enonic.xp.data.Property)1 PropertyVisitor (com.enonic.xp.data.PropertyVisitor)1 Value (com.enonic.xp.data.Value)1 IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 Permission (com.enonic.xp.security.acl.Permission)1 DomElement (com.enonic.xp.xml.DomElement)1 ArrayList (java.util.ArrayList)1