stac-utils / stac-utils/pgstac

Free-text searches with minus (-) and plus (+) signs do not behave as expected

Open Beginner friendly
#459 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PLpgSQL
Stars
223
Forks
57
PR merge metrics
No merged PRs in 30d

Description

version: v0.9.9

Description

I noticed a possible issue with free-text searches (?q=) when the dash (-) symbol is present after an initial word.

From here, I would expect the dash symbol to be translated into the & ! SQL operator, when coming not at the start of the string, only if preceded by a blank space. This sounds reasonable to me, as it would allow for searching dash-separated words, e.g. "first-generation", without it being interpreted as first & ! generation. What I observe, though, is that the - symbol is always interpreted as & !, regardless of the presence of blank spaces before it.

Possible solution

As far as I understand, this behaviour is controlled by this line https://github.com/stac-utils/pgstac/blob/df08f9bd66ddb057133bfcc8d7a6228ac791e49e/src/pgstac/sql/004_search.sql#L181

A possible could be to replace it with

processed_text := regexp_replace(processed_text, '\s+\-([a-zA-Z0-9_]+)', ' & ! \1', 'g');

The same considerations apply to the + term.

Contributor guide

Open the contributing guide

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.

Research direction

Start in src/pgstac/sql/004_search.sql at the regexp_replace line linked in the issue, and compare how free-text searches handle minus and plus terms. Verify that signs in dash-separated words are preserved while signs preceded by spaces retain their operator behavior. Done means both minus and plus searches match the documented expectations.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, sql
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.