Search in sources :

Example 1 with PurgeIndexParams

use of com.enonic.xp.index.PurgeIndexParams in project xp by enonic.

the class IndexServiceImplTest method reindex_cms_repo.

@Test
public void reindex_cms_repo() throws Exception {
    final Context cmsRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(TEST_REPO_ID).branch(ContentConstants.BRANCH_DRAFT).build();
    cmsRepoContext.callWith(this::createDefaultRootNode);
    cmsRepoContext.callWith(() -> createNode(CreateNodeParams.create().setNodeId(NodeId.from("su")).name("su").parent(NodePath.ROOT).build()));
    refresh();
    assertEquals(2, cmsRepoContext.callWith(this::findAllNodes).getHits());
    this.indexService.purgeSearchIndex(new PurgeIndexParams(cmsRepoContext.getRepositoryId()));
    assertEquals(0, cmsRepoContext.callWith(this::findAllNodes).getHits());
    this.indexService.reindex(ReindexParams.create().addBranch(cmsRepoContext.getBranch()).repositoryId(cmsRepoContext.getRepositoryId()).initialize(true).build());
    refresh();
    assertEquals(2, cmsRepoContext.callWith(this::findAllNodes).getHits());
}
Also used : Context(com.enonic.xp.context.Context) PurgeIndexParams(com.enonic.xp.index.PurgeIndexParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 2 with PurgeIndexParams

use of com.enonic.xp.index.PurgeIndexParams in project xp by enonic.

the class IndexServiceImplTest method purge_then_reindex.

@Test
public void purge_then_reindex() throws Exception {
    final Node node = createNode(CreateNodeParams.create().name("myNode").parent(NodePath.ROOT).build());
    refresh();
    this.indexService.purgeSearchIndex(new PurgeIndexParams(TEST_REPO_ID));
    assertNull(queryForNode(node.id()));
    final ReindexResult result = this.indexService.reindex(ReindexParams.create().addBranch(WS_DEFAULT).repositoryId(TEST_REPO_ID).initialize(false).build());
    assertEquals(2, result.getReindexNodes().getSize());
    refresh();
    assertNotNull(queryForNode(node.id()));
    assertNotNull(queryForNode(rootNode.id()));
}
Also used : ReindexResult(com.enonic.xp.index.ReindexResult) Node(com.enonic.xp.node.Node) PurgeIndexParams(com.enonic.xp.index.PurgeIndexParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 3 with PurgeIndexParams

use of com.enonic.xp.index.PurgeIndexParams in project xp by enonic.

the class IndexServiceImplTest method reindex_other_branch.

@Test
public void reindex_other_branch() throws Exception {
    final Node node = createNode(CreateNodeParams.create().name("myNode").parent(NodePath.ROOT).build());
    refresh();
    PushNodesCommand.create().ids(NodeIds.from(node.id())).target(WS_OTHER).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    refresh();
    assertNotNull(queryForNode(node.id()));
    assertNotNull(ctxOther().callWith(() -> queryForNode(node.id())));
    this.indexService.purgeSearchIndex(new PurgeIndexParams(TEST_REPO_ID));
    refresh();
    assertNull(queryForNode(node.id()));
    this.indexService.reindex(ReindexParams.create().addBranch(WS_DEFAULT).repositoryId(TEST_REPO_ID).initialize(false).build());
    refresh();
    assertNotNull(queryForNode(node.id()));
    assertNull(ctxOther().callWith(() -> queryForNode(node.id())));
    this.indexService.reindex(ReindexParams.create().addBranch(WS_OTHER).repositoryId(TEST_REPO_ID).initialize(true).build());
    refresh();
    assertNull(queryForNode(node.id()));
    assertNotNull(ctxOther().callWith(() -> queryForNode(node.id())));
}
Also used : Node(com.enonic.xp.node.Node) PurgeIndexParams(com.enonic.xp.index.PurgeIndexParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 4 with PurgeIndexParams

use of com.enonic.xp.index.PurgeIndexParams in project xp by enonic.

the class IndexServiceImplTest method reindex_system_repo.

@Test
public void reindex_system_repo() throws Exception {
    final Context systemRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(SystemConstants.SYSTEM_REPO_ID).branch(SystemConstants.BRANCH_SYSTEM).build();
    systemRepoContext.callWith(this::createDefaultRootNode);
    systemRepoContext.callWith(() -> createNode(CreateNodeParams.create().setNodeId(NodeId.from("su")).name("su").parent(NodePath.ROOT).build()));
    refresh();
    final long nodesInSystemRepoCount = systemRepoContext.callWith(this::findAllNodes).getHits();
    this.indexService.purgeSearchIndex(new PurgeIndexParams(systemRepoContext.getRepositoryId()));
    assertEquals(0, systemRepoContext.callWith(this::findAllNodes).getHits());
    this.indexService.reindex(ReindexParams.create().addBranch(systemRepoContext.getBranch()).repositoryId(systemRepoContext.getRepositoryId()).initialize(true).build());
    refresh();
    assertEquals(nodesInSystemRepoCount, systemRepoContext.callWith(this::findAllNodes).getHits());
}
Also used : Context(com.enonic.xp.context.Context) PurgeIndexParams(com.enonic.xp.index.PurgeIndexParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

PurgeIndexParams (com.enonic.xp.index.PurgeIndexParams)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 Test (org.junit.jupiter.api.Test)4 Context (com.enonic.xp.context.Context)2 Node (com.enonic.xp.node.Node)2 ReindexResult (com.enonic.xp.index.ReindexResult)1