gpt4 book ai didi

java - 如何将 cassandra 中存在的 Titan 图索引到 solr

转载 作者:行者123 更新时间:2023-12-02 13:11:42 24 4
gpt4 key购买 nike

我在 cassandra 中存储了一张泰坦图。下面是代码。

public class Example1 {

public static void main(String[] args) {
//Initliase graph
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty("storage.backend", "cassandra");
baseConfiguration.setProperty("storage.hostname", "192.168.3.82");
baseConfiguration.setProperty("storage.cassandra.keyspace", "mycustomerdata");
TitanGraph graph = TitanFactory.open(baseConfiguration);

//---------------- Adding Data -------------------
//Create some customers
Vertex alice = graph.addVertex("customer");
alice.property("name", "Alice Mc Alice");
alice.property("birthdat", "100000 BC");

Vertex bob = graph.addVertex("customer");
bob.property("name", "Bob Mc Bob");
bob.property("birthdat", "1000 BC");

//Create Some Products
Vertex meat = graph.addVertex("product");
meat.property("name", "Meat");
meat.property("description", "Delicious Meat");

Vertex lettuce = graph.addVertex("product");
lettuce.property("name", "Lettuce");
lettuce.property("description", "Delicious Lettuce which is green");

//Alice Bought some meat:
alice.addEdge("bought", meat);
//Bob Bought some meat and lettuce:
bob.addEdge("bought",lettuce);

//---------------- Querying (aka traversing whcih is what you do in graph dbs) Data -------------------
//Now who has bought meat?
graph.traversal().V().has("name", "meat").in("bought").forEachRemaining(v -> System.out.println(v.value("name")));

//Who are all our customers
/*graph.traversal().V().hasLabel("customer").forEachRemaining(v -> System.out.println(v.value("name")));

//What products do we have
graph.traversal().V().hasLabel("product").forEachRemaining(v -> System.out.println(v.value("name")));*/


graph.close();

}
}

我想在 solr 中索引相同的图。

  1. 如何使用 java 来做到这一点?
  2. 我是否查询了键空间和索引的表?在 solr 中索引相同的图的方法是什么?

最佳答案

Titan 直接与 solr 集成。这意味着永远不必直接与 solr 对话。相反,你让泰坦为你与它交谈,每当遍历图表时,这种情况就会自然发生。

您所要做的就是按照定义 here 设置索引。我提供了一个使用 Solr/Elastic 搜索优化的混合索引的示例 here

因此,在上面的示例中,每当您与 solr 一起执行特定类型的遍历时,titan 都会快速响应。

请记住您必须创建混合索引。

除了定义索引之外,您还必须让 titan 与 solr 一起运行。不幸的是这并不是那么简单。你必须让 solr 运行,然后让 titan 与 solr 对话,就像我所做的那样 here

关于java - 如何将 cassandra 中存在的 Titan 图索引到 solr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43934890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com