Skip to content

Commit e4e780e

Browse files
author
Eric B. Ridge
committed
chore: make more things public
In implementing custom queries that are similar to tantivy's built-in PhraseQuery and RegexPhraseQuery queries I've found a number of things that can benefit from being `pub` so they can be reused externally.
1 parent f7adcdf commit e4e780e

10 files changed

Lines changed: 28 additions & 14 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ variable
1717

1818
# for `sample record -p`
1919
profile.json
20+
profile.json.gz

src/postings/loaded_postings.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use crate::DocId;
1515
/// terms.
1616
/// E.g. 100_000 terms would need 184MB due to SegmentPostings.
1717
pub struct LoadedPostings {
18-
doc_ids: Box<[DocId]>,
19-
position_offsets: Box<[u32]>,
20-
positions: Box<[u32]>,
21-
cursor: usize,
18+
pub doc_ids: Box<[DocId]>,
19+
pub position_offsets: Box<[u32]>,
20+
pub positions: Box<[u32]>,
21+
pub cursor: usize,
2222
}
2323

2424
impl LoadedPostings {

src/postings/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod serializer;
2121
pub(crate) mod skip;
2222
mod term_info;
2323

24-
pub(crate) use loaded_postings::LoadedPostings;
24+
pub use loaded_postings::LoadedPostings;
2525
pub(crate) use stacker::compute_table_memory_size;
2626

2727
pub use self::block_segment_postings::BlockSegmentPostings;

src/query/explanation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::Serialize;
55

66
use crate::{DocId, Score, TantivyError};
77

8-
pub(crate) fn does_not_match(doc: DocId) -> TantivyError {
8+
pub fn does_not_match(doc: DocId) -> TantivyError {
99
TantivyError::InvalidArgument(format!("Document #({doc}) does not match"))
1010
}
1111

src/query/intersection.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn go_to_first_doc<TDocSet: DocSet>(docsets: &mut [TDocSet]) -> DocId {
6666
}
6767

6868
impl<TDocSet: DocSet> Intersection<TDocSet, TDocSet> {
69-
pub(crate) fn new(mut docsets: Vec<TDocSet>) -> Intersection<TDocSet, TDocSet> {
69+
pub fn new(mut docsets: Vec<TDocSet>) -> Intersection<TDocSet, TDocSet> {
7070
let num_docsets = docsets.len();
7171
assert!(num_docsets >= 2);
7272
docsets.sort_by_key(|docset| docset.size_hint());
@@ -79,10 +79,22 @@ impl<TDocSet: DocSet> Intersection<TDocSet, TDocSet> {
7979
others: docsets,
8080
}
8181
}
82+
83+
pub fn with_two_sets(left: TDocSet, right: TDocSet) -> Intersection<TDocSet, TDocSet> {
84+
let mut docsets = vec![left, right];
85+
go_to_first_doc(&mut docsets);
86+
let left = docsets.remove(0);
87+
let right = docsets.remove(0);
88+
Intersection {
89+
left,
90+
right,
91+
others: docsets,
92+
}
93+
}
8294
}
8395

8496
impl<TDocSet: DocSet> Intersection<TDocSet, TDocSet> {
85-
pub(crate) fn docset_mut_specialized(&mut self, ord: usize) -> &mut TDocSet {
97+
pub fn docset_mut_specialized(&mut self, ord: usize) -> &mut TDocSet {
8698
match ord {
8799
0 => &mut self.left,
88100
1 => &mut self.right,

src/query/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use self::disjunction_max_query::DisjunctionMaxQuery;
4444
pub use self::empty_query::{EmptyQuery, EmptyScorer, EmptyWeight};
4545
pub use self::exclude::Exclude;
4646
pub use self::exist_query::ExistsQuery;
47-
pub use self::explanation::Explanation;
47+
pub use self::explanation::{does_not_match, Explanation};
4848
#[cfg(test)]
4949
pub(crate) use self::fuzzy_query::DfaWrapper;
5050
pub use self::fuzzy_query::FuzzyTermQuery;
@@ -54,6 +54,7 @@ pub use self::more_like_this::{
5454
};
5555
pub use self::phrase_prefix_query::PhrasePrefixQuery;
5656
pub use self::phrase_query::regex_phrase_query::{wildcard_query_to_regex_str, RegexPhraseQuery};
57+
pub use self::phrase_query::regex_phrase_weight::RegexPhraseWeight;
5758
pub use self::phrase_query::PhraseQuery;
5859
pub use self::query::{EnableScoring, Query, QueryClone};
5960
pub use self::query_parser::{QueryParser, QueryParserError};
@@ -64,7 +65,7 @@ pub use self::score_combiner::{DisjunctionMaxCombiner, ScoreCombiner, SumCombine
6465
pub use self::scorer::Scorer;
6566
pub use self::set_query::TermSetQuery;
6667
pub use self::term_query::TermQuery;
67-
pub use self::union::BufferedUnionScorer;
68+
pub use self::union::{BufferedUnionScorer, SimpleUnion};
6869
#[cfg(test)]
6970
pub use self::vec_docset::VecDocSet;
7071
pub use self::weight::Weight;

src/query/phrase_query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod phrase_query;
22
mod phrase_scorer;
33
mod phrase_weight;
44
pub mod regex_phrase_query;
5-
mod regex_phrase_weight;
5+
pub mod regex_phrase_weight;
66

77
pub use self::phrase_query::PhraseQuery;
88
pub(crate) use self::phrase_scorer::intersection_count;

src/query/phrase_query/regex_phrase_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::regex_phrase_weight::RegexPhraseWeight;
1+
pub(crate) use super::regex_phrase_weight::RegexPhraseWeight;
22
use crate::query::bm25::Bm25Weight;
33
use crate::query::{EnableScoring, Query, Weight};
44
use crate::schema::{Field, IndexRecordOption, Term, Type};

src/query/phrase_query/regex_phrase_weight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl RegexPhraseWeight {
173173
/// docs. For higher cardinality buckets this is irrelevant as they are in most blocks.
174174
///
175175
/// Use Roaring Bitmaps for sparse terms. The full bitvec is main memory consumer currently.
176-
pub(crate) fn get_union_from_term_infos(
176+
pub fn get_union_from_term_infos(
177177
term_infos: &[TermInfo],
178178
reader: &SegmentReader,
179179
inverted_index: &InvertedIndexReader,

src/query/union/simple_union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct SimpleUnion<TDocSet> {
1212
}
1313

1414
impl<TDocSet: DocSet> SimpleUnion<TDocSet> {
15-
pub(crate) fn build(mut docsets: Vec<TDocSet>) -> SimpleUnion<TDocSet> {
15+
pub fn build(mut docsets: Vec<TDocSet>) -> SimpleUnion<TDocSet> {
1616
docsets.retain(|docset| docset.doc() != TERMINATED);
1717
let mut docset = SimpleUnion { docsets, doc: 0 };
1818

0 commit comments

Comments
 (0)