最近のアクセス:
全文検索の例 - インデックス作成

このページでは、全文検索のためのインデックス作成関数の使用例を示します。

1.Business Components トランザクションに関連する、データベース内に格納されているすべてのデータのインデックスを作成

Event ReindexAll
    &error = TextSearch.ReindexAll()
EndEvent
[ Searchable ] プロパティが True になっているすべてのトランザクションのインデックスを再作成します。検索可能なビジネスコンポーネントに関連するすべての情報がインデックスから削除され、再度インデックスが作成されます。削除されるのはこの情報だけであり、インデックスを作成できるほかのデータ (ファイルや文字列など) は削除されない点に注意してください。

2.指定されたディレクトリーにあるすべてのファイルのインデックスを作成

この例では、ディレクトリー内のファイルすべてのインデックスを作成します。
検索によってドキュメントを取り出すと、 [ &contentinfo.viewer ] プロパティで指定したとおりにリンクされます。
Event IndexFiles
    &directory.Source = &source
    For &file in &directory.GetFiles("*.*")         &ContentInfo.Viewer = &URL + &file.GetName()
        &booleanvar = TextSearch.Add(&file,&ContentInfo)
        If &booleanvar= TRUE
           msg( format("%1 のインデックスを作成しています", &file.GetName()))
        else
           msg(format("%1 のインデックス作成でエラーが発生しました",&file.GetName()))
        EndIf
    EndFor
EndEvent
データタイプ:
  • &directory は Directory データタイプです。
  • &file は File データタイプの変数です。
  • &contentinfo は ContentInfo データタイプです。

手順 3 -インデックスコンテンツの更新

Event UpdateContentFile
    &directory.Source = &source
    For &file in &directory.GetFiles("*.*")         &ContentInfo.Viewer = &URL + &file.GetName()
        &booleanvar = TextSearch.Update(&file,&ContentInfo)
        If &booleanvar = TRUE
           msg( format("%1 のインデックスを更新しています", &file.GetName()))
        else
           msg(format("%1 のインデックス更新でエラーが発生しました",&file.GetName()))
        EndIf
    EndFor
EndEvent

4.インデックスからのファイルの削除

インデックスからファイルを削除します。
注:
  • &sourcefile は、インデックスから削除するファイルへのパスです。
  • &file はファイル データ タイプの変数です。
Event Delete File Index
    &file.Source = &sourcefile
    &booleanvar = TextSearch.Delete(&file)
    if &booleanvar= TRUE
       msg( format( format("インデックスエントリー %1 は削除されました", &file.GetName())
    else
       msg(format("インデックスエントリー %1 の削除でエラーが発生しました",&file.GetName()))
    endif 
EndEvent
Event IndexString
      &ContentInfo.Id = &AccountingEntry.Id.ToString()
      &ContentInfo.Title = 'Accounting Entry # ' + &AccountingEntry.Id.ToString()
      &ContentInfo.Type = 'Accounting Entry'
      &ContentInfo.Viewer = AccountingEntrydata.Link(&AccountingEntry.Id,'DSP') // トランザクションを表示モードで呼び出し 
      &AccountingDetail = &AccountingEntry.ToXml() // すべての会計項目を XML 文字列に変換
      &booleanvar = TextSearch.Add(&AccountingDetail,&ContentInfo)
      if &booleanvar= TRUE
         msg( format("%1 のインデックスを作成しています", &ContentInfo.Id))
      else
          msg(format("%1 のインデックス作成でエラーが発生しました",&ContentInfo.Id))
     endif
EndEvent
インデックスからエントリーを削除するには次のように記述します:
Event 'Delete Index'
    &AccountingEntryAux = &AccountingEntryDataId.ToString()
    &booleanvar = TextSearch.Delete(&AccountingEntryAux)
    if &booleanvar= TRUE
        msg( format("インデックスコンテンツ %1 を削除しています", &AccountingEntry.Id.ToString()))
    else
        msg(format("インデックスコンテンツ %1 の削除でエラーが発生しました",&AccountingEntryDataId.ToString()))
    endif
EndEvent
参考情報: アプリケーションの全文検索全文検索の例Full Text Search データタイプ

5.文字列 (メモリーからの値) のインデックス作成

データベースやファイルには格納されていない、ほかのソースから情報を収集するプロセスの結果や出力の情報を検索できるようにしたい場合もあります。
たとえば、GeneXus 内で SDT として表される会計エントリーについて、会計エントリーすべての情報を検索可能にするとします。
会計エントリーを計算した後、必要な情報を ContentInfo 変数に格納してから TextSearch.Add 関数または TextSearch.Update 関数を呼び出します。
Event 'IndexString'
      &ContentInfo.Id = &AccountingEntry.Id.ToString()
      &ContentInfo.Title = format('Accounting Entry # %1', &AccountingEntry.Id)
      &ContentInfo.Type = 'Accounting Entry'
      &ContentInfo.Viewer = AccountingEntrydata.Link(&AccountingEntry.Id,'DSP') // トランザクションを表示モードで呼び出し
      &AccountingDetail = &AccountingEntry.ToXml() // すべての会計項目を XML 文字列に変換
      &booleanvar = TextSearch.Add(&AccountingDetail,&ContentInfo)
      if &booleanvar= TRUE
         msg( format("%1 のインデックスが作成されました", &ContentInfo.Id))
      else
         msg(format("%1 のインデックス作成でエラーが発生しました",&ContentInfo.Id))
      endif
EndEvent

参考情報

Full Text Search データタイプ
全文検索の例










サブページ
Created: 14/09/18 03:18 by Admin Last update: 21/10/28 23:31 by Admin
カテゴリ
Powered by GXwiki 3.0