finalize ip addr rename

This commit is contained in:
Pascal Seitz
2022-10-06 11:22:38 +08:00
parent cdc8e3a8be
commit 4d29ff4d01
8 changed files with 36 additions and 36 deletions

View File

@@ -283,7 +283,7 @@ impl FastFieldsWriter {
/// The fast field writer just keeps the values in memory.
///
/// Only when the segment writer can be closed and
/// persisted on disc, the fast field writer is
/// persisted on disk, the fast field writer is
/// sent to a `FastFieldSerializer` via the `.serialize(...)`
/// method.
///
@@ -371,7 +371,7 @@ impl U128FastFieldWriter {
/// The fast field writer just keeps the values in memory.
///
/// Only when the segment writer can be closed and
/// persisted on disc, the fast field writer is
/// persisted on disk, the fast field writer is
/// sent to a `FastFieldSerializer` via the `.serialize(...)`
/// method.
///

View File

@@ -817,7 +817,7 @@ mod tests {
use crate::indexer::NoMergePolicy;
use crate::query::{BooleanQuery, Occur, Query, QueryParser, TermQuery};
use crate::schema::{
self, Cardinality, Facet, FacetOptions, IndexRecordOption, IpOptions, NumericOptions,
self, Cardinality, Facet, FacetOptions, IndexRecordOption, IpAddrOptions, NumericOptions,
TextFieldIndexing, TextOptions, FAST, INDEXED, STORED, STRING, TEXT,
};
use crate::store::DOCSTORE_CACHE_CAPACITY;
@@ -1595,10 +1595,10 @@ mod tests {
force_end_merge: bool,
) -> crate::Result<()> {
let mut schema_builder = schema::Schema::builder();
let ip_field = schema_builder.add_ip_field("ip", FAST | INDEXED | STORED);
let ips_field = schema_builder.add_ip_field(
let ip_field = schema_builder.add_ip_addr_field("ip", FAST | INDEXED | STORED);
let ips_field = schema_builder.add_ip_addr_field(
"ips",
IpOptions::default().set_fast(Cardinality::MultiValues),
IpAddrOptions::default().set_fast(Cardinality::MultiValues),
);
let id_field = schema_builder.add_u64_field("id", FAST | INDEXED | STORED);
let bytes_field = schema_builder.add_bytes_field("bytes", FAST | INDEXED | STORED);

View File

@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use super::ip_options::IpOptions;
use super::ip_options::IpAddrOptions;
use crate::schema::bytes_options::BytesOptions;
use crate::schema::{
is_valid_field_name, DateOptions, FacetOptions, FieldType, JsonObjectOptions, NumericOptions,
@@ -62,7 +62,7 @@ impl FieldEntry {
}
/// Creates a new ip field entry.
pub fn new_ip(field_name: String, ip_options: IpOptions) -> FieldEntry {
pub fn new_ip_addr(field_name: String, ip_options: IpAddrOptions) -> FieldEntry {
Self::new(field_name, FieldType::IpAddr(ip_options))
}

View File

@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use thiserror::Error;
use super::ip_options::IpOptions;
use super::ip_options::IpAddrOptions;
use super::Cardinality;
use crate::schema::bytes_options::BytesOptions;
use crate::schema::facet_options::FacetOptions;
@@ -67,7 +67,7 @@ pub enum Type {
/// Leaf in a Json object.
Json = b'j',
/// IpAddr
Ip = b'p',
IpAddr = b'p',
/// IpAddr
U128 = b'1',
}
@@ -82,7 +82,7 @@ const ALL_TYPES: [Type; 11] = [
Type::Facet,
Type::Bytes,
Type::Json,
Type::Ip,
Type::IpAddr,
Type::U128,
];
@@ -110,7 +110,7 @@ impl Type {
Type::Facet => "Facet",
Type::Bytes => "Bytes",
Type::Json => "Json",
Type::Ip => "Ip",
Type::IpAddr => "IpAddr",
Type::U128 => "U128",
}
}
@@ -128,7 +128,7 @@ impl Type {
b'h' => Some(Type::Facet),
b'b' => Some(Type::Bytes),
b'j' => Some(Type::Json),
b'p' => Some(Type::Ip),
b'p' => Some(Type::IpAddr),
b'1' => Some(Type::U128),
_ => None,
}
@@ -161,7 +161,7 @@ pub enum FieldType {
/// Json object
JsonObject(JsonObjectOptions),
/// IpAddr field
IpAddr(IpOptions),
IpAddr(IpAddrOptions),
}
impl FieldType {
@@ -177,7 +177,7 @@ impl FieldType {
FieldType::Facet(_) => Type::Facet,
FieldType::Bytes(_) => Type::Bytes,
FieldType::JsonObject(_) => Type::Json,
FieldType::IpAddr(_) => Type::Ip,
FieldType::IpAddr(_) => Type::IpAddr,
}
}

View File

@@ -7,13 +7,13 @@ use super::Cardinality;
/// Define how an ip field should be handled by tantivy.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct IpOptions {
pub struct IpAddrOptions {
#[serde(skip_serializing_if = "Option::is_none")]
fast: Option<Cardinality>,
stored: bool,
}
impl IpOptions {
impl IpAddrOptions {
/// Returns true iff the value is a fast field.
pub fn is_fast(&self) -> bool {
self.fast.is_some()
@@ -52,52 +52,52 @@ impl IpOptions {
}
}
impl From<()> for IpOptions {
fn from(_: ()) -> IpOptions {
IpOptions::default()
impl From<()> for IpAddrOptions {
fn from(_: ()) -> IpAddrOptions {
IpAddrOptions::default()
}
}
impl From<FastFlag> for IpOptions {
impl From<FastFlag> for IpAddrOptions {
fn from(_: FastFlag) -> Self {
IpOptions {
IpAddrOptions {
stored: false,
fast: Some(Cardinality::SingleValue),
}
}
}
impl From<StoredFlag> for IpOptions {
impl From<StoredFlag> for IpAddrOptions {
fn from(_: StoredFlag) -> Self {
IpOptions {
IpAddrOptions {
stored: true,
fast: None,
}
}
}
impl From<IndexedFlag> for IpOptions {
impl From<IndexedFlag> for IpAddrOptions {
fn from(_: IndexedFlag) -> Self {
IpOptions {
IpAddrOptions {
stored: false,
fast: None,
}
}
}
impl<T: Into<IpOptions>> BitOr<T> for IpOptions {
type Output = IpOptions;
impl<T: Into<IpAddrOptions>> BitOr<T> for IpAddrOptions {
type Output = IpAddrOptions;
fn bitor(self, other: T) -> IpOptions {
fn bitor(self, other: T) -> IpAddrOptions {
let other = other.into();
IpOptions {
IpAddrOptions {
stored: self.stored | other.stored,
fast: self.fast.or(other.fast),
}
}
}
impl<Head, Tail> From<SchemaFlagList<Head, Tail>> for IpOptions
impl<Head, Tail> From<SchemaFlagList<Head, Tail>> for IpAddrOptions
where
Head: Clone,
Tail: Clone,

View File

@@ -138,7 +138,7 @@ 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::ip_options::IpAddrOptions;
pub use self::json_object_options::JsonObjectOptions;
pub use self::named_field_document::NamedFieldDocument;
pub use self::numeric_options::NumericOptions;

View File

@@ -7,7 +7,7 @@ use serde::ser::SerializeSeq;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{self, Value as JsonValue};
use super::ip_options::IpOptions;
use super::ip_options::IpAddrOptions;
use super::*;
use crate::schema::bytes_options::BytesOptions;
use crate::schema::field_type::ValueParsingError;
@@ -157,13 +157,13 @@ impl SchemaBuilder {
/// by the second one.
/// The first field will get a field id
/// but only the second one will be indexed
pub fn add_ip_field<T: Into<IpOptions>>(
pub fn add_ip_addr_field<T: Into<IpAddrOptions>>(
&mut self,
field_name_str: &str,
field_options: T,
) -> Field {
let field_name = String::from(field_name_str);
let field_entry = FieldEntry::new_ip(field_name, field_options.into());
let field_entry = FieldEntry::new_ip_addr(field_name, field_options.into());
self.add_field(field_entry)
}

View File

@@ -415,7 +415,7 @@ fn debug_value_bytes(typ: Type, bytes: &[u8], f: &mut fmt::Formatter) -> fmt::Re
debug_value_bytes(typ, bytes, f)?;
}
}
Type::Ip => {
Type::IpAddr => {
let s = as_str(bytes); // TODO: change when serialization changes
write_opt(f, s)?;
}