Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions server/bleep/src/indexes/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ impl Indexer<File> {
// hits is a mapping between a document address and the number of trigrams in it that
// matched the query
let repo_ref_term = Term::from_field_text(self.source.repo_ref, &repo_ref.to_string());
let branch_term = branch
.map(|b| {
trigrams(b)
.map(|token| Term::from_field_text(self.source.branches, token.as_str()))
.map(|term| TermQuery::new(term, IndexRecordOption::Basic))
.map(Box::new)
.map(|q| q as Box<dyn Query>)
.collect::<Vec<_>>()
})
.map(|qs| BooleanQuery::intersection(qs));
let mut hits = trigrams(query_str)
.flat_map(|s| case_permutations(s.as_str()))
.map(|token| Term::from_field_text(self.source.relative_path, token.as_str()))
Expand All @@ -183,11 +193,8 @@ impl Indexer<File> {
)),
];

if let Some(b) = branch {
query.push(Box::new(TermQuery::new(
Term::from_field_bytes(self.source.branches, b.as_bytes()),
IndexRecordOption::Basic,
)));
if let Some(b) = branch_term.as_ref() {
query.push(Box::new(b.clone()));
};

BooleanQuery::intersection(query)
Expand Down Expand Up @@ -344,11 +351,18 @@ impl Indexer<File> {
IndexRecordOption::Basic,
)) as Box<dyn Query>);

if let Some(b) = branch {
query.push(Box::new(TermQuery::new(
Term::from_field_bytes(self.source.branches, b.as_bytes()),
IndexRecordOption::Basic,
)));
let branch_term = branch
.map(|b| {
trigrams(b)
.map(|token| Term::from_field_text(self.source.branches, token.as_str()))
.map(|term| TermQuery::new(term, IndexRecordOption::Basic))
.map(Box::new)
.map(|q| q as Box<dyn Query>)
.collect::<Vec<_>>()
})
.map(|qs| BooleanQuery::intersection(qs));
if let Some(b) = branch_term {
query.push(Box::new(b) as Box<dyn Query>);
};

query.push({
Expand Down
23 changes: 17 additions & 6 deletions server/bleep/src/webserver/intelligence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,23 @@ async fn search_nav(
Box::new(TermQuery::new(repo_filter, IndexRecordOption::Basic))
as Box<dyn tantivy::query::Query>,
))
.chain(branch.into_iter().map(|b| {
Box::new(TermQuery::new(
Term::from_field_bytes(indexer.source.branches, b.as_bytes()),
IndexRecordOption::Basic,
)) as Box<dyn tantivy::query::Query>
}))
.chain(
branch
.into_iter()
.map(|b| {
trigrams(b)
.map(|token| {
Term::from_field_text(indexer.source.branches, token.as_str())
})
.map(|term| TermQuery::new(term, IndexRecordOption::Basic))
.map(Box::new)
.map(|q| q as Box<dyn tantivy::query::Query>)
.collect::<Vec<_>>()
})
.map(|b| BooleanQuery::intersection(b))
.map(Box::new)
.map(|b| b as Box<dyn tantivy::query::Query>),
)
.chain(std::iter::once(Box::new(BooleanQuery::union(
associated_langs
.iter()
Expand Down