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

# Auth0 User Search の Lucene クエリ構文と例

> Auth0 User Search バージョン 3 向けの Lucene クエリ構文の詳細と例を紹介します。

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [displayText, setDisplayText] = useState(children);
  const [copyText, setCopyText] = useState(children);
  const wrapperRef = React.useRef(null);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      if (!window.autorun || !window.rootStore) {
        return;
      }
      unsubscribe = window.autorun(() => {
        let processedChildrenForDisplay = children;
        let processedChildrenForCopy = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
          let displayValue = value;
          if (key === "{yourClientSecret}" && value !== "{yourClientSecret}") {
            displayValue = value.substring(0, 3) + "*****MASKED*****";
          }
          processedChildrenForDisplay = processedChildrenForDisplay.replaceAll(new RegExp(escapedKey, "g"), displayValue);
          processedChildrenForCopy = processedChildrenForCopy.replaceAll(new RegExp(escapedKey, "g"), value);
        }
        setDisplayText(processedChildrenForDisplay);
        setCopyText(processedChildrenForCopy);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  useEffect(() => {
    if (!wrapperRef.current) return;
    const originalWriteText = navigator.clipboard.writeText.bind(navigator.clipboard);
    let isOverriding = false;
    const handleClick = e => {
      const button = e.target.closest('[data-testid="copy-code-button"]');
      if (!button || !wrapperRef.current.contains(button)) return;
      isOverriding = true;
      navigator.clipboard.writeText = text => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
          return originalWriteText(copyText);
        }
        return originalWriteText(text);
      };
      setTimeout(() => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
        }
      }, 100);
    };
    const wrapper = wrapperRef.current;
    wrapper.addEventListener('click', handleClick, true);
    return () => {
      wrapper.removeEventListener('click', handleClick, true);
      if (navigator.clipboard.writeText !== originalWriteText) {
        navigator.clipboard.writeText = originalWriteText;
      }
    };
  }, [copyText]);
  return <div ref={wrapperRef}>
      <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
        {displayText}
      </CodeBlock>
    </div>;
};

[ユーザーを一覧表示](./list-and-search-users)する際は、Lucene クエリ構文の検索クエリを使用して結果を絞り込めます。

正式なリファレンスは[Lucene クエリ構文リファレンス](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html)ですが、概略としては、クエリ文字列は一連のタームとブール演算子として解析されます。

<div id="terms">
  ## ターム
</div>

[ターム](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Terms) は、検索対象の文字列を定義します。タームでは、フィールド、ワイルドカード、範囲を指定できます。

<div id="fields">
  ### フィールド
</div>

[フィールド](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Fields)は、指定した文字列をどこで検索するかを定義します。[ユーザープロファイル属性の一覧](/docs/ja-jp/manage-users/user-accounts/user-profiles/user-profile-structure)で、検索可能なフィールドを確認できます。

* [正規化されたユーザープロファイルフィールド](/docs/ja-jp/manage-users/user-accounts/user-profiles/normalized-user-profile-schema) (`email`、`name`、`given_name`、`family_name`、`nickname`) の検索値では大文字と小文字が区別されません。これ以外のすべての検索値では、大文字と小文字が区別されます。

* boolean、integer、double、text、object、またはarrayのデータ型を持つ`app_metadata`および`user_metadata`フィールドを検索できます。

* 空のarray、空のobject、または`null`値を含むメタデータフィールドは、それらの値がインデックス化されないため検索できません。

* フィールド名を指定しないタームは、`user_metadata`に一致しません。

| 検索条件                         | クエリの例                                   |
| ---------------------------- | --------------------------------------- |
| 名前が完全に"eugenio"であるユーザー       | `name:"eugenio"`                        |
| メールドメインが`example.com`であるユーザー | `email.domain:"example.com"`            |
| 特定の接続を使用するユーザー               | `identities.connection:"google-oauth2"` |

メタデータを検索する際は、フィールドへのパスを使用してネストされた値を検索できます。フィールドがarray内にネストされている場合は、arrayの階層を無視できます。たとえば、次の`user_metadata`構造の場合:

```json theme={null}
{
  "full_name": "Example Name",
  "display": {
    "preferredLanguage": "en",
    "fontSize": 13
  },
  "addresses":{
    "cities": [ "Paris", "Seattle" ]
  }
}
```

| 検索条件                       | クエリ例                                                  |
| -------------------------- | ----------------------------------------------------- |
| 氏名が "Example Name" であるユーザー | `user_metadata.full_name:"Example Name"`              |
| 優先言語を設定しているユーザー            | `q: _exists_:user_metadata.display.preferredLanguage` |
| フォントサイズが13に設定されているユーザー     | `q: user_metadata.display.fontSize:13`                |
| 都市にParisが含まれるユーザー          | `q: user_metadata.addresses.cities:"Paris"`           |

<div id="wildcards">
  ### ワイルドカード
</div>

[ワイルドカード](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Wildcard%20Searches)では、`*` 構文を使用して複数の文字を検索できます。

* 接尾辞一致では、リテラルは3文字以上である必要があります。たとえば、`name:*abc` は使用できますが、`name:*ab` は使用できません。

* `user_metadata` はワイルドカードで検索できません。

| 検索条件                   | クエリの例            |
| ---------------------- | ---------------- |
| 名前に「example」を含むユーザー    | `name:*example*` |
| メールアドレスが「test」で始まるユーザー | `email:test*`    |

<div id="ranges">
  ### 範囲
</div>

[範囲](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Range%20Searches)では、指定した下限値から上限値までの範囲にある値を検索できます。

* `user_metadata` を範囲検索することはできません。

| 検索条件                   | クエリの例                                   |
| ---------------------- | --------------------------------------- |
| ログイン回数が9回以下のユーザー       | `logins_count:[* TO 10}`                |
| ログイン回数が10回から99回のユーザー   | `logins_count:[10 TO 100}`              |
| ログイン回数が100回以上のユーザー     | `logins_count:[100 TO *]`               |
| 2025年より前に最後にログインしたユーザー | `last_login:[* TO 2024-12-31]`          |
| 最終ログインが2025年12月のユーザー   | `last_login:[2025-12-01 TO 2025-12-31]` |

<div id="boolean-operators">
  ## ブール演算子
</div>

[ブール演算子](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Boolean%20operators)は、タームを論理的に組み合わせるために使用します。ブール演算子は、すべての正規化されたユーザープロファイルのフィールドとルートメタデータのフィールドで使用できます。

| 検索条件                                        | クエリ例                                                  |
| ------------------------------------------- | ----------------------------------------------------- |
| 名前が「example name」または「test user」と完全に一致するユーザー | `name:("example name" OR "test user")`                |
| 検証済みのメールアドレスを持たないユーザー                       | `NOT _exists_:email_verified OR email_verified:false` |
| 一度もログインしたことがないユーザー                          | `NOT _exists_:logins_count OR logins_count:0`         |
