Skip to content

Commit 93ddf47

Browse files
committed
document generic search query flow
1 parent 7e30129 commit 93ddf47

File tree

17 files changed

+73
-27
lines changed

17 files changed

+73
-27
lines changed

crates/core/src/generic_query/get_homepage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl GenericQuery for GetHomepageQuery {
7272
FirstDocCollector::with_shard_id(ctx.shard_id)
7373
}
7474

75-
fn remote_collector(&self) -> Self::Collector {
75+
fn coordinator_collector(&self) -> Self::Collector {
7676
FirstDocCollector::without_shard_id()
7777
}
7878

crates/core/src/generic_query/get_site_urls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl GenericQuery for GetSiteUrlsQuery {
6565
.disable_offset()
6666
}
6767

68-
fn remote_collector(&self) -> Self::Collector {
68+
fn coordinator_collector(&self) -> Self::Collector {
6969
Self::Collector::new()
7070
.with_limit(self.limit as usize)
7171
.with_offset(self.offset.unwrap_or(0) as usize)

crates/core/src/generic_query/get_webpage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl GenericQuery for GetWebpageQuery {
6868
FirstDocCollector::with_shard_id(ctx.shard_id)
6969
}
7070

71-
fn remote_collector(&self) -> Self::Collector {
71+
fn coordinator_collector(&self) -> Self::Collector {
7272
FirstDocCollector::without_shard_id()
7373
}
7474

crates/core/src/generic_query/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
//! # Main flow
18+
//! ```md
19+
//! `coordinator` <------> `searcher`
20+
//! -----------------------------------
21+
//! send query to searcher
22+
//! search index
23+
//! collect fruits
24+
//! send fruits to coordinator
25+
//! merge fruits
26+
//! filter fruits
27+
//! for each shard
28+
//! send fruits to searchers
29+
//! construct intermediate output
30+
//! from fruits
31+
//! send intermediate output to coordinator
32+
//! merge intermediate outputs
33+
//! return final output
34+
//! ---------------------------------------------------
35+
//! ```
36+
1737
use crate::{inverted_index::ShardId, search_ctx, Result};
1838

1939
pub mod top_key_phrases;
@@ -34,6 +54,8 @@ pub use get_site_urls::GetSiteUrlsQuery;
3454
pub mod collector;
3555
pub use collector::Collector;
3656

57+
/// A generic query that can be executed on a searcher
58+
/// against an index.
3759
pub trait GenericQuery: Send + Sync + bincode::Encode + bincode::Decode + Clone {
3860
type Collector: Collector;
3961
type TantivyQuery: tantivy::query::Query;
@@ -42,7 +64,7 @@ pub trait GenericQuery: Send + Sync + bincode::Encode + bincode::Decode + Clone
4264

4365
fn tantivy_query(&self, ctx: &search_ctx::Ctx) -> Self::TantivyQuery;
4466
fn collector(&self, ctx: &search_ctx::Ctx) -> Self::Collector;
45-
fn remote_collector(&self) -> Self::Collector;
67+
fn coordinator_collector(&self) -> Self::Collector;
4668

4769
fn filter_fruit_shards(
4870
&self,

crates/core/src/generic_query/size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl GenericQuery for SizeQuery {
7070
SizeCollector::new().with_shard_id(ctx.shard_id)
7171
}
7272

73-
fn remote_collector(&self) -> Self::Collector {
73+
fn coordinator_collector(&self) -> Self::Collector {
7474
SizeCollector::new()
7575
}
7676

crates/core/src/generic_query/top_key_phrases.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl GenericQuery for TopKeyPhrasesQuery {
4747
TopKeyPhrasesCollector::new(self.top_n).with_shard_id(ctx.shard_id)
4848
}
4949

50-
fn remote_collector(&self) -> Self::Collector {
50+
fn coordinator_collector(&self) -> Self::Collector {
5151
TopKeyPhrasesCollector::new(self.top_n)
5252
}
5353

crates/core/src/inverted_index/search.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ impl InvertedIndex {
341341
From<<Q::Collector as generic_query::Collector>::Fruit>,
342342
{
343343
let fruit = self.search_initial_generic(query)?;
344-
let mut fruit = query.remote_collector().merge_fruits(vec![fruit.into()])?;
344+
let mut fruit = query
345+
.coordinator_collector()
346+
.merge_fruits(vec![fruit.into()])?;
345347

346348
if let Some(shard_id) = self.shard_id {
347349
fruit = query.filter_fruit_shards(shard_id, fruit);

crates/core/src/searcher/distributed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl SearchClient for DistributedSearcher {
414414
>: From<<Q as sonic::service::Message<SearchService>>::Response>,
415415
<<Q::Collector as generic_query::Collector>::Child as tantivy::collector::SegmentCollector>::Fruit:
416416
From<<Q::Collector as generic_query::Collector>::Fruit> {
417-
let collector = query.remote_collector();
417+
let collector = query.coordinator_collector();
418418

419419
let res = self.conn().await
420420
.send(query, &AllShardsSelector, &RandomReplicaSelector)
@@ -518,7 +518,7 @@ impl SearchClient for DistributedSearcher {
518518
queries
519519
.iter()
520520
.zip_eq(fruits.into_iter())
521-
.map(|(query, shard_fruits)| query.remote_collector().merge_fruits(shard_fruits))
521+
.map(|(query, shard_fruits)| query.coordinator_collector().merge_fruits(shard_fruits))
522522
.collect::<Result<Vec<_>, _>>()
523523
}
524524

crates/core/src/webgraph/query/backlink.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl Query for BacklinksQuery {
182182
collector
183183
}
184184

185-
fn remote_collector(&self) -> Self::Collector {
185+
fn coordinator_collector(&self) -> Self::Collector {
186186
TopDocsCollector::from(self.limit).enable_offset()
187187
}
188188

@@ -314,7 +314,7 @@ impl Query for HostBacklinksQuery {
314314
collector
315315
}
316316

317-
fn remote_collector(&self) -> Self::Collector {
317+
fn coordinator_collector(&self) -> Self::Collector {
318318
TopDocsCollector::from(self.limit)
319319
.enable_offset()
320320
.with_deduplicator(HostDeduplicator)
@@ -467,7 +467,7 @@ impl Query for FullBacklinksQuery {
467467
collector
468468
}
469469

470-
fn remote_collector(&self) -> Self::Collector {
470+
fn coordinator_collector(&self) -> Self::Collector {
471471
TopDocsCollector::from(self.limit).enable_offset()
472472
}
473473

@@ -617,7 +617,7 @@ impl Query for FullHostBacklinksQuery {
617617
collector
618618
}
619619

620-
fn remote_collector(&self) -> Self::Collector {
620+
fn coordinator_collector(&self) -> Self::Collector {
621621
TopDocsCollector::from(self.limit)
622622
.enable_offset()
623623
.with_deduplicator(HostDeduplicator)
@@ -742,7 +742,7 @@ impl Query for BacklinksWithLabelsQuery {
742742
collector
743743
}
744744

745-
fn remote_collector(&self) -> Self::Collector {
745+
fn coordinator_collector(&self) -> Self::Collector {
746746
TopDocsCollector::from(self.limit).enable_offset()
747747
}
748748

crates/core/src/webgraph/query/between.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Query for FullLinksBetweenQuery {
113113
collector
114114
}
115115

116-
fn remote_collector(&self) -> Self::Collector {
116+
fn coordinator_collector(&self) -> Self::Collector {
117117
TopDocsCollector::from(self.limit).enable_offset()
118118
}
119119

0 commit comments

Comments
 (0)