5

我正在文件节点存储中试用带有 lucene 的长耳兔橡树。索引定义记录创建成功,但似乎没有创建索引记录。我正在做的完整项目在这里

我在代码中所做的是初始化一个存储库,创建 lucene 索引定义,添加一个具有单个属性“name”和值为“foo”的测试数据。休眠 5 秒以完成异步索引,然后在重试循环中执行以下查询 select * from [nt:base] where contains(., 'foo')。

不返回任何结果。我已经尝试使用 Oak-run 控制台来检索 Oak:index/lucene 目录上的 lc 信息,它也没有显示任何结果。

这是代码的主要部分

public static void main( String[] args ) throws Exception
{
    init();
    createLuceneIndex();
    createTestData();
    performQuery();

}

private static void init() throws InvalidFileStoreVersionException, IOException {
    LuceneIndexProvider provider = new LuceneIndexProvider();
    FileStore fs = FileStoreBuilder.fileStoreBuilder(new File("repository")).build();
    nodestore = SegmentNodeStoreBuilders.builder(fs).build();
    repository = new Jcr(new Oak(nodestore))
            .withAsyncIndexing("async", 3)
            .with(new LuceneIndexEditorProvider())
            .with((QueryIndexProvider) provider)
            .with((Observer)provider)
            .withAsyncIndexing()
            .createRepository();
}

private static void createLuceneIndex() throws RepositoryException {
    Session session = createAdminSession();
    Node indexesNode = session.getRootNode().getNode("oak:index");
    IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
    IndexRule indexRules = idxBuilder.indexRule("nt:unstructured");
    indexRules.sync();
    indexRules.property("name").analyzed().nodeScopeIndex();
    idxBuilder.async("async");
    idxBuilder.includedPaths("/");
    Node documentIndex = indexesNode.addNode("lucene", "oak:QueryIndexDefinition");
    idxBuilder.build(documentIndex);
    session.save();
    session.logout();

}

private static void createTestData() throws LoginException, RepositoryException {
    Session session = createAdminSession();
    Node test = session.getRootNode().addNode("test");
    test.setProperty("name", "foo");
    session.save();
    session.logout();
}

private static void performQuery() throws Exception {
    final Session session = createAdminSession();
    TimeUnit.MICROSECONDS.sleep(5);

    QueryManager qm = session.getWorkspace().getQueryManager();
    final Query q = qm.createQuery("select * from [nt:base] where contains(., 'foo')", Query.JCR_SQL2);

    new RetryLoop(new RetryLoop.Condition() {
        public String getDescription() {
            return "Full text query";
        }

        public boolean isTrue() throws Exception {
            QueryResult r = q.execute();
            return r.getNodes().hasNext();
        }
    }, 20, 500);
}

pom文件依赖

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>
<dependency>
    <groupId>javax.jcr</groupId>
    <artifactId>jcr</artifactId>
    <version>2.0</version>
</dependency>
<dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>oak-jcr</artifactId>
    <version>1.21-SNAPSHOT</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>oak-core</artifactId>
    <version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>oak-jcr</artifactId>
    <version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>oak-segment-tar</artifactId>
    <version>1.21-SNAPSHOT</version>
</dependency>
    <dependency>
    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>oak-lucene</artifactId>
    <version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.30</version>
</dependency>
<dependency>
    <groupId>com.codahale.metrics</groupId>
    <artifactId>metrics-core</artifactId>
    <version>3.0.2</version>
</dependency>
4

0 回答 0