5.5.4.1 Oracle Textを使用したテキスト索引を介した検索問合せの実行
Oracle Textでのテキスト検索問合せは、スコアの範囲および順序、スコアIDを含む"contains"句を使用したSELECT SQL問合せに変換されます。Oracleのプロパティ・グラフには、OracleTextQueryObject
という名前のユーティリティが含まれ、これを使用して、Oracle Text索引を介したテキスト検索問合せを実行できます。
次のコード・フラグメントは、Oracle Textを使用して自動索引を作成し、特定のキー値ペアを指定して、テキスト索引を介して問合せを実行します。
String prefOwner = "scott"; String datastore = (String) null; String filter = (String) null; String storage = (String) null; String wordlist = (String) null; String stoplist = (String) null; String lexer = "OPG_AUTO_LEXER"; String options = (String) null; OracleIndexParameters params = OracleTextIndexParameters.buildOracleText(prefOwner, datastore, filter, storage, wordlist, stoplist, lexer, dop, options); opg.setDefaultIndexParameters(indexParams); // Create auto indexing on all existing properties, use wildcard for all opg.createKeyIndex(("*", Vertex.class); // Get the auto index object OracleIndex<Vertex> index = ((OracleIndex<Vertex>) opg.getAutoIndex(Vertex.class); // Create the text query object for Oracle Text OracleTextQueryObject otqo = OracleTextQueryObject.getInstance("Smith" /* query body */, 1 /* score */, ScoreRange.POSITIVE /* Score range */, Direction.ASC /* order by direction*/); Iterator<Vertex> vertices = index.get("name", otqo).iterator(); System.out.println("----- Vertices with query: " + otqo.toString() + " -----"); countV = 0; while (vertices.hasNext()) { System.out.println(vertices.next()); countV++; } System.out.println("Vertices found: "+ countV);
問合せを実行するデータ型のクラスを指定して、一致するキー値ペアのデータ型をフィルタ処理できます。次のコード・フラグメントでは、テキスト索引を介して問合せを実行し、語句Smithを含む文字列値を持つすべてのプロパティを取得します。
// Create the text query object for Oracle Text OracleTextQueryObject otqo = OracleTextQueryObject.getInstance("Smith" /* query body */, 1 /* score */, ScoreRange.POSITIVE /* Score range */, Direction.ASC /* order by direction*/, "name", String.class); Iterator<Vertex> vertices = index.get("name", otqo).iterator(); System.out.println("----- Vertices with query: " + otqo.toString() + " -----"); countV = 0; while (vertices.hasNext()) { System.out.println(vertices.next()); countV++; } System.out.println("Vertices found: "+ countV);
親トピック: プロパティ・グラフのテキスト索引を介した検索問合せの実行