検索の実行 (Execute Search)
構造化されたクエリ DSL を使用してドキュメントリポジトリを検索します。全文検索、セマンティックなベクトル検索、メタデータフィルタをサポートしており、すべて組み合わせて使用できます。
リクエスト
Content-Type: application/json
| フィールド | 型 | デフォルト | 説明 |
|---|---|---|---|
where | object | — | 検索・フィルタ句のツリー。 |
select | string[] | 下記参照 | 返すフィールド。 |
sort | object[] | [{_score, desc}] | それぞれ field と direction を指定します。 |
limit | integer | 20 | 1ページあたりの結果件数(1〜500)。 |
offset | integer | 0 | ページネーションのオフセット。 |
options | object | {} | 下記の「オプション」を参照。 |
デフォルトの select: ["id", "description", "doc_type", "doc_status", "reference_number", "entry_date", "_score"]
オプション
| フィールド | 型 | デフォルト | 説明 |
|---|---|---|---|
include_highlights | bool | false | <b> タグ付きのスニペットを返します。FTS 句が必要です。 |
highlight_length | int | 300 | スニペット1件あたりの最大文字数(100〜2000)。 |
where 句の種類
結合子
{"and": [clause, clause, ...]}
{"or": [clause, clause, ...]}
{"not": clause}
全文検索(FTS)
{"fts": {"field": "content", "query": "supply chain risk"}}
field は常に "content" です。query 文字列は、フレーズ、近接検索、ブール演算子を含む高度な構文をサポートします。
ベクトル(セマンティック)検索
{"vector": {"target": "content", "query": "employment applications and CVs"}}
target: "content" または "metadata"。クエリはベクトル化(embedding)され、L2 距離を用いて比較されます。正確なキーワードが一致しない場合でも、概念的に類似したドキュメントを検出します。
比較演算子
eq, ne, gt, gte, lt, lte — それぞれ field と value を受け取ります。
{"eq": {"field": "doc_type", "value": "Invoice"}}
{"gte": {"field": "entry_date", "value": "2025-01-01"}}
リスト演算子
{"in": {"field": "doc_type", "value": ["Invoice", "Receipt"]}}
{"nin": {"field": "doc_status", "value": ["Draft", "Archived"]}}
文字列演算子
{"contains": {"field": "description", "value": "urgent"}}
{"startswith": {"field": "reference_number", "value": "INV-2025"}}
クエリ構文 (Query syntax)
FTS 句の query 文字列は、高度な検索構文をサポートします。
キーワード(暗黙の AND)
supply chain risk
3つの単語すべてを含むドキュメントに一致します(テキスト内のどこでも、順序を問いません)。
完全一致フレーズ
"supply chain risk"
完全に一致するフレーズに一致します — 単語が隣接し、順序どおりに並んでいる必要があります。
OR
invoice OR receipt
いずれかの単語を含むドキュメントに一致します。
除外(NOT)
contract -draft
"contract" に一致しますが、"draft" を含むドキュメントは除外します。
前方一致検索
inv*
"inv" で始まる単語に一致します — 例: "invoice"、"inventory"、"investigation"。
近接検索(NEAR)
*N"contract penalty"
"contract" と "penalty" が10トークン以内(デフォルトの距離)で出現するドキュメントに一致します。
*N5"contract penalty"
5トークン以内に絞り込みます。
近接フレーズ検索
*NP"supply chain" "risk assessment"
NEAR と似ていますが、複数単語の入力をそのままのフレーズとして扱います — フレーズ "supply chain" がフレーズ "risk assessment" の近くに出現するドキュメントを検出します。
構文の組み合わせ
"supply chain" risk -draft inv*
完全一致フレーズ "supply chain" AND 単語 "risk" AND NOT "draft" AND "inv" で始まる任意の単語。
検索モードの動作
| 句 | 動作 |
|---|---|
| FTS のみ | 関連度スコアで順位付けされます |
| ベクトルのみ | 埋め込みの類似度で順位付けされます |
| FTS + ベクトル | 交差した結果を FTS で順位付けします |
| メタデータのみ | 順位付けなし — sort を使用してください |
| FTS + メタデータ | 事前フィルタ付きの FTS |
| ベクトル + メタデータ | 事前フィルタ付きのベクトル検索 |
メタデータフィールド
doc_type, doc_status, doc_number, description, from_entity, to_entity, reference_number, entry_date, entry_person, rev_number, date, privileged, islocked, filesbelongto, subdoctype
レスポンス
200 OK| フィールド | 型 | 説明 |
|---|---|---|
total | integer | 一致したドキュメントの総数。 |
offset | integer | 適用されたオフセット。 |
limit | integer | 適用されたページサイズ。 |
results | array | 結果オブジェクト。 |
結果フィールド
id(常に含まれます)、_score、_highlights、および select で指定した任意のメタデータフィールド。
エラー
| ステータス | 理由 |
|---|---|
| 400 | 無効な DSL です |
| 401 | トークンが無効です |
| 504 | クエリがタイムアウトしました |
例
シンプルなキーワード検索
{
"where": {"fts": {"field": "content", "query": "affidavit"}}
}
ハイライト付きの完全一致フレーズ
{
"where": {"fts": {"field": "content", "query": "\"personal details\""}},
"select": ["id", "description", "_score", "_highlights"],
"options": {"include_highlights": true, "highlight_length": 500}
}
近接検索 — 近くにある単語
"contract" と "penalty" が5単語以内に出現するドキュメントを検索します。
{
"where": {"fts": {"field": "content", "query": "*N5\"contract penalty\""}}
}
あいまい前方一致検索
"inv" で始まる任意の単語に一致させます(invoice、inventory、investigation...)。
{
"where": {"fts": {"field": "content", "query": "inv*"}}
}
ブール FTS — OR + 除外
"invoice" または "receipt" を含み、"draft" は含まない:
{
"where": {"fts": {"field": "content", "query": "invoice OR receipt -draft"}}
}
ベクトル検索 — ドキュメントコンテンツ
テキストコンテンツを検索することで、概念的に関連するドキュメントを検出します。
{
"where": {"vector": {"target": "content", "query": "employment applications and CVs"}},
"select": ["id", "description", "_score"],
"limit": 10
}
ベクトル検索 — メタデータ
全文の代わりにドキュメントメタデータの埋め込みに対して検索します。
{
"where": {"vector": {"target": "metadata", "query": "financial reports from Q1 2025"}},
"select": ["id", "description", "doc_type", "_score"],
"limit": 10
}
FTS + ベクトルの交差
キーワード検索と意味検索の両方に一致するドキュメントのみ:
{
"where": {
"and": [
{"fts": {"field": "content", "query": "risk assessment"}},
{"vector": {"target": "content", "query": "supply chain vulnerabilities"}}
]
}
}
タイプによるフィルタ
{
"where": {"eq": {"field": "doc_type", "value": "Invoice"}},
"sort": [{"field": "entry_date", "direction": "desc"}]
}
日付範囲
{
"where": {
"and": [
{"gte": {"field": "entry_date", "value": "2025-01-01"}},
{"lt": {"field": "entry_date", "value": "2026-01-01"}}
]
}
}
FTS + メタデータフィルタ + ハイライト
{
"where": {
"and": [
{"fts": {"field": "content", "query": "compliance audit"}},
{"eq": {"field": "doc_type", "value": "Report"}},
{"eq": {"field": "doc_status", "value": "Final"}},
{"gte": {"field": "entry_date", "value": "2025-01-01"}}
]
},
"select": ["id", "description", "date", "_score", "_highlights"],
"options": {"include_highlights": true},
"limit": 25
}
複数タイプ(IN)
{
"where": {"in": {"field": "doc_type", "value": ["Invoice", "Receipt", "Credit Note"]}}
}
ステータスの除外(NIN)
{
"where": {"nin": {"field": "doc_status", "value": ["Draft", "Archived"]}}
}
複雑なネストされた OR + AND
Acme Corp の請求書、または2025年の報告書:
{
"where": {
"or": [
{"and": [
{"eq": {"field": "doc_type", "value": "Invoice"}},
{"eq": {"field": "from_entity", "value": "Acme Corp"}}
]},
{"and": [
{"eq": {"field": "doc_type", "value": "Report"}},
{"gte": {"field": "entry_date", "value": "2025-01-01"}}
]}
]
}
}
NOT 演算子
{
"where": {"not": {"eq": {"field": "from_entity", "value": "Acme Corp"}}}
}
ページネーション
{
"where": {"fts": {"field": "content", "query": "contract"}},
"limit": 50,
"offset": 100
}
送信者のドキュメントを日付で全文検索
{
"where": {
"and": [
{"fts": {"field": "content", "query": "\"quarterly review\""}},
{"eq": {"field": "from_entity", "value": "Widget Inc"}},
{"gte": {"field": "date", "value": "2025-01-01"}},
{"ne": {"field": "doc_status", "value": "Draft"}}
]
},
"select": ["id", "description", "date", "doc_status", "_score", "_highlights"],
"options": {"include_highlights": true},
"sort": [{"field": "_score", "direction": "desc"}],
"limit": 25
}
cURL
curl -i -X POST \
"https://portal.docwize.com/apiv2/pub/search" \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"where": {
"and": [
{"fts": {"field": "content", "query": "compliance"}},
{"eq": {"field": "doc_type", "value": "Report"}}
]
},
"select": ["id","description","_score","_highlights"],
"options": {"include_highlights": true},
"limit": 20
}'
{
"total": 142,
"offset": 0,
"limit": 20,
"results": [
{
"id": 1542,
"description": "Supply Chain Risk Assessment",
"_score": 4.238901,
"_highlights": [
"...the <b>compliance</b> audit identified..."
]
},
{
"id": 1601,
"description": "Annual Compliance Review",
"_score": 3.891204,
"_highlights": [
"...regulatory <b>compliance</b> requirements..."
]
}
]
}