memoria: review fixes (GPT-6 Astra) — kind matches fill, never rank; hits don't renew
- §8.12: the words' own top 25 is taken first, and kind tokens only fill what is left (Index.SearchKinds, kinds column alone). ORing the tokens in let their IDF push the office page out of the top 25 on Astra's corpus, and the box guessed a supplier's number. KindsWeight did nothing once tokens match alone, and is removed. - §8.11 cache: a hit is not stored again, so ten minutes means ten. - Tests for Astra's surviving mutants: key order, notices on a hit, escaped unbalanced fallback, unchanged-source revision, handle purpose, typing fill, every kind filled, NoBox values counted, and Astra's corpus itself. Every one seen red.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+228
−51
README.md+3 −1docs/superpowers/specs/2026-09-03-memoria-design.md+31 −12internal/memoria/ai.go+10 −2internal/memoria/ai_test.go+37 −0internal/memoria/feedback_test.go+12 −1internal/memoria/index/index.go+28 −27internal/memoria/kindwords_test.go+78 −5internal/memoria/store.go+29 −3
CI passed — run details
diff --git a/README.md b/README.md| index 6a61622..9eb4dd6 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -27,7 +27,9 @@ cites the passages it rests on, and one citing nothing is not shown; the |
| AI may use bold and bullet points and nothing else. It runs only once |
| you stop typing, never on a keystroke. The reply is kept **in memory** |
| for ten minutes, so asking the same question about the same passages |
| -again — Enter, a reload — does not send them again. 👍 / 👎 under an |
| +again — Enter, a reload — usually does not send them again: it does |
| +when the passages have changed, after a failed or late answer, and once |
| +the reply has aged out or been pushed out by newer ones. 👍 / 👎 under an |
| answer are kept, sealed, on Reports: the query, your note and which |
| passages it cited, never the answer's words. It never asks for a calculation: a search |
| for an average, a total or a count gets no AI answer. To decide whether |
diff --git a/docs/superpowers/specs/2026-09-03-memoria-design.md b/docs/superpowers/specs/2026-09-03-memoria-design.md| index edf3657..a740d4a 100644 |
| --- a/docs/superpowers/specs/2026-09-03-memoria-design.md |
| +++ b/docs/superpowers/specs/2026-09-03-memoria-design.md |
| @@ -4433,8 +4433,10 @@ cite — never a rendered answer. Citations, titles, links and notices are |
| rebuilt on every request from that request's own ruled search, so the |
| ruled search still runs every time (§4.1 is asked every time) and a hit |
| skips only the model call. Only `answered` and `none` are cached; a |
| -late, failed or dropped answer asks again next time. At most **256** |
| -entries; the oldest goes first. Cached content is the same class as the |
| +late, failed or dropped answer asks again next time. **A hit is not |
| +stored again**, so ten minutes means ten minutes from the model's reply, |
| +however often it is asked for since (Astra: storing hits renewed them |
| +for ever). At most **256** entries; the oldest goes first. Cached content is the same class as the |
| in-memory index (§6.3) and dies with the process. |
| **Cost, amended again.** Repeating the same question — Enter, a reload, |
| @@ -4457,13 +4459,24 @@ matches"* — the plausible-empty-list failure, said confidently. |
| validator-backed kinds (§8.8: eircode, phone, IBAN, VAT, email), and the |
| kinds it holds are written into a fifth FTS column, `kinds`, as **private |
| tokens** — `xkindeircode`, `xkindphone` (`fact.KindToken`). At query |
| -time, the kinds the query names (`fact.Wanted`, the same lexicon as the |
| -box) add their tokens to the search as more OR terms. So `Eircode`, |
| -`Postcode` and `post code` all add `xkindeircode`, and find every |
| -passage holding a valid eircode. A passage holding an eircode also |
| -carries the postal kind's token, `xkindaddress`: an eircode is part of a |
| -postal address, and this is what lets *"office address"* find a passage |
| -that writes `Location: … D02 X285` with no word "address" in it. |
| +time, the words are searched first, **exactly as before**; then, if they |
| +left room under the limit, the kinds the query names (`fact.Wanted`, the |
| +same lexicon as the box) fill it from the `kinds` column alone |
| +(`Index.SearchKinds`). So `Eircode`, `Postcode` and `post code` find |
| +every passage holding a valid eircode, after any passage that says the |
| +word. A passage holding an eircode also carries the postal kind's token, |
| +`xkindaddress`: an eircode is part of a postal address, and this is what |
| +lets *"office address"* find a passage that writes `Location: … D02 |
| +X285` with no word "address" in it. |
| + |
| +**Fill, never rank.** The first build ORed the tokens into the words' |
| +query with a low column weight, and the weight could not hold: a token |
| +in few rows has a high IDF, so on a corpus with many passages saying |
| +"phone" and a few only holding numbers, twenty-five supplier numbers |
| +outranked every word match, the office page fell out of the top 25, and |
| +the box guessed a supplier's number (Astra, 2026-10-27, reproduced). |
| +Taking the words' results first makes "finds, never reorders" |
| +structural: a kind match can only take a place no word match wanted. |
| **Tokens, not the words — and this is §12's own objection answered, not |
| overruled.** §12 said the fix *"is not 'index the kind words'"*, because |
| @@ -4474,9 +4487,9 @@ nobody writes has its own IDF and leaves every real word's alone, so a |
| passage that says "phone" ranks as it did. Gate 44 re-takes §8.8's |
| measurement to hold it. |
| -- **Weight below every other column** (`KindsWeight`, 0.25), so a |
| - passage holding the kind and sharing the query's words ranks with |
| - those words, and one that only holds the kind ranks below them. |
| +- **No weight of its own.** Only `SearchKinds` matches the column, and |
| + alone, so its weight cannot change an order; the column takes FTS5's |
| + default. A `KindsWeight` was built, did nothing, and was removed. |
| - **Not shown.** `snippet()` stays on body; the tokens never appear in a |
| result. |
| - **Validators only.** A span counts if the validator accepts it, |
| @@ -4517,6 +4530,12 @@ kind's name or "office": |
| and **§8.8's measurement re-taken** — twenty |
| passages each holding a number, one saying "phone", that one first and |
| far ahead; |
| +- **a kind match never displaces a word match**: Astra's corpus — the |
| + office page, twenty-five number-only suppliers, a hundred passages |
| + that say "phone" and hold no number — still answers "what is the |
| + office phone number?" with the office number; |
| +- the fill reaches the typing path and every kind a query names; |
| +- a NoBox value still counts as a value the passage holds; |
| - **narrowing survives the extra recall**: gate 40's office page among |
| a dozen passages that hold other numbers and never say "phone" still |
| answers "what is the office phone number?" with the office number |
diff --git a/internal/memoria/ai.go b/internal/memoria/ai.go| index 61f86a5..b0eb9b9 100644 |
| --- a/internal/memoria/ai.go |
| +++ b/internal/memoria/ai.go |
| @@ -171,7 +171,9 @@ func (s *Store) Answer(ctx context.Context, asker suite.Subject, q string) (*AIA |
| return out, nil |
| case len(sentences) == 0: |
| out.State = AnswerNone |
| - s.answers.put(key, sentences) |
| + if !hit { |
| + s.answers.put(key, sentences) |
| + } |
| return out, nil |
| } |
| for _, sn := range sentences { |
| @@ -215,7 +217,13 @@ func (s *Store) Answer(ctx context.Context, asker suite.Subject, q string) (*AIA |
| out.State = AnswerDropped |
| return out, nil |
| } |
| - s.answers.put(key, sentences) |
| + // Only a fresh reply is stored. A hit stored again would restart its |
| + // ten minutes, so an answer asked for every nine minutes would live |
| + // for ever, and eviction would become least-recently-used instead of |
| + // oldest (Astra, 2026-10-27). |
| + if !hit { |
| + s.answers.put(key, sentences) |
| + } |
| out.State = AnswerShown |
| h := feedbackHandle{Asker: asker.Value, Query: q, Provider: out.Provider, Model: out.Model} |
| for _, r := range sent { |
diff --git a/internal/memoria/ai_test.go b/internal/memoria/ai_test.go| index 4449b65..29029bb 100644 |
| --- a/internal/memoria/ai_test.go |
| +++ b/internal/memoria/ai_test.go |
| @@ -258,6 +258,9 @@ func TestTheAIFormatsOnlyBoldAndBullets(t *testing.T) { |
| {"**a** and **b**", "<strong>a</strong> and <strong>b</strong>"}, |
| {"unbalanced ** stays", "unbalanced ** stays"}, |
| {"**<img src=x onerror=alert(1)>**", "<strong><img src=x onerror=alert(1)></strong>"}, |
| + // The unbalanced fallback is escaped too. Mutation: it returning |
| + // the raw text → red. |
| + {"<b>x</b> ** odd", "<b>x</b> ** odd"}, |
| {"[a link](https://evil.example)  # heading `code`", |
| "[a link](https://evil.example)  # heading `code`"}, |
| } { |
| @@ -344,6 +347,19 @@ func TestTheAnswerCache(t *testing.T) { |
| if _, _ = s.Answer(ctx, paul, q); len(f.calls) != 4 { |
| t.Errorf("expired: an answer %v old was reused (%d calls)", AnswerCacheTTL, len(f.calls)) |
| } |
| + // A hit does not restart the clock: asked at 0, 9 and 11 minutes, |
| + // the third is a fresh call. Mutation: hits stored again → "renewed". |
| + clock = clock.Add(9 * time.Minute) |
| + s.Answer(ctx, paul, q) |
| + clock = clock.Add(2 * time.Minute) |
| + if _, _ = s.Answer(ctx, paul, q); len(f.calls) != 5 { |
| + t.Errorf("renewed: a hit restarted the cache's clock (%d calls)", len(f.calls)) |
| + } |
| + // Order is part of the key: a block cites passages by their place in |
| + // what was sent. Mutation: chunk ids sorted before hashing → red. |
| + if answerKey(paul, q, []int64{1, 2}) == answerKey(paul, q, []int64{2, 1}) { |
| + t.Error("order: the same passages in another order are the same key") |
| + } |
| // A changed passage is a different key. |
| s2, f2 := corpus(t) |
| @@ -357,6 +373,27 @@ func TestTheAnswerCache(t *testing.T) { |
| t.Errorf("a changed passage reused the old answer (%d calls)", len(f2.calls)) |
| } |
| + // A hit still carries this request's notices: only the model's reply |
| + // is cached, never what the ruled search said. Mutation: notices |
| + // dropped on a hit → "notices". |
| + cusN := &perItemCustody{apps: roster} |
| + sN := factCorpus(t, cusN, [][3]string{ |
| + {"p", "Paul Campbell", "## Roles\n\nPaul Campbell is Chief Executive Officer."}, |
| + {"h", "Hidden", "## Roles\n\nPaul Campbell chairs the hidden board."}, |
| + }) |
| + fN := &fakeAnswerer{reply: reply} |
| + sN.answerer = fN |
| + cusN.give = map[string]suite.Authorization{"h": suite.UNKNOWN} |
| + for i := 0; i < 2; i++ { |
| + a, err := sN.Answer(ctx, paul, q) |
| + if err != nil || a == nil || len(a.Notices) == 0 { |
| + t.Errorf("notices: ask %d carried no withholding notice: %+v, %v", i+1, a, err) |
| + } |
| + } |
| + if len(fN.calls) != 1 { |
| + t.Errorf("notices: the second ask was not a hit (%d calls)", len(fN.calls)) |
| + } |
| + |
| // Only answered and none are kept. |
| s3, f3 := corpus(t) |
| f3.reply = []provider.Sentence{{Text: "cites nothing", Cite: nil}} |
diff --git a/internal/memoria/feedback_test.go b/internal/memoria/feedback_test.go| index 33693bb..afe12a2 100644 |
| --- a/internal/memoria/feedback_test.go |
| +++ b/internal/memoria/feedback_test.go |
| @@ -55,7 +55,18 @@ func TestGate43Feedback(t *testing.T) { |
| } |
| want := a.Blocks()[0].Cites[0].Href |
| if len(list[0].Cited) != 1 || list[0].Cited[0].Href != want { |
| - t.Errorf("cited = %+v, want the one passage cited, %s", list[0].Cited, want) |
| + t.Fatalf("cited = %+v, want the one passage cited, %s", list[0].Cited, want) |
| + } |
| + // An unchanged source says nothing. Mutation: revisions recorded |
| + // as zero → "changed since" on a source nobody touched. |
| + if st := list[0].Cited[0].Status; st != "" { |
| + t.Errorf("an unchanged source says %q", st) |
| + } |
| + // The handle is sealed under its own purpose. Mutation: sealed as |
| + // feedback.body → it opens as a stored row. |
| + ct, _ := base64.RawURLEncoding.DecodeString(a.Feedback) |
| + if _, err := s.sealer.Open(seal.PurposeFeedback, ct); err == nil { |
| + t.Error("a handle opens under the stored row's purpose") |
| } |
| if _, err := s.SetFeedbackNote(ctx, paul, id, " it missed the CTO role "); err != nil { |
| t.Fatal(err) |
diff --git a/internal/memoria/index/index.go b/internal/memoria/index/index.go| index ff1da60..1798231 100644 |
| --- a/internal/memoria/index/index.go |
| +++ b/internal/memoria/index/index.go |
| @@ -189,8 +189,14 @@ func (i *Index) Count() (int, error) { |
| return n, err |
| } |
| -// Column weights for bm25(), in column order: heading, body, title, path, |
| -// kinds. |
| +// Column weights for bm25(), in column order: heading, body, title, path. |
| +// |
| +// The fifth column, kinds (§8.12), has no weight of its own and takes |
| +// FTS5's default. None is needed: only SearchKinds matches it, and it |
| +// matches that column alone, where scaling the one column's weight |
| +// cannot change the order. A KindsWeight was here and did nothing; the |
| +// store taking the words' results first is what keeps a kind match from |
| +// outranking a word match (Astra, 2026-10-27). |
| // |
| // HeadingWeight above BodyWeight because a passage under "Revenue" is a |
| // better answer to "revenue" than one that mentions the word in passing. |
| @@ -223,39 +229,34 @@ const ( |
| BodyWeight = 1.0 |
| TitleWeight = 1.0 |
| PathWeight = 0.5 |
| - // KindsWeight is below everything, path included (§8.12): the kinds |
| - // column FINDS passages that never say the word, and must not |
| - // reorder the ones that do. A passage that says "phone" outranks one |
| - // that only holds a number. Gate 44 measures it. |
| - KindsWeight = 0.25 |
| ) |
| -// Search runs a BM25 query, weighted by the constants above. kinds are |
| -// §8.12's private tokens (fact.KindToken) for the kinds the query names, |
| -// each ORed in as one more term. |
| -func (i *Index) Search(query string, limit int, kinds ...string) ([]Hit, error) { |
| - return i.search(withKinds(MatchQuery(query), kinds), limit) |
| +// Search runs a BM25 query, weighted by the constants above. |
| +func (i *Index) Search(query string, limit int) ([]Hit, error) { |
| + return i.search(MatchQuery(query), limit) |
| } |
| // SearchTyping is Search for live search's keystrokes: the last term |
| // matches as a prefix (MatchQueryTyping). Every other caller — a |
| // submitted page, Enter, a settled request, the native API — uses |
| // Search, where a word means the whole word. |
| -func (i *Index) SearchTyping(query string, limit int, kinds ...string) ([]Hit, error) { |
| - return i.search(withKinds(MatchQueryTyping(query), kinds), limit) |
| +func (i *Index) SearchTyping(query string, limit int) ([]Hit, error) { |
| + return i.search(MatchQueryTyping(query), limit) |
| } |
| -// withKinds ORs §8.12's kind tokens onto a MATCH expression. Only onto |
| -// one that already has terms: the tokens come from the query's own words, |
| -// so a query with none has none. |
| -func withKinds(match string, kinds []string) string { |
| - if match == "" { |
| - return "" |
| +// SearchKinds finds passages by §8.12's kind tokens alone |
| +// (fact.KindToken), restricted to the kinds column so a document that |
| +// happens to contain the token's spelling is not one. The store calls it |
| +// only to fill what the words' own search left of its limit. |
| +func (i *Index) SearchKinds(tokens []string, limit int) ([]Hit, error) { |
| + if len(tokens) == 0 { |
| + return nil, nil |
| } |
| - for _, k := range kinds { |
| - match += ` OR "` + k + `"` |
| + quoted := make([]string, len(tokens)) |
| + for n, t := range tokens { |
| + quoted[n] = `"` + t + `"` |
| } |
| - return match |
| + return i.search("kinds : ("+strings.Join(quoted, " OR ")+")", limit) |
| } |
| func (i *Index) search(q string, limit int) ([]Hit, error) { |
| @@ -274,14 +275,14 @@ func (i *Index) search(q string, limit int) ([]Hit, error) { |
| rows, err := i.db.Query(` |
| SELECT chunk_id, document_id, ordinal, heading, |
| snippet(chunks, 1, '<mark>', '</mark>', '…', 24), |
| - bm25(chunks, ?, ?, ?, ?, ?) |
| + bm25(chunks, ?, ?, ?, ?) |
| FROM chunks |
| WHERE chunks MATCH ? |
| - ORDER BY bm25(chunks, ?, ?, ?, ?, ?) |
| + ORDER BY bm25(chunks, ?, ?, ?, ?) |
| LIMIT ?`, |
| - HeadingWeight, BodyWeight, TitleWeight, PathWeight, KindsWeight, |
| + HeadingWeight, BodyWeight, TitleWeight, PathWeight, |
| q, |
| - HeadingWeight, BodyWeight, TitleWeight, PathWeight, KindsWeight, |
| + HeadingWeight, BodyWeight, TitleWeight, PathWeight, |
| limit) |
| if err != nil { |
| return nil, err |
diff --git a/internal/memoria/kindwords_test.go b/internal/memoria/kindwords_test.go| index 8abb488..afdd0ee 100644 |
| --- a/internal/memoria/kindwords_test.go |
| +++ b/internal/memoria/kindwords_test.go |
| @@ -20,11 +20,12 @@ import ( |
| // nothing else. |
| // |
| // MUTATION-TESTED 2026-10-27, each built and seen red, each reverted: |
| -// Kinds left out of the index entry, and the query's tokens not passed to |
| -// the search → "Deliveries holds one"; the eircode→address token removed |
| -// → "address finds []"; KindsWeight raised to HeadingWeight → "outranks" |
| -// (green until Front desk, which says "phone" and holds no number, was |
| -// added); snippet() pointed at the kinds column → "snippet"; the |
| +// Kinds left out of the index entry, and the fill removed from the |
| +// store's search → "Deliveries holds one"; the eircode→address token removed |
| +// → "address finds []"; kind matches put before word matches → "outranks" (in |
| +// the first build, KindsWeight raised to HeadingWeight did the same, and |
| +// was green until Front desk, which says "phone" and holds no number, |
| +// was added; the weight is gone now — see index.go); snippet() pointed at the kinds column → "snippet"; the |
| // validator check in IndexTokens removed → "look-alike" (green until the |
| // failed-checksum IBAN was added: an eircode's pattern IS its check, so |
| // the eircode look-alike never reached a validator). Tokens written as |
| @@ -206,3 +207,75 @@ func TestKindTokensLeaveTheWordsWeight(t *testing.T) { |
| t.Errorf("the word lost its weight: %.4f for the passage saying it, %.4f for the next", hits[0].Score, hits[1].Score) |
| } |
| } |
| + |
| +// Astra's corpus, 2026-10-27: the office page, twenty-five suppliers that |
| +// only hold numbers, and a hundred longer passages that say "phone" and |
| +// hold none. ORing the kind token into the query let the suppliers' rare |
| +// token outrank every word match: the office page fell out of the top 25 |
| +// and the box guessed a supplier's number. The words come first now. |
| +// |
| +// MUTATION-TESTED 2026-10-27, reverted: the tokens ORed into the words' |
| +// query again → red ("facts = [01 547 7010]"). |
| +func TestGate44TokensNeverDisplaceAWordMatch(t *testing.T) { |
| + paul := suite.Subject{Kind: suite.SubjectAddress, Value: "paul@tito.io"} |
| + docs := [][3]string{{"o", "Office", officePage}} |
| + for i := 0; i < 25; i++ { |
| + docs = append(docs, [3]string{"s" + strconv.Itoa(i), "Supplier " + strconv.Itoa(i), |
| + "## Supplier\n\n01 547 70" + strconv.Itoa(10+i)}) |
| + } |
| + for i := 0; i < 100; i++ { |
| + docs = append(docs, [3]string{"p" + strconv.Itoa(i), "Policy " + strconv.Itoa(i), |
| + "## Policy\n\nPhone calls with customers are logged in the CRM within a working day, and a phone call that runs long is summarised for the account owner before the end of the week."}) |
| + } |
| + s := factCorpus(t, &perItemCustody{apps: docsRoster()}, docs) |
| + page, err := s.Search(context.Background(), paul, "what is the office phone number?", 25) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var got []string |
| + for _, f := range page.Facts { |
| + got = append(got, f.Span) |
| + } |
| + if len(got) != 1 || got[0] != "+353 (0)1 547 7854" { |
| + t.Errorf("facts = %q, want the office number alone", got) |
| + } |
| +} |
| + |
| +// The fill reaches the typing path, and every kind a query names. |
| +// Mutations: the fill skipped while typing → "typing"; only the first |
| +// kind's token used → "both kinds". |
| +func TestGate44FillReachesTypingAndEveryKind(t *testing.T) { |
| + paul := suite.Subject{Kind: suite.SubjectAddress, Value: "paul@tito.io"} |
| + ctx := context.Background() |
| + s := factCorpus(t, &perItemCustody{apps: docsRoster()}, [][3]string{ |
| + {"e", "Where we are", "## Contact\n\nLocation: 1 Grand Canal Square, Dublin 2, D02 X285"}, |
| + {"i", "Paying us", "## Paying\n\nPay into IE29 AIBK 9311 5212 3456 78 by Friday."}, |
| + }) |
| + titles := func(p Page) map[string]bool { |
| + out := map[string]bool{} |
| + for _, r := range p.Results { |
| + out[r.Title] = true |
| + } |
| + return out |
| + } |
| + typed, err := s.SearchWhileTyping(ctx, paul, "eircode", 25) |
| + if err != nil || !titles(typed)["Where we are"] { |
| + t.Errorf("typing: %q while typing found %v, %v", "eircode", titles(typed), err) |
| + } |
| + both, err := s.Search(ctx, paul, "eircode and iban", 25) |
| + if err != nil || !titles(both)["Where we are"] || !titles(both)["Paying us"] { |
| + t.Errorf("both kinds: %q found %v, %v", "eircode and iban", titles(both), err) |
| + } |
| +} |
| + |
| +// A value whose label is too long for a box (NoBox) is still a value the |
| +// passage holds. Mutation: IndexTokens skipping NoBox values → red. |
| +func TestIndexTokensCountANoBoxValue(t *testing.T) { |
| + text := strings.Repeat("this sentence keeps going on about where the calls are routed ", 4) + "is: 01 547 7854" |
| + if f := fact.Scan(text, "Contact", "Tito", []fact.Kind{fact.Phone}); len(f) != 1 || !f[0].NoBox { |
| + t.Fatalf("fixture: the number should be NoBox, got %+v", f) |
| + } |
| + if got := fact.IndexTokens(text); got != "xkindphone" { |
| + t.Errorf("IndexTokens = %q, want xkindphone", got) |
| + } |
| +} |
diff --git a/internal/memoria/store.go b/internal/memoria/store.go| index 88d75ef..d884ddd 100644 |
| --- a/internal/memoria/store.go |
| +++ b/internal/memoria/store.go |
| @@ -707,12 +707,38 @@ func (s *Store) search(ctx context.Context, asker suite.Subject, query string, l |
| if mode == modeTyping { |
| find = s.ix.SearchTyping |
| } |
| - // §8.12: the kinds the query names find passages that hold one and |
| - // never say the word. |
| - hits, err := find(query, limit, fact.QueryTokens(query)...) |
| + hits, err := find(query, limit) |
| if err != nil { |
| return Page{}, err |
| } |
| + // §8.12: the kinds the query names find passages that hold one and |
| + // never say the word — but only in the room the words left. The |
| + // words' own top `limit` is taken first, exactly as before, and kind |
| + // matches fill what is left. ORing the tokens into one query let |
| + // their IDF outrank the words: with many passages saying "phone" and |
| + // a few only holding a number, twenty-five suppliers pushed the |
| + // office page out of the top 25 and the box guessed a supplier's |
| + // number (Astra, 2026-10-27). Filling can add passages; it can never |
| + // remove one the words found. |
| + if toks := fact.QueryTokens(query); len(toks) > 0 && len(hits) < limit { |
| + more, err := s.ix.SearchKinds(toks, limit) |
| + if err != nil { |
| + return Page{}, err |
| + } |
| + have := make(map[int64]bool, len(hits)) |
| + for _, h := range hits { |
| + have[h.ChunkID] = true |
| + } |
| + for _, h := range more { |
| + if len(hits) >= limit { |
| + break |
| + } |
| + if !have[h.ChunkID] { |
| + have[h.ChunkID] = true |
| + hits = append(hits, h) |
| + } |
| + } |
| + } |
| if len(hits) == 0 { |
| return Page{}, nil |
| } |