> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-mintlify-8476678c.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# レジストリ項目を検索する

> グローバル検索バーまたはクエリを使用して、W&B Registry でレジストリ、コレクション、アーティファクトバージョンを検索する方法を説明します。

[W\&B Registry のグローバル検索バー](./search_registry#search-for-registry-items)を使用して、レジストリ、コレクション、アーティファクトバージョンタグ、コレクションタグ、またはエイリアスを検索できます。W\&B Python SDK では、クエリを使用して、特定の条件に基づいて[レジストリ、コレクション、アーティファクトバージョンを絞り込む](/ja/models/registry/search_registry#query-registry-items)こともできます。

<Info>
  W\&B Registry のクエリに使用できる構文と演算子は MongoDB のクエリに似ていますが、同一ではありません。
</Info>

検索結果には、表示権限のある項目のみが表示されます。

<div id="search-for-registry-items">
  ## レジストリ内の項目を検索する
</div>

W\&B App を使用して レジストリ項目を検索します。

1. W\&B Registry にアクセスします。
2. ページ上部の検索バーに検索語を入力します。Enter キーを押して検索します。

入力した語が既存の レジストリ、コレクション 名、アーティファクト バージョンタグ、コレクション タグ、または エイリアス と一致する場合、検索結果が検索バーの下に表示されます。

<div id="query-registry-items">
  ## レジストリ項目をクエリする
</div>

[`wandb.Api().registries()`](/ja/models/ref/python/public-api/api#registries) と *クエリ述語* を使用して、レジストリ、コレクション、アーティファクト バージョンをフィルターします。クエリ述語は、返される項目が満たすべき条件を指定するものです。

クエリ述語を作成するには、[クエリ名](/ja/models/registry/search_registry#filterable-fields)、1 つ以上の [演算子](/ja/models/registry/search_registry#supported-operators)、および値で構成される JSON 形式に似た辞書を使用します。次のコードスニペットは、クエリ述語の一般的な構造を示しています。

```python theme={null}
{
    "query_name": {
        "operator": value
    }
}
```

以下のセクションでは、レジストリで使用可能な[クエリ名](/ja/models/registry/search_registry#filterable-fields)、[サポートされる演算子](/ja/models/registry/search_registry#supported-operators)、および[クエリの例](/ja/models/registry/search_registry#example-queries)について説明します。

<div id="filterable-fields">
  ### フィルター可能なフィールド
</div>

次の表は、フィルターする項目のタイプに応じて使用できるクエリ名を示しています。

|        | クエリ名                                                     |
| ------ | -------------------------------------------------------- |
| レジストリ  | `name`, `description`, `created_at`, `updated_at`        |
| コレクション | `name`, `tag`, `description`, `created_at`, `updated_at` |
| バージョン  | `tag`, `alias`, `created_at`, `updated_at`, `metadata`   |

<div id="supported-operators">
  ### サポートされている演算子
</div>

W\&B は、レジストリ項目を絞り込むために、次の比較演算子および論理演算子をサポートしています。

<div id="comparison-operators">
  #### 比較演算子
</div>

| 演算子    | 説明    |
| ------ | ----- |
| `$eq`  | 等しい   |
| `$ne`  | 等しくない |
| `$gt`  | より大きい |
| `$gte` | 以上    |
| `$lt`  | より小さい |
| `$lte` | 以下    |

<div id="logical-operators">
  #### 論理演算子
</div>

| 演算子    | 説明                                                                            |
| ------ | ----------------------------------------------------------------------------- |
| `$and` | 1 つ以上の条件に対して [AND](https://en.wikipedia.org/wiki/Logical_conjunction) 演算を行います |
| `$or`  | 1 つ以上の条件に対して [OR](https://en.wikipedia.org/wiki/Logical_disjunction) 演算を行います  |
| `$nor` | 1 つ以上の条件に対して [NOR](https://en.wikipedia.org/wiki/Logical_NOR) 演算を行います         |
| `$not` | 条件に対して [NOT](https://en.wikipedia.org/wiki/Negation) 演算を行います                  |

<div id="other-operators">
  #### その他の演算子
</div>

| 演算子         | 説明          |
| ----------- | ----------- |
| `$regex`    | 正規表現パターンに一致 |
| `$exists`   | フィールドの有無    |
| `$contains` | 文字列に値を含む    |

<div id="example-queries">
  ### クエリの例
</div>

以下のコード例では、一般的な検索パターンをいくつか示します。

`wandb.Api().registries()` methodを使用するには、まずW\&B Python SDK ([`wandb`](/ja/models/ref/python/)) ライブラリをインポートします。

```python theme={null}
import wandb

# (Optional) 読みやすくするために wandb.Api() クラスのインスタンスを作成する
api = wandb.Api()
```

`model` という文字列を含むすべてのレジストリを絞り込みます:

```python theme={null}
# `model` という文字列を含むすべてのレジストリをフィルターします
registry_filters = {
    "name": {"$regex": "model"}
}

# フィルターに一致するすべてのレジストリのイテラブルを返します
registries = api.registries(filter=registry_filters)
```

レジストリに関係なく、コレクション名に文字列 `yolo` を含むすべてのコレクションをフィルターするには、次のようにします:

```python theme={null}
# レジストリに関係なく、コレクション名に文字列 `yolo` を含む
# すべてのコレクションをフィルターします
collection_filters = {
    "name": {"$regex": "yolo"}
}

# フィルターに一致するすべてのコレクションのイテラブルを返します
collections = api.registries().collections(filter=collection_filters)
```

コレクション名に文字列 `yolo` を含み、タグに `cnn` を持つ、レジストリに関係なくすべてのコレクションをフィルターします:

```python theme={null}
# レジストリに関係なく、コレクション名に文字列 `yolo` を含み、タグに `cnn` を持つ
# すべてのコレクションをフィルターします
collection_filters = {
    "name": {"$regex": "yolo"},
    "tag": "cnn"
}

# フィルターに一致するすべてのコレクションのイテラブルを返します
collections = api.registries().collections(filter=collection_filters)
```

文字列 `model` を含み、タグ `image-classification` またはエイリアス `latest` のいずれかを持つアーティファクト のすべてのバージョンを検索します:

```python theme={null}
# 文字列 `model` を含み、タグ `image-classification` またはエイリアス `latest` のいずれかを持つ
# アーティファクトのすべてのバージョンを検索します
registry_filters = {
    "name": {"$regex": "model"}
}

# 論理演算子 $or を使用してアーティファクト バージョンをフィルターします
version_filters = {
    "$or": [
        {"tag": "image-classification"},
        {"alias": "production"}
    ]
}

# フィルターに一致するすべてのアーティファクト バージョンのイテラブルを返します
artifacts = api.registries(filter=registry_filters).collections().versions(filter=version_filters)
```

前のコードスニペットの `artifacts` イテラブル内の各要素は、`Artifact` クラスのインスタンスです。つまり、各 アーティファクト の `name`、`collection`、`aliases`、`tags`、`created_at` などの属性にアクセスできます。

```python theme={null}
for art in artifacts:
    print(f"artifact name: {art.name}")
    print(f"collection artifact belongs to: { art.collection.name}")
    print(f"artifact aliases: {art.aliases}")
    print(f"tags attached to artifact: {art.tags}")
    print(f"artifact created at: {art.created_at}\n")
```

アーティファクト オブジェクトの属性の完全な一覧については、API Reference ドキュメントの [Artifacts Class](/ja/models/ref/python/experiments/artifact/) を参照してください。

レジストリ や コレクション に関係なく、2024-01-08 から 2025-03-04 13:10 UTC の間に作成されたすべての アーティファクト バージョンをフィルターします:

```python theme={null}
# 2024-01-08 から 2025-03-04 13:10 UTC の間に作成されたすべてのアーティファクト バージョンを検索します。 

artifact_filters = {
    "alias": "latest",
    "created_at" : {"$gte": "2024-01-08", "$lte": "2025-03-04 13:10:00"},
}

# フィルターに一致するすべてのアーティファクト バージョンのイテラブルを返します
artifacts = api.registries().collections().versions(filter=artifact_filters)
```

<Note>`created_at` および `updated_at` のクエリでは、日時を `YYYY-MM-DD HH:MM:SS` 形式で指定します。日付のみでフィルターする場合は、時・分・秒を省略できます。</Note>
