Compare commits

..

1 Commits

Author SHA1 Message Date
Pascal Seitz
ba3215b469 reuse samples, add EstimateColumn
estimations can be expensive since the samples span the whole column
and depending on the implementation get_val can not be easily computed
without an index.
EstimateColumn adds a view over the column which limits num_vals
to 100_000.
2022-09-25 23:54:03 +08:00
74 changed files with 257 additions and 625 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
cpp/* linguist-vendored

1
.gitignore vendored
View File

@@ -9,6 +9,7 @@ target/release
Cargo.lock
benchmark
.DS_Store
cpp/simdcomp/bitpackingbenchmark
*.bk
.idea
trace.dat

View File

@@ -277,7 +277,7 @@ impl BitSet {
self.tinyset(el / 64u32).contains(el % 64)
}
/// Returns the first non-empty `TinySet` associated with a bucket lower
/// Returns the first non-empty `TinySet` associated to a bucket lower
/// or greater than bucket.
///
/// Reminder: the tiny set with the bucket `bucket`, represents the

View File

@@ -50,7 +50,7 @@ to get tantivy to fit your use case:
*Example 1* You could for instance use hadoop to build a very large search index in a timely manner, copy all of the resulting segment files in the same directory and edit the `meta.json` to get a functional index.[^2]
*Example 2* You could also disable your merge policy and enforce daily segments. Removing data after one week can then be done very efficiently by just editing the `meta.json` and deleting the files associated with segment `D-7`.
*Example 2* You could also disable your merge policy and enforce daily segments. Removing data after one week can then be done very efficiently by just editing the `meta.json` and deleting the files associated to segment `D-7`.
## Merging

View File

@@ -113,7 +113,7 @@ fn main() -> tantivy::Result<()> {
// on its id.
//
// Note that `tantivy` does nothing to enforce the idea that
// there is only one document associated with this id.
// there is only one document associated to this id.
//
// Also you might have noticed that we apply the delete before
// having committed. This does not matter really...

View File

@@ -44,7 +44,7 @@ fn main() -> tantivy::Result<()> {
// A segment contains different data structure.
// Inverted index stands for the combination of
// - the term dictionary
// - the inverted lists associated with each terms and their positions
// - the inverted lists associated to each terms and their positions
let inverted_index = segment_reader.inverted_index(title)?;
// A `Term` is a text token associated with a field.
@@ -105,7 +105,7 @@ fn main() -> tantivy::Result<()> {
// A segment contains different data structure.
// Inverted index stands for the combination of
// - the term dictionary
// - the inverted lists associated with each terms and their positions
// - the inverted lists associated to each terms and their positions
let inverted_index = segment_reader.inverted_index(title)?;
// This segment posting object is like a cursor over the documents matching the term.

View File

@@ -18,7 +18,6 @@ fastdivide = "0.4"
log = "0.4"
itertools = { version = "0.10.3" }
measure_time = { version="0.8.2", optional=true}
roaring = "0.10.1"
[dev-dependencies]
more-asserts = "0.3.0"

View File

@@ -44,15 +44,6 @@ mod tests {
open(OwnedBytes::new(buffer)).unwrap()
}
pub fn serialize_and_load_dense<T: MonotonicallyMappableToU64 + Ord + Default>(
column: &[T],
fill_ratio: u32,
) -> Arc<dyn Column<T>> {
let mut buffer = Vec::new();
serialize(VecColumn::from(&column), &mut buffer, &ALL_CODEC_TYPES).unwrap();
open_dense(OwnedBytes::new(buffer), fill_ratio).unwrap()
}
#[bench]
fn bench_intfastfield_jumpy_veclookup(b: &mut Bencher) {
let permutation = generate_permutation();
@@ -192,67 +183,6 @@ mod tests {
});
}
#[bench]
fn bench_intfastfield_stride7_fflookup_sparse_roaring(b: &mut Bencher) {
let permutation = generate_permutation();
let n = permutation.len();
let column: Arc<dyn Column<u64>> = serialize_and_load(&permutation);
let column = SparseCodecRoaringBitmap::with_full(column);
b.iter(|| {
let mut a = 0u64;
for i in (0..n / 7).map(|val| val * 7) {
a += column.get_val(i as u64);
}
a
});
}
#[bench]
fn bench_intfastfield_stride7_fflookup_dense_bitmap_with_offset(b: &mut Bencher) {
let permutation = generate_permutation();
let n = permutation.len();
let column: Arc<dyn Column<u64>> = serialize_and_load_dense(&permutation, 1000);
b.iter(|| {
let mut a = 0u64;
for i in (0..n / 7).map(|val| val * 7) {
a += column.get_val(i as u64);
}
a
});
}
#[bench]
fn bench_intfastfield_stride7_fflookup_dense_bitmap_with_offset_70percent_dense(
b: &mut Bencher,
) {
let permutation = generate_permutation();
let n = permutation.len();
let column: Arc<dyn Column<u64>> = serialize_and_load_dense(&permutation, 700);
b.iter(|| {
let mut a = 0u64;
for i in (0..n / 7).map(|val| val * 7) {
a += column.get_val(i as u64);
}
a
});
}
#[bench]
fn bench_intfastfield_stride7_fflookup_dense_bitmap_with_offset_20percent_dense(
b: &mut Bencher,
) {
let permutation = generate_permutation();
let n = permutation.len();
let column: Arc<dyn Column<u64>> = serialize_and_load_dense(&permutation, 200);
b.iter(|| {
let mut a = 0u64;
for i in (0..n / 7).map(|val| val * 7) {
a += column.get_val(i as u64);
}
a
});
}
#[bench]
fn bench_intfastfield_scan_all_fflookup(b: &mut Bencher) {
let permutation = generate_permutation();

View File

@@ -3,6 +3,7 @@ use std::io::{self, Write};
use ownedbytes::OwnedBytes;
use tantivy_bitpacker::{compute_num_bits, BitPacker, BitUnpacker};
use crate::column::EstimateColumn;
use crate::serialize::NormalizedHeader;
use crate::{Column, FastFieldCodec, FastFieldCodecType};
@@ -75,7 +76,7 @@ impl FastFieldCodec for BitpackedCodec {
Ok(())
}
fn estimate(column: &dyn Column) -> Option<f32> {
fn estimate(column: &EstimateColumn) -> Option<f32> {
let num_bits = compute_num_bits(column.max_value());
let num_bits_uncompressed = 64;
Some(num_bits as f32 / num_bits_uncompressed as f32)

View File

@@ -5,6 +5,7 @@ use common::{BinarySerializable, CountingWriter, DeserializeFrom};
use ownedbytes::OwnedBytes;
use tantivy_bitpacker::{compute_num_bits, BitPacker, BitUnpacker};
use crate::column::EstimateColumn;
use crate::line::Line;
use crate::serialize::NormalizedHeader;
use crate::{Column, FastFieldCodec, FastFieldCodecType, VecColumn};
@@ -71,7 +72,7 @@ impl FastFieldCodec for BlockwiseLinearCodec {
}
// Estimate first_chunk and extrapolate
fn estimate(column: &dyn crate::Column) -> Option<f32> {
fn estimate(column: &EstimateColumn) -> Option<f32> {
if column.num_vals() < 10 * CHUNK_SIZE as u64 {
return None;
}

View File

@@ -4,7 +4,7 @@ use std::ops::RangeInclusive;
use tantivy_bitpacker::minmax;
pub trait Column<T: PartialOrd = u64>: Send + Sync {
/// Return the value associated with the given idx.
/// Return the value associated to the given idx.
///
/// This accessor should return as fast as possible.
///
@@ -137,6 +137,57 @@ where V: AsRef<[T]> + ?Sized
}
}
// Creates a view over a Column with a limited number of vals. Stats like min max are unchanged
pub struct EstimateColumn<'a> {
column: &'a dyn Column,
num_vals: u64,
}
impl<'a> EstimateColumn<'a> {
pub(crate) fn new(column: &'a dyn Column) -> Self {
let limit_num_vals = column.num_vals().min(100_000);
Self {
column,
num_vals: limit_num_vals,
}
}
}
impl<'a> Column for EstimateColumn<'a> {
fn get_val(&self, idx: u64) -> u64 {
(*self.column).get_val(idx)
}
fn min_value(&self) -> u64 {
(*self.column).min_value()
}
fn max_value(&self) -> u64 {
(*self.column).max_value()
}
fn num_vals(&self) -> u64 {
self.num_vals
}
fn iter<'b>(&'b self) -> Box<dyn Iterator<Item = u64> + 'b> {
Box::new((*self.column).iter().take(self.num_vals as usize))
}
fn get_range(&self, start: u64, output: &mut [u64]) {
(*self.column).get_range(start, output)
}
}
impl<'a> From<&'a dyn Column> for EstimateColumn<'a> {
fn from(column: &'a dyn Column) -> Self {
let limit_num_vals = column.num_vals().min(100_000);
Self {
column,
num_vals: limit_num_vals,
}
}
}
struct MonotonicMappingColumn<C, T, Input> {
from_column: C,
monotonic_mapping: T,

View File

@@ -11,6 +11,7 @@ use std::io;
use std::io::Write;
use std::sync::Arc;
use column::EstimateColumn;
use common::BinarySerializable;
use compact_space::CompactSpaceDecompressor;
use ownedbytes::OwnedBytes;
@@ -22,7 +23,6 @@ mod compact_space;
mod line;
mod linear;
mod monotonic_mapping;
mod sparse_codec_wrapper;
mod column;
mod gcd;
@@ -36,8 +36,6 @@ pub use self::monotonic_mapping::MonotonicallyMappableToU64;
pub use self::serialize::{
estimate, serialize, serialize_and_load, serialize_u128, NormalizedHeader,
};
pub use sparse_codec_wrapper::DenseCodec;
pub use sparse_codec_wrapper::SparseCodecRoaringBitmap;
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
#[repr(u8)]
@@ -79,44 +77,6 @@ impl FastFieldCodecType {
pub fn open_u128(bytes: OwnedBytes) -> io::Result<Arc<dyn Column<u128>>> {
Ok(Arc::new(CompactSpaceDecompressor::open(bytes)?))
}
//DenseCodec
//
/// Returns the correct codec reader wrapped in the `Arc` for the data.
pub fn open_dense<T: MonotonicallyMappableToU64>(
mut bytes: OwnedBytes,
fill_ratio: u32,
) -> io::Result<Arc<dyn Column<T>>> {
let header = Header::deserialize(&mut bytes)?;
match header.codec_type {
FastFieldCodecType::Bitpacked => {
open_specific_codec_dense::<BitpackedCodec, _>(bytes, &header, fill_ratio)
}
FastFieldCodecType::Linear => {
open_specific_codec_dense::<LinearCodec, _>(bytes, &header, fill_ratio)
}
FastFieldCodecType::BlockwiseLinear => {
open_specific_codec_dense::<BlockwiseLinearCodec, _>(bytes, &header, fill_ratio)
}
}
}
fn open_specific_codec_dense<C: FastFieldCodec, Item: MonotonicallyMappableToU64>(
bytes: OwnedBytes,
header: &Header,
fill_ratio: u32,
) -> io::Result<Arc<dyn Column<Item>>> {
let normalized_header = header.normalized();
let reader = C::open_from_bytes(bytes, normalized_header)?;
let reader = DenseCodec::with_fill_ratio(reader, fill_ratio);
let min_value = header.min_value;
if let Some(gcd) = header.gcd {
let monotonic_mapping = move |val: u64| Item::from_u64(min_value + val * gcd.get());
Ok(Arc::new(monotonic_map_column(reader, monotonic_mapping)))
} else {
let monotonic_mapping = move |val: u64| Item::from_u64(min_value + val);
Ok(Arc::new(monotonic_map_column(reader, monotonic_mapping)))
}
}
/// Returns the correct codec reader wrapped in the `Arc` for the data.
pub fn open<T: MonotonicallyMappableToU64>(
@@ -173,7 +133,7 @@ trait FastFieldCodec: 'static {
///
/// It could make sense to also return a value representing
/// computational complexity.
fn estimate(column: &dyn Column) -> Option<f32>;
fn estimate(column: &EstimateColumn) -> Option<f32>;
}
pub const ALL_CODEC_TYPES: [FastFieldCodecType; 3] = [
@@ -190,6 +150,7 @@ mod tests {
use crate::bitpacked::BitpackedCodec;
use crate::blockwise_linear::BlockwiseLinearCodec;
use crate::column::EstimateColumn;
use crate::linear::LinearCodec;
use crate::serialize::Header;
@@ -200,7 +161,9 @@ mod tests {
let col = &VecColumn::from(data);
let header = Header::compute_header(col, &[Codec::CODEC_TYPE])?;
let normalized_col = header.normalize_column(col);
let estimation = Codec::estimate(&normalized_col)?;
let limited_column = EstimateColumn::new(&normalized_col);
let estimation = Codec::estimate(&limited_column)?;
let mut out = Vec::new();
let col = VecColumn::from(data);
@@ -321,14 +284,16 @@ mod tests {
let data = (10..=20000_u64).collect::<Vec<_>>();
let data: VecColumn = data.as_slice().into();
let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();
let linear_interpol_estimation =
LinearCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_le!(linear_interpol_estimation, 0.01);
let multi_linear_interpol_estimation = BlockwiseLinearCodec::estimate(&data).unwrap();
let multi_linear_interpol_estimation =
BlockwiseLinearCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_le!(multi_linear_interpol_estimation, 0.2);
assert_lt!(linear_interpol_estimation, multi_linear_interpol_estimation);
let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
let bitpacked_estimation = BitpackedCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_lt!(linear_interpol_estimation, bitpacked_estimation);
}
#[test]
@@ -336,18 +301,20 @@ mod tests {
let data: &[u64] = &[200, 10, 10, 10, 10, 1000, 20];
let data: VecColumn = data.into();
let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();
let linear_interpol_estimation =
LinearCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_le!(linear_interpol_estimation, 0.34);
let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
let bitpacked_estimation = BitpackedCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_lt!(bitpacked_estimation, linear_interpol_estimation);
}
#[test]
fn estimation_prefer_bitpacked() {
let data = VecColumn::from(&[10, 10, 10, 10]);
let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();
let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
let linear_interpol_estimation =
LinearCodec::estimate(&EstimateColumn::new(&data)).unwrap();
let bitpacked_estimation = BitpackedCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_lt!(bitpacked_estimation, linear_interpol_estimation);
}
@@ -359,10 +326,11 @@ mod tests {
// in this case the linear interpolation can't in fact not be worse than bitpacking,
// but the estimator adds some threshold, which leads to estimated worse behavior
let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();
let linear_interpol_estimation =
LinearCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_le!(linear_interpol_estimation, 0.35);
let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
let bitpacked_estimation = BitpackedCodec::estimate(&EstimateColumn::new(&data)).unwrap();
assert_le!(bitpacked_estimation, 0.32);
assert_le!(bitpacked_estimation, linear_interpol_estimation);
}
@@ -481,7 +449,6 @@ mod bench {
let data: Vec<_> = get_data();
bench_get::<BitpackedCodec>(b, &data);
}
#[bench]
fn bench_fastfield_bitpack_get_dynamic(b: &mut Bencher) {
let data: Vec<_> = get_data();

View File

@@ -67,19 +67,11 @@ impl Line {
self.intercept.wrapping_add(linear_part)
}
// Same as train, but the intercept is only estimated from provided sample positions
pub fn estimate(ys: &dyn Column, sample_positions: &[u64]) -> Self {
Self::train_from(
ys,
sample_positions
.iter()
.cloned()
.map(|pos| (pos, ys.get_val(pos))),
)
}
// Intercept is only computed from provided positions
fn train_from(ys: &dyn Column, positions_and_values: impl Iterator<Item = (u64, u64)>) -> Self {
pub fn train_from(
ys: &dyn Column,
positions_and_values: impl Iterator<Item = (u64, u64)>,
) -> Self {
let num_vals = if let Some(num_vals) = NonZeroU64::new(ys.num_vals() - 1) {
num_vals
} else {

View File

@@ -4,6 +4,7 @@ use common::BinarySerializable;
use ownedbytes::OwnedBytes;
use tantivy_bitpacker::{compute_num_bits, BitPacker, BitUnpacker};
use crate::column::EstimateColumn;
use crate::line::Line;
use crate::serialize::NormalizedHeader;
use crate::{Column, FastFieldCodec, FastFieldCodecType};
@@ -121,23 +122,23 @@ impl FastFieldCodec for LinearCodec {
/// where the local maxima for the deviation of the calculated value are and
/// the offset to shift all values to >=0 is also unknown.
#[allow(clippy::question_mark)]
fn estimate(column: &dyn Column) -> Option<f32> {
fn estimate(column: &EstimateColumn) -> Option<f32> {
if column.num_vals() < 3 {
return None; // disable compressor for this case
}
// let's sample at 0%, 5%, 10% .. 95%, 100%
let num_vals = column.num_vals() as f32 / 100.0;
let sample_positions = (0..20)
let sample_positions_and_values = (0..20)
.map(|pos| (num_vals * pos as f32 * 5.0) as u64)
.map(|pos| (pos, column.get_val(pos)))
.collect::<Vec<_>>();
let line = Line::estimate(column, &sample_positions);
let line = { Line::train_from(column, sample_positions_and_values.iter().cloned()) };
let estimated_bit_width = sample_positions
let estimated_bit_width = sample_positions_and_values
.into_iter()
.map(|pos| {
let actual_value = column.get_val(pos);
.map(|(pos, actual_value)| {
let interpolated_val = line.eval(pos as u64);
actual_value.wrapping_sub(interpolated_val)
})

View File

@@ -1,42 +0,0 @@
use std::net::{IpAddr, Ipv6Addr};
pub trait MonotonicallyMappableToU128: 'static + PartialOrd + Copy + Send + Sync {
/// Converts a value to u128.
///
/// Internally all fast field values are encoded as u64.
fn to_u128(self) -> u128;
/// Converts a value from u128
///
/// Internally all fast field values are encoded as u64.
/// **Note: To be used for converting encoded Term, Posting values.**
fn from_u128(val: u128) -> Self;
}
impl MonotonicallyMappableToU128 for u128 {
fn to_u128(self) -> u128 {
self
}
fn from_u128(val: u128) -> Self {
val
}
}
impl MonotonicallyMappableToU128 for IpAddr {
fn to_u128(self) -> u128 {
ip_to_u128(self)
}
fn from_u128(val: u128) -> Self {
IpAddr::from(val.to_be_bytes())
}
}
fn ip_to_u128(ip_addr: IpAddr) -> u128 {
let ip_addr_v6: Ipv6Addr = match ip_addr {
IpAddr::V4(v4) => v4.to_ipv6_mapped(),
IpAddr::V6(v6) => v6,
};
u128::from_be_bytes(ip_addr_v6.octets())
}

View File

@@ -28,6 +28,7 @@ use ownedbytes::OwnedBytes;
use crate::bitpacked::BitpackedCodec;
use crate::blockwise_linear::BlockwiseLinearCodec;
use crate::column::EstimateColumn;
use crate::compact_space::CompactSpaceCompressor;
use crate::linear::LinearCodec;
use crate::{
@@ -125,23 +126,6 @@ impl BinarySerializable for Header {
}
}
pub fn estimate<T: MonotonicallyMappableToU64>(
typed_column: impl Column<T>,
codec_type: FastFieldCodecType,
) -> Option<f32> {
let column = monotonic_map_column(typed_column, T::to_u64);
let min_value = column.min_value();
let gcd = crate::gcd::find_gcd(column.iter().map(|val| val - min_value))
.filter(|gcd| gcd.get() > 1u64);
let divider = DividerU64::divide_by(gcd.map(|gcd| gcd.get()).unwrap_or(1u64));
let normalized_column = monotonic_map_column(&column, |val| divider.divide(val - min_value));
match codec_type {
FastFieldCodecType::Bitpacked => BitpackedCodec::estimate(&normalized_column),
FastFieldCodecType::Linear => LinearCodec::estimate(&normalized_column),
FastFieldCodecType::BlockwiseLinear => BlockwiseLinearCodec::estimate(&normalized_column),
}
}
pub fn serialize_u128(
typed_column: impl Column<u128>,
output: &mut impl io::Write,
@@ -177,10 +161,29 @@ pub fn serialize<T: MonotonicallyMappableToU64>(
Ok(())
}
pub fn estimate<T: MonotonicallyMappableToU64>(
typed_column: impl Column<T>,
codec_type: FastFieldCodecType,
) -> Option<f32> {
let column = monotonic_map_column(typed_column, T::to_u64);
let min_value = column.min_value();
let gcd = crate::gcd::find_gcd(column.iter().map(|val| val - min_value))
.filter(|gcd| gcd.get() > 1u64);
let divider = DividerU64::divide_by(gcd.map(|gcd| gcd.get()).unwrap_or(1u64));
let normalized_column = monotonic_map_column(&column, |val| divider.divide(val - min_value));
let estimate_column = EstimateColumn::new(&normalized_column);
match codec_type {
FastFieldCodecType::Bitpacked => BitpackedCodec::estimate(&estimate_column),
FastFieldCodecType::Linear => LinearCodec::estimate(&estimate_column),
FastFieldCodecType::BlockwiseLinear => BlockwiseLinearCodec::estimate(&estimate_column),
}
}
fn detect_codec(
column: impl Column<u64>,
codecs: &[FastFieldCodecType],
) -> Option<FastFieldCodecType> {
let column: EstimateColumn = EstimateColumn::new(&column);
let mut estimations = Vec::new();
for &codec in codecs {
let estimation_opt = match codec {

View File

@@ -1,157 +0,0 @@
use std::sync::Arc;
use rand::{thread_rng, Rng};
use roaring::RoaringBitmap;
use crate::Column;
pub struct SparseCodecRoaringBitmap {
null: RoaringBitmap,
column: Arc<dyn Column<u64>>, // column: C,
}
impl SparseCodecRoaringBitmap {
pub fn with_full(column: Arc<dyn Column<u64>>) -> Self {
let mut rb = RoaringBitmap::new();
rb.insert_range(0..column.num_vals() as u32 + 1);
Self { null: rb, column }
}
}
impl Column for SparseCodecRoaringBitmap {
fn get_val(&self, idx: u64) -> u64 {
let position_of_val = self.null.rank(idx as u32);
self.column.get_val(position_of_val) // TODO this does not handle null!
// self.null.select(num_vals)
}
fn min_value(&self) -> u64 {
todo!()
}
fn max_value(&self) -> u64 {
todo!()
}
fn num_vals(&self) -> u64 {
todo!()
}
}
pub struct DenseCodec<C> {
// the bitmap blocks of length 64 bit each
blocks: Vec<u64>,
// the offset for each block
offsets: Vec<u32>,
column: C, // column: C,
}
impl<C: Column> DenseCodec<C> {
// fill ratio valid range 0..1000 1000 == all elements, 1 == every 1000th element
pub fn with_fill_ratio(column: C, fill_ratio: u32) -> Self {
let mut rng = thread_rng();
let num_blocks = (column.num_vals() as usize / 64) + 1;
let mut blocks = Vec::with_capacity(num_blocks);
let mut offsets = Vec::with_capacity(num_blocks);
// fill all blocks
let mut offset = 0;
for _block_num in 0..num_blocks {
let mut block = 0;
for n in 0..64 {
if rng.gen_range(0..=1000) <= fill_ratio {
set_bit_at(&mut block, n);
}
}
blocks.push(block);
offsets.push(offset);
offset += block.count_ones();
}
Self {
blocks,
offsets,
column,
}
}
pub fn with_full(column: C) -> Self {
let num_blocks = (column.num_vals() as usize / 64) + 1;
let mut blocks = Vec::with_capacity(num_blocks);
let mut offsets = Vec::with_capacity(num_blocks);
// fill all blocks
let mut offset = 0;
for _block_num in 0..num_blocks {
let block = u64::MAX;
blocks.push(block);
offsets.push(offset);
offset += block.count_ones();
}
Self {
blocks,
offsets,
column,
}
}
}
fn gen_mask(msb: u64) -> u64 {
let src = 1 << msb;
src - 1
}
fn get_bit_at(input: u64, n: u64) -> bool {
input & (1 << n) != 0
}
fn set_bit_at(input: &mut u64, n: u64) {
*input |= 1 << n;
}
impl<C: Column> Column for DenseCodec<C> {
fn get_val(&self, idx: u64) -> u64 {
let block_pos = idx / 64;
let pos_in_block = idx % 64;
let offset = self.offsets[block_pos as usize];
let bitvec = self.blocks[block_pos as usize];
let offset_in_block = (bitvec & gen_mask(pos_in_block)).count_ones();
let dense_idx = offset as u64 + offset_in_block as u64;
if get_bit_at(bitvec, pos_in_block) {
self.column.get_val(dense_idx)
} else {
0 // TODO null
}
}
fn min_value(&self) -> u64 {
todo!()
}
fn max_value(&self) -> u64 {
todo!()
}
fn num_vals(&self) -> u64 {
todo!()
}
}
#[cfg(test)]
mod tests {
//use itertools::Itertools;
//use super::*;
//use crate::serialize_and_load;
//#[test]
//fn dense_test() {
//let data = (0..100u64).collect_vec();
//{
//let column = serialize_and_load(&data);
//let dense = DenseCodec::with_full(column);
//for i in 0..100 {
//dense.get_val(i);
//}
//}
//}
}

View File

@@ -38,7 +38,7 @@ pub trait CustomSegmentScorer<TScore>: 'static {
pub trait CustomScorer<TScore>: Sync {
/// Type of the associated [`CustomSegmentScorer`].
type Child: CustomSegmentScorer<TScore>;
/// Builds a child scorer for a specific segment. The child scorer is associated with
/// Builds a child scorer for a specific segment. The child scorer is associated to
/// a specific segment.
fn segment_scorer(&self, segment_reader: &SegmentReader) -> crate::Result<Self::Child>;
}

View File

@@ -91,7 +91,7 @@ fn facet_depth(facet_bytes: &[u8]) -> usize {
/// let index = Index::create_in_ram(schema);
/// {
/// let mut index_writer = index.writer(3_000_000)?;
/// // a document can be associated with any number of facets
/// // a document can be associated to any number of facets
/// index_writer.add_document(doc!(
/// title => "The Name of the Wind",
/// facet => Facet::from("/lang/en"),

View File

@@ -37,7 +37,7 @@ impl HistogramCollector {
/// The scale/range of the histogram is not dynamic. It is required to
/// define it by supplying following parameter:
/// - `min_value`: the minimum value that can be recorded in the histogram.
/// - `bucket_width`: the length of the interval that is associated with each buckets.
/// - `bucket_width`: the length of the interval that is associated to each buckets.
/// - `num_buckets`: The overall number of buckets.
///
/// Together, this parameters define a partition of `[min_value, min_value + num_buckets *

View File

@@ -142,7 +142,7 @@ pub trait Collector: Sync + Send {
/// e.g. `usize` for the `Count` collector.
type Fruit: Fruit;
/// Type of the `SegmentCollector` associated with this collector.
/// Type of the `SegmentCollector` associated to this collector.
type Child: SegmentCollector;
/// `set_segment` is called before beginning to enumerate
@@ -156,7 +156,7 @@ pub trait Collector: Sync + Send {
/// Returns true iff the collector requires to compute scores for documents.
fn requires_scoring(&self) -> bool;
/// Combines the fruit associated with the collection of each segments
/// Combines the fruit associated to the collection of each segments
/// into one fruit.
fn merge_fruits(
&self,

View File

@@ -693,7 +693,7 @@ impl Collector for TopDocs {
}
}
/// Segment Collector associated with `TopDocs`.
/// Segment Collector associated to `TopDocs`.
pub struct TopScoreSegmentCollector(TopSegmentCollector<Score>);
impl SegmentCollector for TopScoreSegmentCollector {

View File

@@ -40,7 +40,7 @@ pub trait ScoreTweaker<TScore>: Sync {
/// Type of the associated [`ScoreSegmentTweaker`].
type Child: ScoreSegmentTweaker<TScore>;
/// Builds a child tweaker for a specific segment. The child scorer is associated with
/// Builds a child tweaker for a specific segment. The child scorer is associated to
/// a specific segment.
fn segment_tweaker(&self, segment_reader: &SegmentReader) -> Result<Self::Child>;
}

View File

@@ -130,7 +130,7 @@ impl SegmentMeta {
/// Returns the relative path of a component of our segment.
///
/// It just joins the segment id with the extension
/// associated with a segment component.
/// associated to a segment component.
pub fn relative_path(&self, component: SegmentComponent) -> PathBuf {
let mut path = self.id().uuid_string();
path.push_str(&*match component {
@@ -326,13 +326,13 @@ pub struct IndexMeta {
/// `IndexSettings` to configure index options.
#[serde(default)]
pub index_settings: IndexSettings,
/// List of `SegmentMeta` information associated with each finalized segment of the index.
/// List of `SegmentMeta` information associated to each finalized segment of the index.
pub segments: Vec<SegmentMeta>,
/// Index `Schema`
pub schema: Schema,
/// Opstamp associated with the last `commit` operation.
/// Opstamp associated to the last `commit` operation.
pub opstamp: Opstamp,
/// Payload associated with the last commit.
/// Payload associated to the last commit.
///
/// Upon commit, clients can optionally add a small `String` payload to their commit
/// to help identify this commit.

View File

@@ -9,11 +9,11 @@ use crate::schema::{IndexRecordOption, Term};
use crate::termdict::TermDictionary;
/// The inverted index reader is in charge of accessing
/// the inverted index associated with a specific field.
/// the inverted index associated to a specific field.
///
/// # Note
///
/// It is safe to delete the segment associated with
/// It is safe to delete the segment associated to
/// an `InvertedIndexReader`. As long as it is open,
/// the `FileSlice` it is relying on should
/// stay available.
@@ -30,7 +30,7 @@ pub struct InvertedIndexReader {
}
impl InvertedIndexReader {
#[allow(clippy::needless_pass_by_value)] // for symmetry
#[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] // for symmetry
pub(crate) fn new(
termdict: TermDictionary,
postings_file_slice: FileSlice,

View File

@@ -69,7 +69,7 @@ pub struct Searcher {
}
impl Searcher {
/// Returns the `Index` associated with the `Searcher`
/// Returns the `Index` associated to the `Searcher`
pub fn index(&self) -> &Index {
&self.inner.index
}
@@ -108,7 +108,7 @@ impl Searcher {
store_reader.get_async(doc_address.doc_id).await
}
/// Access the schema associated with the index of this searcher.
/// Access the schema associated to the index of this searcher.
pub fn schema(&self) -> &Schema {
&self.inner.schema
}
@@ -161,11 +161,11 @@ impl Searcher {
///
/// Search works as follows :
///
/// First the weight object associated with the query is created.
/// First the weight object associated to the query is created.
///
/// Then, the query loops over the segments and for each segment :
/// - setup the collector and informs it that the segment being processed has changed.
/// - creates a SegmentCollector for collecting documents associated with the segment
/// - creates a SegmentCollector for collecting documents associated to the segment
/// - creates a `Scorer` object associated for this segment
/// - iterate through the matched documents and push them to the segment collector.
///

View File

@@ -70,7 +70,7 @@ impl Segment {
/// Returns the relative path of a component of our segment.
///
/// It just joins the segment id with the extension
/// associated with a segment component.
/// associated to a segment component.
pub fn relative_path(&self, component: SegmentComponent) -> PathBuf {
self.meta.relative_path(component)
}

View File

@@ -6,7 +6,7 @@ use std::slice;
/// except the delete component that takes an `segment_uuid`.`delete_opstamp`.`component_extension`
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum SegmentComponent {
/// Postings (or inverted list). Sorted lists of document ids, associated with terms
/// Postings (or inverted list). Sorted lists of document ids, associated to terms
Postings,
/// Positions of terms in each document.
Positions,

View File

@@ -89,7 +89,7 @@ impl SegmentReader {
&self.fast_fields_readers
}
/// Accessor to the `FacetReader` associated with a given `Field`.
/// Accessor to the `FacetReader` associated to a given `Field`.
pub fn facet_reader(&self, field: Field) -> crate::Result<FacetReader> {
let field_entry = self.schema.get_field_entry(field);
@@ -208,13 +208,13 @@ impl SegmentReader {
})
}
/// Returns a field reader associated with the field given in argument.
/// Returns a field reader associated to the field given in argument.
/// If the field was not present in the index during indexing time,
/// the InvertedIndexReader is empty.
///
/// The field reader is in charge of iterating through the
/// term dictionary associated with a specific field,
/// and opening the posting list associated with any term.
/// term dictionary associated to a specific field,
/// and opening the posting list associated to any term.
///
/// If the field is not marked as index, a warn is logged and an empty `InvertedIndexReader`
/// is returned.
@@ -241,7 +241,7 @@ impl SegmentReader {
if postings_file_opt.is_none() || record_option_opt.is_none() {
// no documents in the segment contained this field.
// As a result, no data is associated with the inverted index.
// As a result, no data is associated to the inverted index.
//
// Returns an empty inverted index.
let record_option = record_option_opt.unwrap_or(IndexRecordOption::Basic);

View File

@@ -154,14 +154,14 @@ impl CompositeFile {
}
}
/// Returns the `FileSlice` associated with
/// a given `Field` and stored in a `CompositeFile`.
/// Returns the `FileSlice` associated
/// to a given `Field` and stored in a `CompositeFile`.
pub fn open_read(&self, field: Field) -> Option<FileSlice> {
self.open_read_with_idx(field, 0)
}
/// Returns the `FileSlice` associated with
/// a given `Field` and stored in a `CompositeFile`.
/// Returns the `FileSlice` associated
/// to a given `Field` and stored in a `CompositeFile`.
pub fn open_read_with_idx(&self, field: Field, idx: usize) -> Option<FileSlice> {
self.offsets_index
.get(&FileAddr { field, idx })

View File

@@ -39,7 +39,7 @@ impl RetryPolicy {
/// The `DirectoryLock` is an object that represents a file lock.
///
/// It is associated with a lock file, that gets deleted on `Drop.`
/// It is associated to a lock file, that gets deleted on `Drop.`
pub struct DirectoryLock(Box<dyn Send + Sync + 'static>);
struct DirectoryLockGuard {

View File

@@ -1,5 +1,5 @@
use std::ops::{Deref, Range};
use std::sync::Arc;
use std::sync::{Arc, Weak};
use std::{fmt, io};
use async_trait::async_trait;
@@ -8,6 +8,9 @@ use stable_deref_trait::StableDeref;
use crate::directory::OwnedBytes;
pub type ArcBytes = Arc<dyn Deref<Target = [u8]> + Send + Sync + 'static>;
pub type WeakArcBytes = Weak<dyn Deref<Target = [u8]> + Send + Sync + 'static>;
/// Objects that represents files sections in tantivy.
///
/// By contract, whatever happens to the directory file, as long as a FileHandle

View File

@@ -9,7 +9,7 @@ use crc32fast::Hasher;
use crate::directory::{WatchCallback, WatchCallbackList, WatchHandle};
const POLLING_INTERVAL: Duration = Duration::from_millis(if cfg!(test) { 1 } else { 500 });
pub const POLLING_INTERVAL: Duration = Duration::from_millis(if cfg!(test) { 1 } else { 500 });
// Watches a file and executes registered callbacks when the file is modified.
pub struct FileWatcher {

View File

@@ -3,7 +3,7 @@ use std::fs::{self, File, OpenOptions};
use std::io::{self, BufWriter, Read, Seek, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock, Weak};
use std::sync::{Arc, RwLock};
use std::{fmt, result};
use fs2::FileExt;
@@ -18,13 +18,10 @@ use crate::directory::error::{
};
use crate::directory::file_watcher::FileWatcher;
use crate::directory::{
AntiCallToken, Directory, DirectoryLock, FileHandle, Lock, OwnedBytes, TerminatingWrite,
WatchCallback, WatchHandle, WritePtr,
AntiCallToken, ArcBytes, Directory, DirectoryLock, FileHandle, Lock, OwnedBytes,
TerminatingWrite, WatchCallback, WatchHandle, WeakArcBytes, WritePtr,
};
pub type ArcBytes = Arc<dyn Deref<Target = [u8]> + Send + Sync + 'static>;
pub type WeakArcBytes = Weak<dyn Deref<Target = [u8]> + Send + Sync + 'static>;
/// Create a default io error given a string.
pub(crate) fn make_io_err(msg: String) -> io::Error {
io::Error::new(io::ErrorKind::Other, msg)
@@ -337,7 +334,7 @@ impl Directory for MmapDirectory {
Ok(Arc::new(owned_bytes))
}
/// Any entry associated with the path in the mmap will be
/// Any entry associated to the path in the mmap will be
/// removed before the file is deleted.
fn delete(&self, path: &Path) -> result::Result<(), DeleteError> {
let full_path = self.resolve_path(path);

View File

@@ -26,6 +26,7 @@ pub use ownedbytes::OwnedBytes;
pub(crate) use self::composite_file::{CompositeFile, CompositeWrite};
pub use self::directory::{Directory, DirectoryClone, DirectoryLock};
pub use self::directory_lock::{Lock, INDEX_WRITER_LOCK, META_LOCK};
pub(crate) use self::file_slice::{ArcBytes, WeakArcBytes};
pub use self::file_slice::{FileHandle, FileSlice};
pub use self::ram_directory::RamDirectory;
pub use self::watch_event_router::{WatchCallback, WatchCallbackList, WatchHandle};

View File

@@ -1,4 +1,3 @@
use std::ops::Range;
use std::sync::Arc;
use fastfield_codecs::Column;
@@ -32,39 +31,36 @@ impl BytesFastFieldReader {
Ok(BytesFastFieldReader { idx_reader, values })
}
fn range(&self, doc: DocId) -> Range<u64> {
fn range(&self, doc: DocId) -> (usize, usize) {
let idx = doc as u64;
let start = self.idx_reader.get_val(idx);
let end = self.idx_reader.get_val(idx + 1);
start..end
let start = self.idx_reader.get_val(idx) as usize;
let stop = self.idx_reader.get_val(idx + 1) as usize;
(start, stop)
}
/// Returns the bytes associated with the given `doc`
/// Returns the bytes associated to the given `doc`
pub fn get_bytes(&self, doc: DocId) -> &[u8] {
let range = self.range(doc);
&self.values.as_slice()[range.start as usize..range.end as usize]
let (start, stop) = self.range(doc);
&self.values.as_slice()[start..stop]
}
/// Returns the length of the bytes associated with the given `doc`
pub fn num_bytes(&self, doc: DocId) -> u64 {
let range = self.range(doc);
range.end - range.start
/// Returns the length of the bytes associated to the given `doc`
pub fn num_bytes(&self, doc: DocId) -> usize {
let (start, stop) = self.range(doc);
stop - start
}
/// Returns the overall number of bytes in this bytes fast field.
pub fn total_num_bytes(&self) -> u64 {
self.values.len() as u64
pub fn total_num_bytes(&self) -> usize {
self.values.len()
}
}
impl MultiValueLength for BytesFastFieldReader {
fn get_range(&self, doc_id: DocId) -> std::ops::Range<u64> {
self.range(doc_id)
}
fn get_len(&self, doc_id: DocId) -> u64 {
self.num_bytes(doc_id)
self.num_bytes(doc_id) as u64
}
fn get_total_len(&self) -> u64 {
self.total_num_bytes()
self.total_num_bytes() as u64
}
}

View File

@@ -24,7 +24,7 @@ use crate::DocId;
///
/// Once acquired, writing is done by calling
/// [`.add_document_val(&[u8])`](BytesFastFieldWriter::add_document_val)
/// once per document, even if there are no bytes associated with it.
/// once per document, even if there are no bytes associated to it.
pub struct BytesFastFieldWriter {
field: Field,
vals: Vec<u8>,
@@ -45,7 +45,7 @@ impl BytesFastFieldWriter {
pub fn mem_usage(&self) -> usize {
self.vals.capacity() + self.doc_index.capacity() * std::mem::size_of::<u64>()
}
/// Access the field associated with the `BytesFastFieldWriter`
/// Access the field associated to the `BytesFastFieldWriter`
pub fn field(&self) -> Field {
self.field
}
@@ -67,7 +67,7 @@ impl BytesFastFieldWriter {
}
}
/// Register the bytes associated with a document.
/// Register the bytes associated to a document.
///
/// The method returns the `DocId` of the document that was
/// just written.

View File

@@ -7,7 +7,7 @@ use crate::termdict::{TermDictionary, TermOrdinal};
use crate::DocId;
/// The facet reader makes it possible to access the list of
/// facets associated with a given document in a specific
/// facets associated to a given document in a specific
/// segment.
///
/// Rather than manipulating `Facet` object directly, the API
@@ -58,7 +58,7 @@ impl FacetReader {
&self.term_dict
}
/// Given a term ordinal returns the term associated with it.
/// Given a term ordinal returns the term associated to it.
pub fn facet_from_ord(
&mut self,
facet_ord: TermOrdinal,
@@ -74,7 +74,7 @@ impl FacetReader {
Ok(())
}
/// Return the list of facet ordinals associated with a document.
/// Return the list of facet ordinals associated to a document.
pub fn facet_ords(&self, doc: DocId, output: &mut Vec<u64>) {
self.term_ords.get_vals(doc, output);
}

View File

@@ -47,9 +47,7 @@ mod writer;
/// Trait for `BytesFastFieldReader` and `MultiValuedFastFieldReader` to return the length of data
/// for a doc_id
pub trait MultiValueLength {
/// returns the positions for a docid
fn get_range(&self, doc_id: DocId) -> std::ops::Range<u64>;
/// returns the num of values associated with a doc_id
/// returns the num of values associated to a doc_id
fn get_len(&self, doc_id: DocId) -> u64;
/// returns the sum of num values for all doc_ids
fn get_total_len(&self) -> u64;

View File

@@ -30,8 +30,8 @@ impl<Item: FastValue> MultiValuedFastFieldReader<Item> {
}
}
/// Returns `[start, end)`, such that the values associated with
/// the given document are `start..end`.
/// Returns `[start, end)`, such that the values associated
/// to the given document are `start..end`.
#[inline]
fn range(&self, doc: DocId) -> Range<u64> {
let idx = doc as u64;
@@ -40,7 +40,7 @@ impl<Item: FastValue> MultiValuedFastFieldReader<Item> {
start..end
}
/// Returns the array of values associated with the given `doc`.
/// Returns the array of values associated to the given `doc`.
#[inline]
fn get_vals_for_range(&self, range: Range<u64>, vals: &mut Vec<Item>) {
let len = (range.end - range.start) as usize;
@@ -48,7 +48,7 @@ impl<Item: FastValue> MultiValuedFastFieldReader<Item> {
self.vals_reader.get_range(range.start, &mut vals[..]);
}
/// Returns the array of values associated with the given `doc`.
/// Returns the array of values associated to the given `doc`.
#[inline]
pub fn get_vals(&self, doc: DocId, vals: &mut Vec<Item>) {
let range = self.range(doc);
@@ -88,9 +88,6 @@ impl<Item: FastValue> MultiValuedFastFieldReader<Item> {
}
impl<Item: FastValue> MultiValueLength for MultiValuedFastFieldReader<Item> {
fn get_range(&self, doc_id: DocId) -> Range<u64> {
self.range(doc_id)
}
fn get_len(&self, doc_id: DocId) -> u64 {
self.num_vals(doc_id) as u64
}

View File

@@ -62,7 +62,7 @@ impl MultiValuedFastFieldWriter {
+ self.doc_index.capacity() * std::mem::size_of::<u64>()
}
/// Access the field associated with the `MultiValuedFastFieldWriter`
/// Access the field associated to the `MultiValuedFastFieldWriter`
pub fn field(&self) -> Field {
self.field
}

View File

@@ -135,7 +135,7 @@ impl FastFieldReaders {
Ok(MultiValuedFastFieldReader::open(idx_reader, vals_reader))
}
/// Returns the `u64` fast field reader reader associated with `field`.
/// Returns the `u64` fast field reader reader associated to `field`.
///
/// If `field` is not a u64 fast field, this method returns an Error.
pub fn u64(&self, field: Field) -> crate::Result<Arc<dyn Column<u64>>> {
@@ -143,16 +143,16 @@ impl FastFieldReaders {
self.typed_fast_field_reader(field)
}
/// Returns the `u64` fast field reader reader associated with `field`, regardless of whether
/// the given field is effectively of type `u64` or not.
/// Returns the `u64` fast field reader reader associated to `field`, regardless of whether the
/// given field is effectively of type `u64` or not.
///
/// If not, the fastfield reader will returns the u64-value associated with the original
/// If not, the fastfield reader will returns the u64-value associated to the original
/// FastValue.
pub fn u64_lenient(&self, field: Field) -> crate::Result<Arc<dyn Column<u64>>> {
self.typed_fast_field_reader(field)
}
/// Returns the `i64` fast field reader reader associated with `field`.
/// Returns the `i64` fast field reader reader associated to `field`.
///
/// If `field` is not a i64 fast field, this method returns an Error.
pub fn i64(&self, field: Field) -> crate::Result<Arc<dyn Column<i64>>> {
@@ -160,7 +160,7 @@ impl FastFieldReaders {
self.typed_fast_field_reader(field)
}
/// Returns the `date` fast field reader reader associated with `field`.
/// Returns the `date` fast field reader reader associated to `field`.
///
/// If `field` is not a date fast field, this method returns an Error.
pub fn date(&self, field: Field) -> crate::Result<Arc<dyn Column<DateTime>>> {
@@ -168,7 +168,7 @@ impl FastFieldReaders {
self.typed_fast_field_reader(field)
}
/// Returns the `f64` fast field reader reader associated with `field`.
/// Returns the `f64` fast field reader reader associated to `field`.
///
/// If `field` is not a f64 fast field, this method returns an Error.
pub fn f64(&self, field: Field) -> crate::Result<Arc<dyn Column<f64>>> {
@@ -176,7 +176,7 @@ impl FastFieldReaders {
self.typed_fast_field_reader(field)
}
/// Returns the `bool` fast field reader reader associated with `field`.
/// Returns the `bool` fast field reader reader associated to `field`.
///
/// If `field` is not a bool fast field, this method returns an Error.
pub fn bool(&self, field: Field) -> crate::Result<Arc<dyn Column<bool>>> {
@@ -184,7 +184,7 @@ impl FastFieldReaders {
self.typed_fast_field_reader(field)
}
/// Returns a `u64s` multi-valued fast field reader reader associated with `field`.
/// Returns a `u64s` multi-valued fast field reader reader associated to `field`.
///
/// If `field` is not a u64 multi-valued fast field, this method returns an Error.
pub fn u64s(&self, field: Field) -> crate::Result<MultiValuedFastFieldReader<u64>> {
@@ -192,15 +192,15 @@ impl FastFieldReaders {
self.typed_fast_field_multi_reader(field)
}
/// Returns a `u64s` multi-valued fast field reader reader associated with `field`, regardless
/// of whether the given field is effectively of type `u64` or not.
/// Returns a `u64s` multi-valued fast field reader reader associated to `field`, regardless of
/// whether the given field is effectively of type `u64` or not.
///
/// If `field` is not a u64 multi-valued fast field, this method returns an Error.
pub fn u64s_lenient(&self, field: Field) -> crate::Result<MultiValuedFastFieldReader<u64>> {
self.typed_fast_field_multi_reader(field)
}
/// Returns a `i64s` multi-valued fast field reader reader associated with `field`.
/// Returns a `i64s` multi-valued fast field reader reader associated to `field`.
///
/// If `field` is not a i64 multi-valued fast field, this method returns an Error.
pub fn i64s(&self, field: Field) -> crate::Result<MultiValuedFastFieldReader<i64>> {
@@ -208,7 +208,7 @@ impl FastFieldReaders {
self.typed_fast_field_multi_reader(field)
}
/// Returns a `f64s` multi-valued fast field reader reader associated with `field`.
/// Returns a `f64s` multi-valued fast field reader reader associated to `field`.
///
/// If `field` is not a f64 multi-valued fast field, this method returns an Error.
pub fn f64s(&self, field: Field) -> crate::Result<MultiValuedFastFieldReader<f64>> {
@@ -216,7 +216,7 @@ impl FastFieldReaders {
self.typed_fast_field_multi_reader(field)
}
/// Returns a `bools` multi-valued fast field reader reader associated with `field`.
/// Returns a `bools` multi-valued fast field reader reader associated to `field`.
///
/// If `field` is not a bool multi-valued fast field, this method returns an Error.
pub fn bools(&self, field: Field) -> crate::Result<MultiValuedFastFieldReader<bool>> {
@@ -224,7 +224,7 @@ impl FastFieldReaders {
self.typed_fast_field_multi_reader(field)
}
/// Returns a `time::OffsetDateTime` multi-valued fast field reader reader associated with
/// Returns a `time::OffsetDateTime` multi-valued fast field reader reader associated to
/// `field`.
///
/// If `field` is not a `time::OffsetDateTime` multi-valued fast field, this method returns an
@@ -234,7 +234,7 @@ impl FastFieldReaders {
self.typed_fast_field_multi_reader(field)
}
/// Returns the `bytes` fast field reader associated with `field`.
/// Returns the `bytes` fast field reader associated to `field`.
///
/// If `field` is not a bytes fast field, returns an Error.
pub fn bytes(&self, field: Field) -> crate::Result<BytesFastFieldReader> {

View File

@@ -131,7 +131,7 @@ impl FastFieldsWriter {
.sum::<usize>()
}
/// Get the `FastFieldWriter` associated with a field.
/// Get the `FastFieldWriter` associated to a field.
pub fn get_term_id_writer(&self, field: Field) -> Option<&MultiValuedFastFieldWriter> {
// TODO optimize
self.term_id_writers
@@ -139,7 +139,7 @@ impl FastFieldsWriter {
.find(|field_writer| field_writer.field() == field)
}
/// Get the `FastFieldWriter` associated with a field.
/// Get the `FastFieldWriter` associated to a field.
pub fn get_field_writer(&self, field: Field) -> Option<&IntFastFieldWriter> {
// TODO optimize
self.single_value_writers
@@ -147,7 +147,7 @@ impl FastFieldsWriter {
.find(|field_writer| field_writer.field() == field)
}
/// Get the `FastFieldWriter` associated with a field.
/// Get the `FastFieldWriter` associated to a field.
pub fn get_field_writer_mut(&mut self, field: Field) -> Option<&mut IntFastFieldWriter> {
// TODO optimize
self.single_value_writers
@@ -155,7 +155,7 @@ impl FastFieldsWriter {
.find(|field_writer| field_writer.field() == field)
}
/// Get the `FastFieldWriter` associated with a field.
/// Get the `FastFieldWriter` associated to a field.
pub fn get_term_id_writer_mut(
&mut self,
field: Field,
@@ -294,7 +294,7 @@ impl IntFastFieldWriter {
/// Records a new value.
///
/// The n-th value being recorded is implicitly
/// associated with the document with the `DocId` n.
/// associated to the document with the `DocId` n.
/// (Well, `n-1` actually because of 0-indexing)
pub fn add_val(&mut self, val: u64) {
self.vals.add(val);
@@ -313,7 +313,7 @@ impl IntFastFieldWriter {
/// (or use the default value) and records it.
///
///
/// Extract the value associated with the fast field for
/// Extract the value associated to the fast field for
/// this document.
///
/// i64 and f64 are remapped to u64 using the logic
@@ -383,7 +383,7 @@ struct WriterFastFieldAccessProvider<'map, 'bitp> {
}
impl<'map, 'bitp> Column for WriterFastFieldAccessProvider<'map, 'bitp> {
/// Return the value associated with the given doc.
/// Return the value associated to the given doc.
///
/// Whenever possible use the Iterator passed to the fastfield creation instead, for performance
/// reasons.

View File

@@ -1,4 +1,4 @@
//! The fieldnorm represents the length associated with
//! The fieldnorm represents the length associated to
//! a given Field of a given document.
//!
//! This metric is important to compute the score of a

View File

@@ -47,9 +47,9 @@ impl FieldNormReaders {
}
}
/// Reads the fieldnorm associated with a document.
/// Reads the fieldnorm associated to a document.
///
/// The [fieldnorm](FieldNormReader::fieldnorm) represents the length associated with
/// The [fieldnorm](FieldNormReader::fieldnorm) represents the length associated to
/// a given Field of a given document.
#[derive(Clone)]
pub struct FieldNormReader(ReaderImplEnum);
@@ -104,7 +104,7 @@ impl FieldNormReader {
}
}
/// Returns the `fieldnorm` associated with a doc id.
/// Returns the `fieldnorm` associated to a doc id.
/// The fieldnorm is a value approximating the number
/// of tokens in a given field of the `doc_id`.
///
@@ -123,7 +123,7 @@ impl FieldNormReader {
}
}
/// Returns the `fieldnorm_id` associated with a document.
/// Returns the `fieldnorm_id` associated to a document.
#[inline]
pub fn fieldnorm_id(&self, doc_id: DocId) -> u8 {
match &self.0 {

View File

@@ -188,7 +188,7 @@ impl DeleteCursor {
}
}
#[allow(clippy::wrong_self_convention)]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))]
fn is_behind_opstamp(&mut self, target_opstamp: Opstamp) -> bool {
self.get()
.map(|operation| operation.opstamp < target_opstamp)

View File

@@ -24,7 +24,7 @@ impl SegmentDocIdMapping {
/// Returns an iterator over the old document addresses, ordered by the new document ids.
///
/// In the returned `DocAddress`, the `segment_ord` is the ordinal of targeted segment
/// In the returned `DocAddress`, the `segment_ord` is the ordinal of targetted segment
/// in the list of merged segments.
pub(crate) fn iter_old_doc_addrs(&self) -> impl Iterator<Item = DocAddress> + '_ {
self.new_doc_id_to_old_doc_addr.iter().copied()

View File

@@ -370,9 +370,9 @@ impl IndexWriter {
/// This method is useful only for users trying to do complex
/// operations, like converting an index format to another.
///
/// It is safe to start writing file associated with the new `Segment`.
/// It is safe to start writing file associated to the new `Segment`.
/// These will not be garbage collected as long as an instance object of
/// `SegmentMeta` object associated with the new `Segment` is "alive".
/// `SegmentMeta` object associated to the new `Segment` is "alive".
pub fn new_segment(&self) -> Segment {
self.index.new_segment()
}

View File

@@ -17,7 +17,7 @@ impl<'a> PreparedCommit<'a> {
}
}
/// Returns the opstamp associated with the prepared commit.
/// Returns the opstamp associated to the prepared commit.
pub fn opstamp(&self) -> Opstamp {
self.opstamp
}

View File

@@ -72,9 +72,13 @@ impl<'a> SortedDocIdMultiValueColumn<'a> {
impl<'a> Column for SortedDocIdMultiValueColumn<'a> {
fn get_val(&self, pos: u64) -> u64 {
// use the offsets index to find the doc_id which will contain the position.
// the offsets are strictly increasing so we can do a binary search on it.
let new_doc_id: DocId = self.offsets.partition_point(|&offset| offset <= pos) as DocId - 1; // Offsets start at 0, so -1 is safe
// the offsets are strictly increasing so we can do a simple search on it.
let new_doc_id: DocId = self
.offsets
.iter()
.position(|&offset| offset > pos)
.expect("pos is out of bounds") as DocId
- 1u32;
// now we need to find the position of `pos` in the multivalued bucket
let num_pos_covered_until_now = self.offsets[new_doc_id as usize];

View File

@@ -31,7 +31,7 @@ pub use self::term_info::TermInfo;
pub(crate) type UnorderedTermId = u64;
#[allow(clippy::enum_variant_names)]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::enum_variant_names))]
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
pub(crate) enum FreqReadingOption {
NoFreq,

View File

@@ -50,7 +50,7 @@ impl<'a> Iterator for VInt32Reader<'a> {
/// Recorder is in charge of recording relevant information about
/// the presence of a term in a document.
///
/// Depending on the `TextIndexingOptions` associated with the
/// Depending on the `TextIndexingOptions` associated to the
/// field, the recorder may records
/// * the document frequency
/// * the document id

View File

@@ -7,7 +7,7 @@ use crate::postings::compression::COMPRESSION_BLOCK_SIZE;
use crate::postings::{branchless_binary_search, BlockSegmentPostings, Postings};
use crate::{DocId, TERMINATED};
/// `SegmentPostings` represents the inverted list or postings associated with
/// `SegmentPostings` represents the inverted list or postings associated to
/// a term in a `Segment`.
///
/// As we iterate through the `SegmentPostings`, the frequencies are optionally decoded.
@@ -216,7 +216,7 @@ impl HasLen for SegmentPostings {
}
impl Postings for SegmentPostings {
/// Returns the frequency associated with the current document.
/// Returns the frequency associated to the current document.
/// If the schema is set up so that no frequency have been encoded,
/// this method should always return 1.
///

View File

@@ -4,7 +4,7 @@ use std::ops::Range;
use common::{BinarySerializable, FixedSize};
/// `TermInfo` wraps the metadata associated with a Term.
/// `TermInfo` wraps the metadata associated to a Term.
/// It is segment-local.
#[derive(Debug, Default, Eq, PartialEq, Clone)]
pub struct TermInfo {

View File

@@ -17,7 +17,7 @@ impl Query for AllQuery {
}
}
/// Weight associated with the `AllQuery` query.
/// Weight associated to the `AllQuery` query.
pub struct AllWeight;
impl Weight for AllWeight {
@@ -37,7 +37,7 @@ impl Weight for AllWeight {
}
}
/// Scorer associated with the `AllQuery` query.
/// Scorer associated to the `AllQuery` query.
pub struct AllScorer {
doc: DocId,
max_doc: DocId,

View File

@@ -14,7 +14,7 @@ use crate::DocId;
/// when the bitset is sparse
pub struct BitSetDocSet {
docs: BitSet,
cursor_bucket: u32, //< index associated with the current tiny bitset
cursor_bucket: u32, //< index associated to the current tiny bitset
cursor_tinybitset: TinySet,
doc: u32,
}

View File

@@ -39,7 +39,7 @@ impl Explanation {
}
}
/// Returns the value associated with the current node.
/// Returns the value associated to the current node.
pub fn value(&self) -> Score {
self.value
}

View File

@@ -5,7 +5,7 @@ use crate::{DocId, Score};
/// Returns the intersection scorer.
///
/// The score associated with the documents is the sum of the
/// The score associated to the documents is the sum of the
/// score of the `Scorer`s given in argument.
///
/// For better performance, the function uses a

View File

@@ -119,7 +119,7 @@ impl PhraseQuery {
}
impl Query for PhraseQuery {
/// Create the weight associated with a query.
/// Create the weight associated to a query.
///
/// See [`Weight`].
fn weight(&self, searcher: &Searcher, scoring_enabled: bool) -> crate::Result<Box<dyn Weight>> {

View File

@@ -42,7 +42,7 @@ use crate::{DocAddress, Term};
/// [`Scorer`]: crate::query::Scorer
/// [`SegmentReader`]: crate::SegmentReader
pub trait Query: QueryClone + Send + Sync + downcast_rs::Downcast + fmt::Debug {
/// Create the weight associated with a query.
/// Create the weight associated to a query.
///
/// If scoring is not required, setting `scoring_enabled` to `false`
/// can increase performances.
@@ -67,7 +67,7 @@ pub trait Query: QueryClone + Send + Sync + downcast_rs::Downcast + fmt::Debug {
Ok(result)
}
/// Extract all of the terms associated with the query and pass them to the
/// Extract all of the terms associated to the query and pass them to the
/// given closure.
///
/// Each term is associated with a boolean indicating whether

View File

@@ -610,7 +610,7 @@ impl QueryParser {
if let Some((field, path)) = self.split_full_path(full_path) {
return Ok(vec![(field, path, literal.phrase.as_str())]);
}
// We need to add terms associated with json default fields.
// We need to add terms associated to json default fields.
let triplets: Vec<(Field, &str, &str)> = self
.default_indexed_json_fields()
.map(|json_field| (json_field, full_path.as_str(), literal.phrase.as_str()))

View File

@@ -83,7 +83,7 @@ impl BytesOptions {
///
/// Fast fields are designed for random access.
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated with a fast field, only the last one is
/// If more than one value is associated to a fast field, only the last one is
/// kept.
#[must_use]
pub fn set_fast(mut self) -> BytesOptions {

View File

@@ -104,7 +104,7 @@ impl DateOptions {
///
/// Fast fields are designed for random access.
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated with a fast field, only the last one is
/// If more than one value is associated to a fast field, only the last one is
/// kept.
#[must_use]
pub fn set_fast(mut self, cardinality: Cardinality) -> DateOptions {

View File

@@ -35,7 +35,7 @@ pub enum FacetParseError {
/// For instance, an e-commerce website could
/// have a `Facet` for `/electronics/tv_and_video/led_tv`.
///
/// A document can be associated with any number of facets.
/// A document can be associated to any number of facets.
/// The hierarchy implicitly imply that a document
/// belonging to a facet also belongs to the ancestor of
/// its facet. In the example above, `/electronics/tv_and_video/`

View File

@@ -1,109 +0,0 @@
use std::ops::BitOr;
use serde::{Deserialize, Serialize};
use super::flags::{FastFlag, IndexedFlag, SchemaFlagList, StoredFlag};
use super::Cardinality;
/// Define how an ip field should be handled by tantivy.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct IpOptions {
#[serde(skip_serializing_if = "Option::is_none")]
fast: Option<Cardinality>,
stored: bool,
}
impl IpOptions {
/// Returns true iff the value is a fast field.
pub fn is_fast(&self) -> bool {
self.fast.is_some()
}
/// Returns `true` if the json object should be stored.
pub fn is_stored(&self) -> bool {
self.stored
}
/// Returns the cardinality of the fastfield.
///
/// If the field has not been declared as a fastfield, then
/// the method returns None.
pub fn get_fastfield_cardinality(&self) -> Option<Cardinality> {
self.fast
}
/// Sets the field as stored
#[must_use]
pub fn set_stored(mut self) -> Self {
self.stored = true;
self
}
/// Set the field as a fast field.
///
/// Fast fields are designed for random access.
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated with a fast field, only the last one is
/// kept.
#[must_use]
pub fn set_fast(mut self, cardinality: Cardinality) -> Self {
self.fast = Some(cardinality);
self
}
}
impl From<()> for IpOptions {
fn from(_: ()) -> IpOptions {
IpOptions::default()
}
}
impl From<FastFlag> for IpOptions {
fn from(_: FastFlag) -> Self {
IpOptions {
stored: false,
fast: Some(Cardinality::SingleValue),
}
}
}
impl From<StoredFlag> for IpOptions {
fn from(_: StoredFlag) -> Self {
IpOptions {
stored: true,
fast: None,
}
}
}
impl From<IndexedFlag> for IpOptions {
fn from(_: IndexedFlag) -> Self {
IpOptions {
stored: false,
fast: None,
}
}
}
impl<T: Into<IpOptions>> BitOr<T> for IpOptions {
type Output = IpOptions;
fn bitor(self, other: T) -> IpOptions {
let other = other.into();
IpOptions {
stored: self.stored | other.stored,
fast: self.fast.or(other.fast),
}
}
}
impl<Head, Tail> From<SchemaFlagList<Head, Tail>> for IpOptions
where
Head: Clone,
Tail: Clone,
Self: BitOr<Output = Self> + From<Head> + From<Tail>,
{
fn from(head_tail: SchemaFlagList<Head, Tail>) -> Self {
Self::from(head_tail.head) | Self::from(head_tail.tail)
}
}

View File

@@ -120,7 +120,6 @@ mod date_time_options;
mod field;
mod flags;
mod index_record_option;
mod ip_options;
mod json_object_options;
mod named_field_document;
mod numeric_options;
@@ -139,7 +138,6 @@ pub use self::field_type::{FieldType, Type};
pub use self::field_value::FieldValue;
pub use self::flags::{FAST, INDEXED, STORED};
pub use self::index_record_option::IndexRecordOption;
pub use self::ip_options::IpOptions;
pub use self::json_object_options::JsonObjectOptions;
pub use self::named_field_document::NamedFieldDocument;
pub use self::numeric_options::NumericOptions;

View File

@@ -7,10 +7,10 @@ use crate::schema::flags::{FastFlag, IndexedFlag, SchemaFlagList, StoredFlag};
/// Express whether a field is single-value or multi-valued.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum Cardinality {
/// The document must have exactly one value associated with the document.
/// The document must have exactly one value associated to the document.
#[serde(rename = "single")]
SingleValue,
/// The document can have any number of values associated with the document.
/// The document can have any number of values associated to the document.
/// This is more memory and CPU expensive than the `SingleValue` solution.
#[serde(rename = "multi")]
MultiValues,
@@ -124,7 +124,7 @@ impl NumericOptions {
///
/// Fast fields are designed for random access.
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated with a fast field, only the last one is
/// If more than one value is associated to a fast field, only the last one is
/// kept.
#[must_use]
pub fn set_fast(mut self, cardinality: Cardinality) -> NumericOptions {

View File

@@ -258,7 +258,7 @@ impl Eq for InnerSchema {}
pub struct Schema(Arc<InnerSchema>);
impl Schema {
/// Return the `FieldEntry` associated with a `Field`.
/// Return the `FieldEntry` associated to a `Field`.
pub fn get_field_entry(&self, field: Field) -> &FieldEntry {
&self.0.fields[field.field_id() as usize]
}
@@ -422,8 +422,12 @@ pub enum DocParsingError {
impl DocParsingError {
/// Builds a NotJson DocParsingError
fn invalid_json(invalid_json: &str) -> Self {
let sample = invalid_json.chars().take(20).collect();
DocParsingError::InvalidJson(sample)
let sample_json: String = if invalid_json.len() < 20 {
invalid_json.to_string()
} else {
format!("{:?}...", &invalid_json[0..20])
};
DocParsingError::InvalidJson(sample_json)
}
}
@@ -789,11 +793,6 @@ mod tests {
))
);
}
{
// Short JSON, under the 20 char take.
let json_err = schema.parse_document(r#"{"count": 50,}"#);
assert_matches!(json_err, Err(InvalidJson(_)));
}
{
let json_err = schema.parse_document(
r#"{

View File

@@ -161,7 +161,7 @@ impl TextFieldIndexing {
self
}
/// Returns the indexing options associated with this field.
/// Returns the indexing options associated to this field.
///
/// See [`IndexRecordOption`] for more detail.
pub fn index_option(&self) -> IndexRecordOption {

View File

@@ -342,7 +342,7 @@ impl SnippetGenerator {
/// Generates a snippet for the given `Document`.
///
/// This method extract the text associated with the `SnippetGenerator`'s field
/// This method extract the text associated to the `SnippetGenerator`'s field
/// and computes a snippet.
pub fn snippet_from_doc(&self, doc: &Document) -> Snippet {
let text: String = doc

View File

@@ -136,7 +136,7 @@ where A: Automaton
}
/// Return the next `(key, value)` pair.
#[allow(clippy::should_implement_trait)]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::should_implement_trait))]
pub fn next(&mut self) -> Option<(&[u8], &TermInfo)> {
if self.advance() {
Some((self.key(), self.value()))

View File

@@ -138,12 +138,12 @@ impl TermDictionary {
self.term_info_store.num_terms()
}
/// Returns the ordinal associated with a given term.
/// Returns the ordinal associated to a given term.
pub fn term_ord<K: AsRef<[u8]>>(&self, key: K) -> io::Result<Option<TermOrdinal>> {
Ok(self.fst_index.get(key))
}
/// Stores the term associated with a given term ordinal in
/// Stores the term associated to a given term ordinal in
/// a `bytes` buffer.
///
/// Term ordinals are defined as the position of the term in

View File

@@ -179,7 +179,7 @@ where
}
/// Return the next `(key, value)` pair.
#[allow(clippy::should_implement_trait)]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::should_implement_trait))]
pub fn next(&mut self) -> Option<(&[u8], &TermInfo)> {
if self.advance() {
Some((self.key(), self.value()))

View File

@@ -52,7 +52,7 @@ impl<W: io::Write> TermDictionaryBuilder<W> {
/// to insert_key and insert_value.
///
/// Prefer using `.insert(key, value)`
#[allow(clippy::unnecessary_wraps)]
#[allow(clippy::clippy::clippy::unnecessary_wraps)]
pub(crate) fn insert_key(&mut self, key: &[u8]) -> io::Result<()> {
self.sstable_writer.write_key(key);
Ok(())
@@ -153,7 +153,7 @@ impl TermDictionary {
self.num_terms as usize
}
/// Returns the ordinal associated with a given term.
/// Returns the ordinal associated to a given term.
pub fn term_ord<K: AsRef<[u8]>>(&self, key: K) -> io::Result<Option<TermOrdinal>> {
let mut term_ord = 0u64;
let key_bytes = key.as_ref();
@@ -167,7 +167,7 @@ impl TermDictionary {
Ok(None)
}
/// Returns the term associated with a given term ordinal.
/// Returns the term associated to a given term ordinal.
///
/// Term ordinals are defined as the position of the term in
/// the sorted list of terms.