stac-utils / stac-utils/pgstac
Free-text searches with minus (-) and plus (+) signs do not behave as expected
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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