Deferred code quality and refactoring work from PR #284 (Wave 3f, #197). These are cosmetic but improve maintainability for Wave 4 feature work.
Refactoring Items
A1/CX2: Split query.rs into focused modules
File:Line: crates/rskim-search/src/query.rs (482 lines, 4 responsibilities)
Current file bundles: parsing, query engine dispatch, scoring, and adapter/trait logic. Split into:
query/parse.rs — parse_*_query() functions
query/engine.rs — run_ngram_set() and dispatch logic (~73 lines)
query/scoring.rs — score_postings(), IDF cache, scoring helpers
query/adapter.rs — AstPostingSource and trait implementations
This aligns with single-responsibility principle and reduces merge contention during #198/#283/#200 work.
CX3: Extract dedup+assert generic helper
File:Line: crates/rskim-search/src/query.rs:155,162
Duplicated block for bigram and trigram deduplication:
{
set.sort_unstable_by_key(|p| p.bigram_key());
set.dedup_by_key(|p| p.bigram_key());
debug_assert!(!set.is_empty(), "bigram postings should never be empty");
}
Extract a generic dedup_by_ngram_key<F>(set: &mut Vec<T>, key_fn: F) -> Result<()> helper with the assert built-in.
CX4: Extract idf_for helper
File:Line: crates/rskim-search/src/query.rs:422
Flatten score_postings() nesting (current depth 4 → target depth 2) by extracting:
fn idf_for(cache: &mut IdfCache, lang: LangId, postings: &[AstPosting]) -> Result<f64>
This makes the scoring loop more readable without affecting logic.
Sequencing
Bundle with: #198 (multi-layer intersection), #283 (unigram posting index), #200 (composite ranking)
Rationale: Doing this refactor alongside Wave 4 feature work limits merge contention. Standalone refactor carries risk of conflicts.
North Star: #174 (AST Structural Query Engine)
Closes #284 (code quality items A1/CX2-CX4).
Deferred code quality and refactoring work from PR #284 (Wave 3f, #197). These are cosmetic but improve maintainability for Wave 4 feature work.
Refactoring Items
A1/CX2: Split query.rs into focused modules
File:Line:
crates/rskim-search/src/query.rs(482 lines, 4 responsibilities)Current file bundles: parsing, query engine dispatch, scoring, and adapter/trait logic. Split into:
query/parse.rs—parse_*_query()functionsquery/engine.rs—run_ngram_set()and dispatch logic (~73 lines)query/scoring.rs—score_postings(), IDF cache, scoring helpersquery/adapter.rs—AstPostingSourceand trait implementationsThis aligns with single-responsibility principle and reduces merge contention during #198/#283/#200 work.
CX3: Extract dedup+assert generic helper
File:Line:
crates/rskim-search/src/query.rs:155,162Duplicated block for bigram and trigram deduplication:
Extract a generic
dedup_by_ngram_key<F>(set: &mut Vec<T>, key_fn: F) -> Result<()>helper with the assert built-in.CX4: Extract idf_for helper
File:Line:
crates/rskim-search/src/query.rs:422Flatten
score_postings()nesting (current depth 4 → target depth 2) by extracting:This makes the scoring loop more readable without affecting logic.
Sequencing
Bundle with: #198 (multi-layer intersection), #283 (unigram posting index), #200 (composite ranking)
Rationale: Doing this refactor alongside Wave 4 feature work limits merge contention. Standalone refactor carries risk of conflicts.
North Star: #174 (AST Structural Query Engine)
Closes #284 (code quality items A1/CX2-CX4).