2016-12-07 5 views
0
root: { 
    dir: { 
    subDir: { 
     subSubDir: { 
     ... 
     }, 
     ... 
    }, 
    subDir_2: { 
     ... 
    } 
    }, 
    dir_2: { 
    ... 
    }, 
    ... 
} 

私はdir内検索を実行する必要があり、すべてはそれが子孫だ、またはsubDirとすべてで、それは子孫などだ...私は少し(dirの名前を変更するノードを含むかなり頻繁に(10〜100倍の日)にデータを変更することがありますdirectoryなど)。データの量は1MBから数百MBまでで、約1GBでも可能ですが、ノードの数は無限になる可能性がありますが、平均は最大10kです。ネスティングの深さはおそらく20までになります。ファイルシステムのように、ネストされた "ディレクトリ"内でフルテキスト検索を実行できるデータベースは何ですか?

アーキテクチャは変更される可能性がありますが、「ディレクトリのような」表現の考え方が必要です。

私はこの代替を考えた:

{ 
    [guid]: {title, text, path etc}, 
    [guid]: {title, text, path etc}, 
    [guid]: {title, text, path etc}, 
    [guid]: {title, text, path etc}, 
    [guid]: {title, text, path etc}, 
    } 

たのかもしれない(生)これは、同様のSQLデータベースに実装することができますが、ノード名の変更の場合には、私は、各ノードでpathプロパティを変更する必要があります非常に高価です。

+2

postgresにネイティブJSONと全文検索 – NinjaGaiden

+0

はい、それもESがあり、mongodbはそれを持っていると信じています...しかし、私はまだ記述されている条件で全文検索を実装する方法を見ていません上記。 – stkvtflw

+0

これを正規化された階層データとして保存すると、リレーショナルデータベースで再帰的なSQLクエリを実行するのは簡単です。 –

答えて

1

modern SQLと再帰的な共通テーブル式を使用すると、SQLで階層データを扱うのは簡単です。

次のセットアップ:

は、テーブルディレクトリ ( ID整数プライマリキー、 名前はvarchar(100)nullではない、 説明テキスト、 parent_directory_id整数の参照ディレクトリ )を作成します。

insert into directory (id, name, description, parent_directory_id) 
values 
(1, 'Root', 'The root of all evil', null), 
(2, 'Toplevel1', 'First directory', 1), 
(3, 'Toplevel2', 'Second directory', 1), 
(4, 'T1-Subdir1', 'T1 - Some data', 2), 
(5, 'T2-Subdir1', 'T2 - Irrelevant', 3), 
(6, 'T1-S1-S1', 'T1-S1 important docs', 4), 
(7, 'T1-S1-S2', 'T1-S1 trashcan', 4), 
(8, 'T1-S1-S3', 'T1-S1 important scans', 4); 
あなたが "重要" を使用して、このクエリ文字列が含まれている "Toplevel1" のすべてのサブディレクトリを検索することができ

with recursive tree as (
    select id, name, description, parent_directory_id 
    from directory 
    where id = 2 -- The starting directory 
    union all 
    select cd.id, cd.name, cd.description, cd.parent_directory_id 
    from directory cd 
    join tree parent on cd.parent_directory_id = parent.id 
) 
select id,name,description 
from tree 
where description like '%important%'; 

上記リターン:

id | name  | description   
---+----------+---------------------- 
6 | T1-S1-S1 | T1-S1 important docs 
8 | T1-S1-S3 | T1-S1 important scans 

where条件は、データベースの全文検索機能を利用することもできます。

関連する問題