Persona search: one matcher, stemmed as the normal form is, for the fixture and the live forge
Soul's R9 item 4. search_finds stems the query's content words and the text's words with the same light plural stem and stopword list as ReadRequest::normal, so "consent receipts" finds what "consent receipt" finds. A fixture search always goes through the matcher over the recorded changes, never a lookup of a recorded search, as the live path has no such lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1f3a3d1312
commit
623061bb77
2 changed files with 35 additions and 5 deletions
|
|
@ -264,10 +264,11 @@ pub(crate) fn content(word: &str) -> bool {
|
|||
}
|
||||
|
||||
/// Whether a search's words find `text`: every word of the query that carries content stands in it as a whole word, case
|
||||
/// blind (Soul's R7). One matcher for the live forge and the fixture, so the harness and the live path agree.
|
||||
/// blind, each lightly stemmed as `ReadRequest::normal` stems it (Soul's R7, R9), so "consent receipts" finds "receipt".
|
||||
/// One matcher for the live forge and the fixture, so the harness and the live path agree.
|
||||
fn search_finds(query: &str, text: &str) -> bool {
|
||||
let wanted: Vec<String> = word_tokens(query).into_iter().filter(|word| content(word)).collect();
|
||||
let held = word_tokens(text);
|
||||
let wanted: Vec<String> = word_tokens(query).into_iter().filter(|word| content(word)).map(|word| stem(&word)).collect();
|
||||
let held: Vec<String> = word_tokens(text).into_iter().map(|word| stem(&word)).collect();
|
||||
!wanted.is_empty() && wanted.iter().all(|word| held.contains(word))
|
||||
}
|
||||
|
||||
|
|
@ -384,11 +385,15 @@ impl ReadSource for ReadFixture {
|
|||
fn read(&self, request: &ReadRequest, _since: DateTime<Utc>) -> Result<String, ReadFailure> {
|
||||
let key = request.normal();
|
||||
let request_of = |entry: &ReadEntry| serde_json::from_value::<ReadRequest>(serde_json::json!({ "kind": entry.kind, "target": entry.target })).ok();
|
||||
// A search always goes through the matcher over the recorded changes, never a lookup of a recorded search (Soul's
|
||||
// R9): the live path has no such lookup either.
|
||||
if matches!(request, ReadRequest::Repo(target) if target.contains("?q=")) {
|
||||
return fixture_search(&self.0, request).ok_or(ReadFailure::NotFound);
|
||||
}
|
||||
match self.0.iter().find(|entry| request_of(entry).is_some_and(|recorded| recorded.normal() == key)) {
|
||||
Some(ReadEntry { refused: Some(why), .. }) => Err(*why),
|
||||
Some(ReadEntry { text: Some(text), .. }) => Ok(text.clone()),
|
||||
Some(_) => Err(ReadFailure::NotFound),
|
||||
None => fixture_search(&self.0, request).ok_or(ReadFailure::NotFound),
|
||||
_ => Err(ReadFailure::NotFound),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,3 +157,28 @@ fn r8_a_search_and_a_number_have_one_normal_form() {
|
|||
assert_eq!(normal("GameCult/Bifrost#0"), "repo:gamecult/bifrost#0");
|
||||
assert_eq!(normal("GameCult/Bifrost?q=queries class"), "repo:gamecult/bifrost?q=class query");
|
||||
}
|
||||
|
||||
/// Soul's R9: one matcher, stemmed as the normal form is, in the fixture and the live path alike: "merge pages" and "page
|
||||
/// merge" find the same, and "consent receipts" finds what "consent receipt" finds, live as in the fixture.
|
||||
#[test]
|
||||
fn r9_one_matcher_stems_for_the_fixture_and_the_live_forge() {
|
||||
let fixture: ReadFixture = serde_json::from_value(serde_json::json!([
|
||||
{ "kind": "repo", "target": "GameCult/Bifrost#87", "text": "Merge pages and notices\nProve both." },
|
||||
{ "kind": "repo", "target": "GameCult/Bifrost#59", "text": "Chat sign-in needs a live consent receipt" },
|
||||
]))
|
||||
.unwrap();
|
||||
let since = Utc::now();
|
||||
let search = |target: &str| fixture.read(&ReadRequest::Repo(target.into()), since);
|
||||
assert_eq!(search("GameCult/Bifrost?q=merge pages"), search("GameCult/Bifrost?q=page merge"));
|
||||
assert!(search("GameCult/Bifrost?q=merge pages").is_ok_and(|found| found.contains("#87")));
|
||||
assert_eq!(search("GameCult/Bifrost?q=consent receipts"), search("GameCult/Bifrost?q=consent receipt"));
|
||||
assert!(search("GameCult/Bifrost?q=consent receipts").is_ok_and(|found| found.contains("#59")));
|
||||
struct Recorded;
|
||||
impl ForgeGet for Recorded {
|
||||
fn get(&self, _path: &str) -> anyhow::Result<(u16, String)> {
|
||||
Ok((200, include_str!("../fixtures/forge-bifrost-q-consent.json").to_owned()))
|
||||
}
|
||||
}
|
||||
assert_eq!(repo_read(&Recorded, "GameCult/Bifrost?q=consent receipts"), repo_read(&Recorded, "GameCult/Bifrost?q=consent receipt"));
|
||||
assert!(repo_read(&Recorded, "GameCult/Bifrost?q=consent receipts").unwrap().starts_with("- #71 "));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue