golang/go

x/text/search: `Backwards` as an IndexOption not implemented

Open

#59,049 opened on Mar 15, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Go (19,008 forks)batch import
FeatureRequestNeedsInvestigationhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

x/text/search has an explicit implementation todo panic if you attempt to search backwards in text. Presumably, this is to support RTL languages, but the utility isn't clear. It would be nice to implement it if it's useful, or at the very least document that it can't be used.

For context, my use case involves query-driven scanning of string fields in streams of structured data for keywords in various languages, so I can see this being useful when combined with an appropriate language tag, though in my case it ends up being just a boolean match, so start >= 0 is fine for now.

As a side note, the package comments include the following todos:

  • Maybe IndexAll methods (probably not necessary).
  • Some way to match patterns in a Reader (a bit tricky).
  • Some fold transformer that folds text to comparable text, based on the search options. This is a common technique, though very different from the collation-based design of this package. It has a somewhat different use case, so probably makes sense to support both. Should probably be in a different package, though, as it uses completely different kind of tables (based on norm, cases, width and range tables.)

I could see the last of these being useful to me in lieu of stemming or lemmatization, and the longstanding #16863 suggests that maybe x/text/search could use a little love. If @mpvl or anyone else would be willing to give me some guidance, I'd be willing to try and carve off some cycles to clear these out.

What version of Go are you using (go version)?

n/a

Does this issue reproduce with the latest release?

Yes, it is currently in the code here: https://github.com/golang/text/blob/master/search/search.go#L192-L193

What operating system and processor architecture are you using (go env)?

n/a

What did you do?

attempted to use Backwards as an IndexOption

What did you expect to see?

Not a panic.

What did you see instead?

panic: TODO: implement

Contributor guide