search fix to new architecture2
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use common::search::{
|
||||
ARCHIVED_ROW_KEY_PREFIX, SchemaFields, json_path_term, normalize_column_name,
|
||||
normalize_exact, tokenize_ngram, tokenize_word,
|
||||
SchemaFields, json_path_term, normalize_column_name, normalize_exact, tokenize_ngram,
|
||||
tokenize_word,
|
||||
};
|
||||
use common::proto::komp_ac::search::SearchVersionScope;
|
||||
use tantivy::query::{
|
||||
BooleanQuery, BoostQuery, EmptyQuery, FuzzyTermQuery, Occur, PhraseQuery, Query, QueryParser,
|
||||
RegexQuery, TermQuery,
|
||||
TermQuery,
|
||||
};
|
||||
use tantivy::schema::{IndexRecordOption, Term};
|
||||
use tantivy::Index;
|
||||
@@ -62,14 +62,15 @@ pub fn build_master_query(
|
||||
));
|
||||
}
|
||||
|
||||
let archived_rows = RegexQuery::from_pattern(
|
||||
&format!("{ARCHIVED_ROW_KEY_PREFIX}.*"),
|
||||
fields.row_key,
|
||||
)
|
||||
.map_err(|error| Status::internal(format!("Archived-row query build failed: {error}")))?;
|
||||
let archived_rows = |archived| {
|
||||
Box::new(TermQuery::new(
|
||||
Term::from_field_u64(fields.is_archived, u64::from(archived)),
|
||||
IndexRecordOption::Basic,
|
||||
)) as Box<dyn Query>
|
||||
};
|
||||
match version_scope {
|
||||
SearchVersionScope::Current => clauses.push((Occur::MustNot, Box::new(archived_rows))),
|
||||
SearchVersionScope::Archived => clauses.push((Occur::Must, Box::new(archived_rows))),
|
||||
SearchVersionScope::Current => clauses.push((Occur::Must, archived_rows(false))),
|
||||
SearchVersionScope::Archived => clauses.push((Occur::Must, archived_rows(true))),
|
||||
SearchVersionScope::All => {}
|
||||
}
|
||||
|
||||
@@ -328,6 +329,17 @@ mod tests {
|
||||
for source in documents {
|
||||
let mut document = TantivyDocument::default();
|
||||
document.add_u64(fields.pg_id, source.row_id);
|
||||
document.add_u64(fields.row_revision, 1);
|
||||
let archive = common::search::parse_archived_search_row_key(&source.row_key);
|
||||
document.add_u64(fields.is_archived, u64::from(archive.is_some()));
|
||||
document.add_u64(
|
||||
fields.table_definition_id,
|
||||
archive.map(|item| item.0 as u64).unwrap_or_default(),
|
||||
);
|
||||
document.add_u64(
|
||||
fields.version_number,
|
||||
archive.map(|item| item.2 as u64).unwrap_or_default(),
|
||||
);
|
||||
document.add_text(fields.table_name, source.table_name);
|
||||
document.add_text(fields.row_key, &source.row_key);
|
||||
let mut object = std::collections::BTreeMap::new();
|
||||
|
||||
Reference in New Issue
Block a user