Skip to content

fix: keyword search and country filter don't combine correctly in Algolia search / キーワード検索と国名フィルタが正しく併存しない #578

Description

@zigzagdev

Motivation / 目的

Fix a bug in AlgoliaWorldHeritageSearchAdapter::search() where combining a free-text keyword with a resolved country (country_name/country_iso3, whether given explicitly or auto-detected from the keyword itself) silently drops the keyword and returns every site in that country instead of narrowing by both.

AlgoliaWorldHeritageSearchAdapter::search()のバグ修正です。自由テキストのkeywordと、解決済みの国名(country_name/country_iso3。明示指定でもkeyword自動判定でも)を同時に使うと、keywordが握りつぶされ、両方で絞り込むべきところがその国の全遺産を返してしまいます。

現状の問題 / Current problem

  • country_iso3が確定すると$queryStringを強制的に空文字にしている(AlgoliaWorldHeritageSearchAdapter.php:44-48)。
  • そのためkeywordと国指定を同時に使うと、keyword側の条件が無視される。
  • 実測で確認済み: query="temple" + filters=state_party_codes:JPNは本来2件(日本の寺院関連遺産)を返すべきだが、現状の実装はqueryが空にされるため26件(日本の全遺産)が返る。
  • 他の全フィルタ(region/category/year_inscribed/criteria/is_endangered)はkeywordと正しく共存しており、国フィルタだけがこの例外的挙動を持っている(一貫性が無い)。

検討したが不要と判断した対応 / Considered and ruled out

  • 「jap」「nihon」のような国名の略称・ローマ字がヒットしないのでは、という懸念を最初に持ったが、実インデックス検証で否定された。country/country_name_jp/state_party_codesが既にsearchableAttributesに含まれているため、Algolia自身のprefix/トークンマッチだけで国名バリエーションを正しく拾えている(jap→25件、jpn→26件、日本→26件、フィルタのみ→26件、と一致)。CountryResolverの精度改善は不要。

解決策 / Solution

  • AlgoliaWorldHeritageSearchAdapter::search()から$queryString = '';を削除する。
  • 国名/国コードの特別扱いを撤廃し、「フィルタはkeywordを絶対に上書き・消去しない」という、他のフィルタと同じ単一ルールに統一する。

Sub-issues / サブIssue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions