5.5.2 プロパティ・グラフ・データの自動索引の使用

自動テキスト索引は、プロパティ・キーのセットにより、頂点またはエッジの自動的な索引付けを提供します。この主な目的は、特定のキー/値のペアに基づき、頂点およびエッジの検索速度を上げることです。指定したキーの自動索引が有効な場合、キー/値ペア参照は、データベース参照ではなく、索引に対するテキスト検索として実行されます。

プロパティ・グラフで自動索引を指定するときに、次のメソッドを使用して、自動索引を作成、削除および操作します。

  • OraclePropertyGraph.createKeyIndex(String key, Class elementClass, Parameter[] parameters): 指定したプロパティ・キーにより、タイプelementClassのすべての要素に対する自動索引を作成します。索引は指定したパラメータに基づいて構成されます。

  • OraclePropertyGraph.createKeyIndex(String[] keys, Class elementClass, Parameter[] parameters): プロパティ・キーのセットにより、タイプelementClassのすべての要素に対する自動索引を作成します。索引は指定したパラメータに基づいて構成されます。

  • OraclePropertyGraph.dropKeyIndex(String key, Class elementClass): 指定したプロパティ・キーにより、タイプelementClassのすべての要素に対する自動索引を削除します。

  • OraclePropertyGraph.dropKeyIndex(String[] keys, Class elementClass): 指定したプロパティ・キーのセット用の、タイプelementClassのすべての要素に対する自動索引を作成します。

  • OraclePropertyGraph.getAutoIndex(Class elementClass): タイプelementClassの自動索引の索引インスタンスを取得します。

  • OraclePropertyGraph.getIndexedKeys(Class elementClass): タイプelementClassのすべての要素の自動索引で現在使用されている索引付けされたキーのセットを取得します。

デフォルトでは、索引はメソッドopg.setDefaultIndexParameters(indexParams)を使用してプロパティ・グラフに関連付けられたOracleIndexParametersに基づいて構成されます。

索引は、パラメータの異なるセットを指定することでも作成できます。これは次のコード・スニペットに示されています。

// Create an OracleIndexParameters object to get Index configuration (search engine, etc).
OracleIndexParameters indexParams = OracleIndexParameters.buildFS(args)  
 
// Create auto indexing on above properties for all vertices
opg.createKeyIndex("name", Vertex.class, indexParams.getParameters());

次の例のコード・フラグメントは、すべての頂点に対して問合せを実行し、キー値ペアname:Robert Smithを持つすべての一致する頂点を検索します。この操作は、テキスト索引の検索を実行します。

さらに、getVertices APIコールでパラメータuseWildCardsを指定することにより、ワイルドカード検索がサポートされます。ワイルドカード検索は、指定したプロパティ・キーに対して自動索引が有効な場合にのみサポートされます。

// Find all vertices with name Robert Smith. 
    Iterator<Vertices> vertices = opg.getVertices("name", "Robert Smith").iterator();
    System.out.println("----- Vertices with name Robert Smith -----");
    countV = 0;
    while (vertices.hasNext()) {
      System.out.println(vertices.next());
      countV++;
    }
    System.out.println("Vertices found: " + countV);
 
   // Find all vertices with name including keyword "Smith"
   // Wildcard searching is supported.
    boolean useWildcard = true;
    Iterator<Vertices> vertices = opg.getVertices("name", "*Smith*").iterator();
    System.out.println("----- Vertices with name *Smith* -----");
    countV = 0;
    while (vertices.hasNext()) {
      System.out.println(vertices.next());
      countV++;
    }
    System.out.println("Vertices found: " + countV);

このコード例によって生成される出力は、次のようになります。

----- Vertices with name Robert Smith-----
Vertex ID 1 {name:str:Robert Smith, role:str:political authority, occupation:str:CEO of Example Corporation, country:str:United States, political party:str:Bipartisan, religion:str:Unknown}
Vertices found: 1
 
----- Vertices with name *Smith* -----
Vertex ID 1 {name:str:Robert Smith, role:str:political authority, occupation:str:CEO of Example Corporation, country:str:United States, political party:str:Bipartisan, religion:str:Unknown}
Vertices found: 1