2014-09-06 20 views
11

Ho osservato il sistema di gestione ma alcune cose ancora mi sfuggono. In sostanza, quello che voglio fare è:Titan db come elencare tutti gli indici del grafico

  • Elenca tutti gli indici basati su Edge (incluso vertice).
  • Elenca tutti gli indici basati su vertici (in base all'etichetta se l'indice è collegato a un'etichetta).

Fondamentalmente è come mappare lo schema del grafico.

Ho provato alcune cose ma ottengo solo dati parziali al meglio.

g.getIndexdKeys(<Vertex or Edge>); 
//basic information. Doesn't seem to return any buildEdgeIndex() based indexes 

mgmt.getVertexLabels(); 
// gets labels, can't find a way of getting indexes attached to these labels. 

mgmt.getGraphIndexes(Vertex.class); 
// works nicely I can retrieve Vertex indexes and get pretty much any 
// information I want out of them except for information regarding 
// indexOnly(label). So I can't tell what label these indexes are attached to. 

mgmt.getGraphIndexes(Edge.class); 
// doesn't seem to return any buildEdgeIndex() indexes. 

Qualsiasi aiuto nel riempire il vuoto sarebbe utile.

Id piacerebbe sapere:

  • Come posso trovare gli indici collegati a un'etichetta (o l'etichetta attaccata ad un indice) tramite indexonly()
  • Come posso elencare gli indici dei bordi impostati tramite buildEdgeIndex() e le rispettive etichette di bordo?

Grazie in anticipo.

Ulteriori informazioni: Titan 0.5.0, Cassandra backend, via rexster.

risposta

9

non è proprio semplice, quindi lo mostrerò utilizzando un esempio.

Cominciamo con il grafico degli Dei + un indice aggiuntivo per i nomi dio:

g = TitanFactory.open("conf/titan-cassandra-es.properties") 
GraphOfTheGodsFactory.load(g) 
m = g.getManagementSystem() 
name = m.getPropertyKey("name") 
god = m.getVertexLabel("god") 
m.buildIndex("god-name", Vertex.class).addKey(name).unique().indexOnly(god).buildCompositeIndex() 
m.commit() 

Ora cerchiamo di tirare le informazioni di indice di nuovo.

gremlin> m = g.getManagementSystem() 
==>com.t[email protected]2f414e82 

gremlin> // get the index by its name 
gremlin> index = m.getGraphIndex("god-name") 
==>com.thinkau[email protected]e4f5395 

gremlin> // determine which properties are covered by this index 
gremlin> gn.getFieldKeys() 
==>name 

// 
// the following part shows what you're looking for 
// 
gremlin> import static com.thinkaurelius.titan.graphdb.types.TypeDefinitionCategory.* 

gremlin> // get the schema vertex for the index 
gremlin> sv = m.getSchemaVertex(index) 
==>god-name 

gremlin> // get index constraints 
gremlin> rel = sv.getRelated(INDEX_SCHEMA_CONSTRAINT, Direction.OUT) 
==>[email protected] 

gremlin> // get the first constraint; no need to do a .hasNext() check in this 
gremlin> // example, since we know that we will only get a single entry 
gremlin> sse = rel.iterator().next() 
==>[email protected] 

gremlin> // finally get the schema type (that's the vertex label that's used in .indexOnly()) 
gremlin> sse.getSchemaType() 
==>god 

Cheers, Daniel

+0

sorprendente grazie! Ne avevo già tratto una parte ma mancava l'etichetta dei vertici. –

Problemi correlati