我的目的是使用存储在列表中的关键字索引包含pdf文件(以及其他文件类型)的任意目录.我有一个传统的解决方案,我听说使用例如SimpleGraph的基于图形的解决方案可以更优雅/高效并且独立于目录结构.
基于图形的解决方案(例如SimpleGraph)会是什么样的?
传统解决方案
// https://stackoverflow.com/a/14051951/1497139
List<File> pdfFiles = this.explorePath(TestPDFFiles.RFC_DIRECTORY, "pdf");
List<PDFFile> pdfs = this.getPdfsFromFileList(pdfFiles);
…
for (PDFFile pdf:pdfs) {
// https://stackoverflow.com/a/9560307/1497139
if (org.apache.commons.lang3.StringUtils.containsIgnoreCase(pdf.getText(), keyWord)) {
foundList.add(pdf.file.getName()); // here we access by structure (early binding)
// - in the graph solution by name (late binding)
}
}
Run Code Online (Sandbox Code Playgroud) 下面来自 simplegraph-core 测试套件的单元测试代码显示了机场的区域计数,但它的顺序并不像我预期的那样。
结果开始于:
NZ-BOP= 3
MZ-A= 1
MZ-B= 1
IN-TN= 5
MZ-N= 1
PW-004= 1
MZ-I= 2
BS-FP= 1
IN-TR= 1
MZ-T= 1
BJ-AQ= 1
GB-ENG= 27
Run Code Online (Sandbox Code Playgroud)
我调查了
并在标记为 gremlin 的问题中搜索“GroupCount”无济于事
什么是修复排序所必需的?
@Test
public void testSortedGroupCount() throws Exception {
Graph graph = getAirRoutes();
GraphTraversalSource g = graph.traversal();
Map<Object, Long> counts = g.V().hasLabel("airport").groupCount()
.by("region").order().by(Order.decr).next();
assertEquals(1473, counts.size());
for (Object key : counts.keySet()) {
System.out.println(String.format("%s=%3d", key, counts.get(key)));
}
}
Run Code Online (Sandbox Code Playgroud)