Search in sources :

Example 1 with IndexItems

use of com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems in project xp by enonic.

the class NodeStoreDocumentFactoryTest method references.

@Test
public void references() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addReference("myRef", new Reference(NodeId.from("otherNode")));
    final Node node = Node.create().id(NodeId.from("myNodeId")).parentPath(NodePath.ROOT).name("myNode").data(data).build();
    final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build().create();
    assertEquals(1, indexDocuments.size());
    final IndexDocument indexDocument = indexDocuments.iterator().next();
    final IndexItems indexItems = indexDocument.getIndexItems();
    final Collection<IndexValue> referenceValues = indexItems.get(NodeIndexPath.REFERENCE.getPath());
    assertEquals(1, referenceValues.size());
    final IndexValue next = referenceValues.iterator().next();
    assertTrue(next instanceof IndexValueString);
    final IndexValueString referenceValue = (IndexValueString) next;
    assertEquals("otherNode", referenceValue.getValue());
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IndexValueString(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValueString) IndexItems(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems) IndexValue(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValue) Test(org.junit.jupiter.api.Test)

Example 2 with IndexItems

use of com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems in project xp by enonic.

the class StoreDocumentXContentBuilderFactoryTest method testName.

@Test
public void testName() throws Exception {
    final IndexItems indexItems = IndexItems.create().add(IndexPath.from("myProperty"), ValueFactory.newString("myValue"), createDefaultDocument(IndexConfig.MINIMAL)).build();
    final IndexDocument indexDocument = IndexDocument.create().analyzer("myAnalyzer").id(NodeId.from("myNodeId").toString()).indexName("myIndex").indexTypeName("myIndexType").indexItems(indexItems).build();
    final XContentBuilder xContentBuilder = StoreDocumentXContentBuilderFactory.create(indexDocument);
    System.out.println(xContentBuilder.string());
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) IndexItems(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

IndexDocument (com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument)2 IndexItems (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems)2 Test (org.junit.jupiter.api.Test)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 Node (com.enonic.xp.node.Node)1 IndexValue (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValue)1 IndexValueString (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValueString)1 Reference (com.enonic.xp.util.Reference)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1