Search with a quoted phrase plus other words returns the whole catalog

Open Beginner friendly
#6,567 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
search

Research direction

The issue points to app/search/queries/registry.py and names parse_search_query, build_base_query, and unit tests to add. Read build_base_query and the existing query tests first. Done means phrase-plus-word and two-phrase searches require every term to match, while a phrase with no matches returns no results.

Written by the indexing model from the issue text.

Description

bug

A catalog search that combines a quoted phrase with plain words, without OR, ignores the search and returns the whole catalog sorted by popularity.

  • Environment: prod catalog.data.gov
  • Component: datagov-catalog search, app/search/queries/registry.py

How to reproduce

  1. Search https://catalog.data.gov/search?q=%22baby%20names%22%20california
  2. Compare with https://catalog.data.gov/search?q=%22baby%20names%22
  3. Try a phrase that matches nothing: https://catalog.data.gov/search?q=%22zzzqqq%20nomatch%22%20california

Expected behavior

  • Results must contain the phrase "baby names" and the word "california".
  • A phrase that matches nothing returns no results.

Actual behavior

  • The first and third searches both return the whole catalog, starting with "Electric Vehicle Population Data".
  • parse_search_query returns two terms with has_or false. build_base_query only handles one term in that case and otherwise falls back to {"match_all": {}}. The comment there says "Shouldn't happen, but fall back to match_all".

Sketch

  • When there's more than one term and no OR, combine them with a bool must, so every phrase and word has to match
  • Add unit tests for a phrase plus a word, and for two phrases without OR
Dominant language
Python
Stars
1.2k
Forks
207
Avg merge
3d 16h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GSA/data.gov

All issues in GSA/data.gov

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.