我尝试使用 jcr jackrabbit Oak、mongoDb 和查询。
首先我在存储库中添加了一些文件。
现在我想使用全文搜索。
当我使用查询时:
Session session = getSessions();
Workspace workspace = session.getWorkspace();
QueryManager queryManager = workspace.getQueryManager();
Query query = queryManager.createQuery("SELECT [nt:file].* FROM [nt:file],Query.JCR_SQL2);
QueryResult result = query.execute();
log.info("Size nodes " + result.getRows().getSize());
来自日志:2019-02-28 15:11:50.959 INFO 63248 --- [nio-8080-exec-5] cerservice.DocumentManagementService:大小节点 8
所以当我尝试使用如下查询时:
Query query = queryManager.createQuery("SELECT [nt:file].* FROM [nt:file] WHERE contains(*, 'insert)",Query.JCR_SQL2);
cerservice.DocumentManagementService:大小节点 0
我确定每个文件都有一个单词“插入”。
我做错了什么?
非常感谢
所以我还创建了索引 lucene :
String indexPath = "/oak:index/lucene";
Node lucene = JcrUtils.getOrCreateByPath(indexPath, JcrConstants.NT_UNSTRUCTURED,
"oak:QueryIndexDefinition", session, false);
lucene.setProperty("async", "async");
lucene.setProperty(IndexConstants.TYPE_PROPERTY_NAME, "lucene");
lucene.setProperty(FulltextIndexConstants.EVALUATE_PATH_RESTRICTION, true);
lucene.setProperty(LuceneIndexConstants.INDEX_PATH, indexPath);
lucene.setProperty(FulltextIndexConstants.COMPAT_MODE, IndexFormatVersion.V2.getVersion());
Node indexRules = lucene.addNode(FulltextIndexConstants.INDEX_RULES, JcrConstants.NT_UNSTRUCTURED);
Node ntBaseRule = indexRules.addNode(JcrConstants.NT_BASE);
ntBaseRule.setProperty(FulltextIndexConstants.INCLUDE_PROPERTY_TYPES,
new String[] {PropertyType.TYPENAME_BINARY, PropertyType.TYPENAME_STRING});
Node propNode = ntBaseRule.addNode(FulltextIndexConstants.PROP_NODE);
Node allPropNode = propNode.addNode("allProps");
allPropNode.setProperty(FulltextIndexConstants.PROP_ANALYZED, true);
allPropNode.setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true);
allPropNode.setProperty(FulltextIndexConstants.PROP_NAME, FulltextIndexConstants.REGEX_ALL_PROPS);
allPropNode.setProperty(FulltextIndexConstants.PROP_IS_REGEX, true);
allPropNode.setProperty(FulltextIndexConstants.PROP_USE_IN_SPELLCHECK, true);
Node aggNode = lucene.addNode(FulltextIndexConstants.AGGREGATES);
Node aggFile = aggNode.addNode(JcrConstants.NT_FILE);
aggFile.addNode("include0").setProperty(FulltextIndexConstants.AGG_PATH, JcrConstants.JCR_CONTENT);
节点大小为0。
伙计们请帮助我:)