private IndexDocument getIndexDocumentOfType( final Collection<IndexDocument> indexDocuments, final IndexType indexType) { for (IndexDocument indexDocument : indexDocuments) { if (indexType.getName().equals(indexDocument.getIndexTypeName())) { return indexDocument; } } return null; }
@Test public void node_index_document_meta_data_values() throws Exception { final String myAnalyzerName = "myAnalyzer"; Instant modifiedDateTime = LocalDateTime.of(2013, 1, 2, 3, 4, 5).toInstant(ZoneOffset.UTC); Node node = Node.newNode() .id(EntityId.from("myId")) .parent(NodePath.ROOT) .name(NodeName.from("my-name")) .createdTime(Instant.now()) .creator(UserKey.from("test:creator")) .modifier(UserKey.from("test:modifier").asUser()) .modifiedTime(modifiedDateTime) .entityIndexConfig( EntityPropertyIndexConfig.newEntityIndexConfig().analyzer(myAnalyzerName).build()) .build(); final Collection<IndexDocument> indexDocuments = NodeIndexDocumentFactory.create(node, TEST_WORKSPACE); final IndexDocument indexDocument = getIndexDocumentOfType(indexDocuments, IndexType.NODE); assertEquals(myAnalyzerName, indexDocument.getAnalyzer()); assertEquals(TEST_WORKSPACE.getSearchIndexName(), indexDocument.getIndexName()); assertEquals(IndexType.NODE.getName(), indexDocument.getIndexTypeName()); final AbstractIndexDocumentItem createdTimeItem = getItemWithName( indexDocument, NodeIndexDocumentFactory.CREATED_TIME_PROPERTY, IndexValueType.DATETIME); assertEquals(Date.from(node.getCreatedTime()), createdTimeItem.getValue()); final AbstractIndexDocumentItem creator = getItemWithName( indexDocument, NodeIndexDocumentFactory.CREATOR_PROPERTY_PATH, IndexValueType.STRING); assertEquals("test:creator", creator.getValue()); final AbstractIndexDocumentItem modifier = getItemWithName( indexDocument, NodeIndexDocumentFactory.MODIFIER_PROPERTY_PATH, IndexValueType.STRING); assertEquals("test:modifier", modifier.getValue()); }
@Test public void set_analyzer() throws Exception { final String myAnalyzerName = "myAnalyzer"; final Node node = Node.newNode() .id(EntityId.from("abc")) .entityIndexConfig( EntityPropertyIndexConfig.newEntityIndexConfig().analyzer(myAnalyzerName).build()) .build(); final Collection<IndexDocument> indexDocuments = NodeIndexDocumentFactory.create(node, TEST_WORKSPACE); final IndexDocument indexDocument = getIndexDocumentOfType(indexDocuments, IndexType.NODE); assertEquals(myAnalyzerName, indexDocument.getAnalyzer()); }
public AbstractIndexDocumentItem getItemWithName( final IndexDocument indexDocument, final IndexDocumentItemPath path, final IndexValueType baseType) { for (AbstractIndexDocumentItem item : indexDocument.getIndexDocumentItems()) { if (item.getPath().equals(path.toString()) && item.getIndexBaseType().equals(baseType)) { return item; } } return null; }
public Set<AbstractIndexDocumentItem> getItemsWithName( final IndexDocument indexDocument, final IndexDocumentItemPath path, final IndexValueType baseType) { Set<AbstractIndexDocumentItem> items = Sets.newHashSet(); for (AbstractIndexDocumentItem item : indexDocument.getIndexDocumentItems()) { if (item.getPath().equals(path.toString()) && item.getIndexBaseType().equals(baseType)) { items.add(item); } } return items; }