Search: a question ranks like its subject
Paul, 2026-10-26: "who is Paul Campbell" ranked a team row that only names him as its owner above his People page; "paul Campbell" ranked them correctly. index.dropQuestionFraming removes the opening of a query that starts with a question word: the word, the helper verbs after it, and one determiner. The rest of the query is untouched, so "May revenue" and "Will Turner" keep their subjects. A query that is only framing is searched as typed. Reviewed by GPT-6 Astra (REQUEST CHANGES): the first version dropped such words anywhere and erased subjects. Fixed; all surviving mutants are built and red. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from fix/question-words into main.
4 files changed,
+128
−6
docs/superpowers/specs/2026-09-03-memoria-design.md+13 −0internal/memoria/index/index.go+47 −0internal/memoria/index/index_test.go+4 −6internal/memoria/index/rank_test.go+64 −0
CI passed — run details
diff --git a/docs/superpowers/specs/2026-09-03-memoria-design.md b/docs/superpowers/specs/2026-09-03-memoria-design.md| index db0619d..9fb70e1 100644 |
| --- a/docs/superpowers/specs/2026-09-03-memoria-design.md |
| +++ b/docs/superpowers/specs/2026-09-03-memoria-design.md |
| @@ -3782,6 +3782,19 @@ settled request sends them, and pressing Enter or reloading is another |
| full request that sends them again. The footer says "once you stop |
| typing", and the README says the rest. |
| +**A question's opening is not searched for (2026-10-26).** "who is Paul |
| +Campbell" ranked a team list that only names him as its owner above his |
| +own People page, because "who" and "is" also matched its body. In an OR |
| +query they are not neutral. `index.dropQuestionFraming` removes the |
| +opening of a query that starts with a question word: the question word, |
| +the helper verbs straight after it, and one determiner after those. So |
| +"what is the office phone number" searches "office phone number". |
| + |
| +It removes **only the opening**. A first version dropped such words |
| +anywhere, and review found it erasing subjects: "Will Turner", "May |
| +revenue", "IT support", "US tax". A query that is nothing but framing is |
| +searched as typed. |
| + |
| **While typing, the last word matches as a prefix (2026-10-26).** |
| Whole-token matching made live search find nothing on the way to a word: |
| "offi" matched no passage, so the list emptied until "office" was |
diff --git a/internal/memoria/index/index.go b/internal/memoria/index/index.go| index a5ce49b..9c319e2 100644 |
| --- a/internal/memoria/index/index.go |
| +++ b/internal/memoria/index/index.go |
| @@ -336,6 +336,7 @@ func matchQuery(raw string, typing bool) string { |
| if len(terms) == 0 { |
| return "" |
| } |
| + terms = dropQuestionFraming(terms) |
| // A search box is not a document. Beyond this the OR chain costs |
| // more than the answer is worth: measured at 2.8ms for 100 terms, |
| // 97ms for 1000 and 2.25s for 5000 — and Search holds the index's |
| @@ -408,6 +409,52 @@ func matchQuery(raw string, typing bool) string { |
| return strings.Join(quoted, " OR ") |
| } |
| +// A question's framing is not its subject. "who is Paul Campbell" |
| +// ranked a team list that only names him as its owner above his own |
| +// People page, because "who" and "is" also matched its body (Paul, |
| +// 2026-10-26). So a query that OPENS with a question word loses that |
| +// opening — the question word, the helper verbs straight after it, and a |
| +// determiner after those — and is searched as its subject. |
| +// |
| +// Only the opening. A first version dropped such words anywhere and |
| +// erased subjects with them: "Will Turner", "May revenue", "IT support", |
| +// "US tax" (review, 2026-10-26). A word that is a subject in one query |
| +// and framing in another can only be told apart by where it stands. |
| +var ( |
| + questionOpeners = setOf("what whats which who whom whose where when why how") |
| + questionHelpers = setOf("is are was were be been am do does did has have had can could will would should shall may might must s") |
| + questionDeterms = setOf("the a an my our your their his her its") |
| +) |
| + |
| +func setOf(words string) map[string]bool { |
| + m := map[string]bool{} |
| + for _, w := range strings.Fields(words) { |
| + m[w] = true |
| + } |
| + return m |
| +} |
| + |
| +// dropQuestionFraming removes a leading question word, the helper verbs |
| +// straight after it, and one determiner after those, when at least one |
| +// term remains. Case does not matter. A query that is nothing but framing |
| +// ("who is") is searched as typed. |
| +func dropQuestionFraming(terms []string) []string { |
| + i := 0 |
| + if i < len(terms) && questionOpeners[strings.ToLower(terms[i])] { |
| + i++ |
| + for i < len(terms) && questionHelpers[strings.ToLower(terms[i])] { |
| + i++ |
| + } |
| + if i < len(terms) && questionDeterms[strings.ToLower(terms[i])] { |
| + i++ |
| + } |
| + } |
| + if i == 0 || i >= len(terms) { |
| + return terms |
| + } |
| + return terms[i:] |
| +} |
| + |
| // randomName gives each in-memory index its own shared-cache key. Random |
| // rather than a counter: a counter resets when the process restarts, and |
| // two indexes alive across a restart boundary in a test binary would |
diff --git a/internal/memoria/index/index_test.go b/internal/memoria/index/index_test.go| index 0112b73..7e2054c 100644 |
| --- a/internal/memoria/index/index_test.go |
| +++ b/internal/memoria/index/index_test.go |
| @@ -134,14 +134,12 @@ func TestMatchQueryQuotesAndOrs(t *testing.T) { |
| // TestWordOrderDoesNotChangeTheRanking. |
| // |
| // "what's up" is the interesting row. The apostrophe splits the query |
| - // into three terms and they are required together as three, which |
| - // still matches a document's "what's up": the tokenizer is |
| - // `porter unicode61`, and unicode61 drops the apostrophe on both |
| - // sides while porter stems what is left. The phrase logic depends on |
| - // both halves of that tokenizer, so swapping either changes this. |
| + // into "what", "s" and "up": a question opener and its helper, so |
| + // since 2026-10-26 the search is for "up" alone (dropQuestionFraming), |
| + // which still matches a document saying "what's up". |
| for in, want := range map[string]string{ |
| "june revenue": `"june" OR "revenue" OR NEAR("june" "revenue", 2)`, |
| - "what's up": `"what" OR "s" OR "up" OR NEAR("what" "s" "up", 2)`, |
| + "what's up": `"up"`, |
| " spaced out ": `"spaced" OR "out" OR NEAR("spaced" "out", 2)`, |
| "!!!": ``, |
| "café": `"café"`, |
diff --git a/internal/memoria/index/rank_test.go b/internal/memoria/index/rank_test.go| index 34eab93..bb19875 100644 |
| --- a/internal/memoria/index/rank_test.go |
| +++ b/internal/memoria/index/rank_test.go |
| @@ -242,3 +242,67 @@ func TestAbsurdlyLongQueryIsCapped(t *testing.T) { |
| t.Errorf("a 5000-term search took %s; it holds the index read lock throughout", d) |
| } |
| } |
| + |
| +// "who is Paul Campbell" ranks his own page first, as "paul campbell" |
| +// does (Paul, 2026-10-26). Question words in an OR query are not neutral: |
| +// "who" and "is" matched a team list's body, which only names him as its |
| +// owner, and lifted it above his People page and the Leadership Team. |
| +// |
| +// MUTATION-TESTED 2026-10-26, reverted: the dropQuestionFraming call |
| +// removed → "\"who is Paul Campbell\" ranked document 1 first". |
| +func TestAQuestionRanksLikeItsSubject(t *testing.T) { |
| + ix := build(t, |
| + Entry{ChunkID: 1, DocumentID: 1, Title: "Saron Yitbarek", Path: "Coronavirus Advisory Team", Text: "Owner: Paul Campbell. Who is on the team, and what is the plan? This is where it is tracked, who is next, and what is done."}, |
| + Entry{ChunkID: 2, DocumentID: 2, Title: "Paul Campbell", Path: "Roles and responsibilities › Current allocated roles", Heading: "Paul Campbell", Text: "Chief Executive Officer, Chief Technical Officer"}, |
| + Entry{ChunkID: 3, DocumentID: 3, Title: "Leadership Team", Heading: "Leadership Team", Text: "Paul Campbell, Co-founder & Chief Executive Officer. Doc Parsons, Co-founder & Chief Operating Officer."}, |
| + ) |
| + for _, q := range []string{"who is Paul Campbell", "paul campbell", "what is Paul Campbell's role?"} { |
| + hits, err := ix.Search(q, 10) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(hits) == 0 || hits[0].DocumentID != 2 { |
| + first := int64(0) |
| + if len(hits) > 0 { |
| + first = hits[0].DocumentID |
| + } |
| + t.Errorf("%q ranked document %d first, want his own page (2)", q, first) |
| + } |
| + } |
| +} |
| + |
| +// Only a question's OPENING is dropped. GPT-6 Astra's review (2026-10-26) |
| +// found a first version, which dropped such words anywhere, erasing |
| +// subjects ("Will Turner" became "Turner") and moving a typed prefix onto |
| +// the wrong word ("bank in" became "bank"*). |
| +// |
| +// MUTATION-TESTED 2026-10-26, each reverted: words dropped anywhere in |
| +// the query (the first version) → the subject cases; the opener compared |
| +// case-sensitively → "WHO IS Paul Campbell"; an all-framing query cut to |
| +// its first word → "who is"; framing kept while typing → "who is pa". |
| +func TestOnlyTheQuestionsOpeningIsDropped(t *testing.T) { |
| + for q, want := range map[string]string{ |
| + "Will Turner": `"Will" OR "Turner" OR NEAR("Will" "Turner", 2)`, |
| + "May revenue": `"May" OR "revenue" OR NEAR("May" "revenue", 2)`, |
| + "IT support": `"IT" OR "support" OR NEAR("IT" "support", 2)`, |
| + "US tax": `"US" OR "tax" OR NEAR("US" "tax", 2)`, |
| + "C programming": `"C" OR "programming" OR NEAR("C" "programming", 2)`, |
| + "or prix": `"or" OR "prix" OR NEAR("or" "prix", 2)`, |
| + "東京 駅": `"東京" OR "駅" OR NEAR("東京" "駅", 2)`, |
| + "WHO IS Paul Campbell": `"Paul" OR "Campbell" OR NEAR("Paul" "Campbell", 2)`, |
| + "what is the office phone number": `"office" OR "phone" OR "number" OR NEAR("office" "phone" "number", 2)`, |
| + "who is": `"who" OR "is" OR NEAR("who" "is", 2)`, |
| + } { |
| + if got := MatchQuery(q); got != want { |
| + t.Errorf("MatchQuery(%q) = %q, want %q", q, got, want) |
| + } |
| + } |
| + for q, want := range map[string]string{ |
| + "bank in": `"bank" OR "in"* OR NEAR("bank" "in"*, 2)`, |
| + "who is pa": `"pa"*`, |
| + } { |
| + if got := MatchQueryTyping(q); got != want { |
| + t.Errorf("MatchQueryTyping(%q) = %q, want %q", q, got, want) |
| + } |
| + } |
| +} |