Add incremental search index and boolean/phrase query support#16
Add incremental search index and boolean/phrase query support#16
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a805c1e9f0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if prev != nil && needsImplicitAnd(*prev, tok) { | ||
| tokens = append(tokens, token{kind: tokenAnd}) | ||
| } | ||
| tokens = append(tokens, tok) | ||
| prev = &tok |
There was a problem hiding this comment.
Fix implicit AND insertion using range variable pointer
Because prev is set to &tok from a Go range loop, it always points to the loop variable that gets reused on each iteration. That means needsImplicitAnd(*prev, tok) is comparing the current token to itself instead of the previous token, so an implicit AND is inserted before every term/phrase regardless of the actual prior token. Queries with explicit operators or parentheses (e.g., a OR b, a (b)) will be rewritten incorrectly (e.g., a OR AND b) and can fail parsing or change meaning. Use a separate prevToken value or index-based loop so the previous token is preserved.
Useful? React with 👍 / 👎.
Motivation
jot search <query>against the local journal.Description
~/.jot/index.jsonwithsearch_index.gothat hashes lines, reuses unchanged entries, and builds a term->entry map.search_query.gowith implicitAND, operator precedence, and conversion to RPN for evaluation.jot searchwiring inmain.gowhich updates the index viaUpdateIndexand prints matching entries returned bySearchIndex.search_index_test.gocovering incremental update behavior and boolean/phrase queries, plusBenchmarkIndexing1kandBenchmarkSearch1kfor latency measurements.Testing
go test ./...and they passed (okfor the package).Codex Task