こんにちは、演算子 IN を使用して検索しようとしていますが、常に空のリストが返されます。何が問題なのですか? 私の単体テストの下に。私が欲しいのは、説明または説明に一致する類似語で製品を検索することです。(将来的にはファジーを実装するふりをします)。
private GraphDatabaseService graph;
private Index<Node> indexProduct;
private ExecutionEngine engine;
@Before
public void prepareTestDatabase() {
TestGraphDatabaseFactory testGraphDatabaseFactory = new TestGraphDatabaseFactory();
this.graph = testGraphDatabaseFactory.newEmbeddedDatabase("/tmp/neo4j/tests");
this.indexProduct = this.graph.index().forNodes("node_product");
this.engine = new ExecutionEngine(this.graph, StringLogger.SYSTEM);
this.loadDataForTest();
}
private void loadDataForTest() {
Transaction tx = this.graph.beginTx();
List<String> similarities = new ArrayList<>();
similarities.add("televisor");
similarities.add("tv");
String description = "televisão";
Product product = new Product(description, similarities);
Node node = this.graph.createNode(DynamicLabel.label(product.description));
node.setProperty("description", product.description);
node.setProperty("similarities", product.similarities);
this.indexProduct.add(node, "PRODUCT", product.description);
tx.success();
tx.finish();
}
@Test
public void searchByDescription(){
String description = "televisão";
List<String> list = new ArrayList<>();
ExecutionResult result = this.engine.execute("start n=node:node_product('PRODUCT:*') WHERE HAS(n.similarities) AND n.similarities IN ['tv'] return n.description");
for (Map<String, Object> row : result) {
for (Entry<String, Object> column : row.entrySet()) {
Object value = column.getValue();
list.add(String.valueOf(value));
}
}
Assert.assertTrue(list.contains(description));
}
これは製品クラスです
class Product {
String description;
String[] similarities;
Product(String description, List<String> similaritiesList) {
super();
this.description = description;
this.similarities = new String[similaritiesList.size()];
for (int i=0; i<similaritiesList.size(); i++)
this.similarities[i] = similaritiesList.get(i);
}