searchwp\query\logic\and\token_threshold
since: 4.1.12
ANDロジックパスを実行するかどうかを決定する際にSearchWPが考慮するしきい値を制御します。
ANDロジックはリソースの点で問題となる可能性があり、場合によってはクエリ時間が長くなることがあります。
SearchWPの関連性アルゴリズムにより、検索語が多すぎるためにANDロジックをスキップしても、最も関連性の高い結果が最初に表示されるため結果の品質は低下しません。ANDロジックの利点は、すべての検索語を含む結果が少なくなることですが、ANDロジックをスキップしても全体の結果に大きな影響はないでしょう。
このしきい値は完全に制御可能であり、ニーズに最も適した実行時にしきい値をカスタマイズできます。
関連項目: searchwp\query\logic\and
パラメータ
| タイプ | パラメータ | デフォルト | 提供開始 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 整数 | $threshold |
5 | 4.1.12 |
|||||||||
| 配列 |
$args
|
4.1.12 |
||||||||||
例
すべてのフックはカスタムのSearchWP カスタマイズプラグインに追加する必要があります。
ANDロジックのトークンしきい値を無効にする
| <?php | |
| // Disable SearchWP AND logic token threshold, allowing AND logic for all searches. | |
| // @link https://searchwp.com/documentation/hooks/searchwp-query-logic-and-token_threshold/ | |
| add_filter( 'searchwp\query\logic\and\token_threshold', '__return_false' ); |
ANDロジックのトークンしきい値を制御する
現在の検索の検索トークンに基づいてANDロジックのしきい値をカスタマイズします。
| <?php | |
| // Control SearchWP AND logic token threshold. | |
| // @link https://searchwp.com/documentation/hooks/searchwp-query-logic-and-token_threshold/ | |
| add_filter( 'searchwp\query\logic\and\token_threshold', function( $threshold, $args ) { | |
| // If the search contains 'coffee' allow up to 10 tokens for AND logic. | |
| if ( in_array( 'coffee', $args['tokens'], true ) ) { | |
| $threshold = 10; | |
| } | |
| // If the search contains 'soccer' disable AND logic token threshold. | |
| if ( in_array( 'soccer', $args['tokens'], true ) ) { | |
| $threshold = false; | |
| } | |
| return $threshold; | |
| }, 20, 2 ); |

