mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
apply code suggestion
Co-authored-by: Kerollmops <kero@meilisearch.com>
This commit is contained in:
parent
3cb1f6d0a1
commit
c55368ddd4
@ -97,6 +97,12 @@ impl From<fst::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<GeoError> for Error {
|
||||||
|
fn from(error: GeoError) -> Error {
|
||||||
|
Error::UserError(UserError::InvalidGeoField(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E> From<grenad::Error<E>> for Error
|
impl<E> From<grenad::Error<E>> for Error
|
||||||
where
|
where
|
||||||
Error: From<E>,
|
Error: From<E>,
|
||||||
|
@ -7,7 +7,7 @@ use serde_json::Value;
|
|||||||
|
|
||||||
use super::helpers::{create_writer, writer_into_reader, GrenadParameters};
|
use super::helpers::{create_writer, writer_into_reader, GrenadParameters};
|
||||||
use crate::error::GeoError;
|
use crate::error::GeoError;
|
||||||
use crate::{FieldId, InternalError, Result, UserError};
|
use crate::{FieldId, InternalError, Result};
|
||||||
|
|
||||||
/// Extracts the geographical coordinates contained in each document under the `_geo` field.
|
/// Extracts the geographical coordinates contained in each document under the `_geo` field.
|
||||||
///
|
///
|
||||||
@ -35,23 +35,23 @@ pub fn extract_geo_points<R: io::Read + io::Seek>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// first we get the two fields
|
// first we get the two fields
|
||||||
let lat = obkv.get(lat_fid).ok_or_else(|| -> UserError {
|
let lat = obkv
|
||||||
GeoError::MissingLatitude { document_id: primary_key() }.into()
|
.get(lat_fid)
|
||||||
})?;
|
.ok_or_else(|| GeoError::MissingLatitude { document_id: primary_key() })?;
|
||||||
let lng = obkv.get(lng_fid).ok_or_else(|| -> UserError {
|
let lng = obkv
|
||||||
GeoError::MissingLongitude { document_id: primary_key() }.into()
|
.get(lng_fid)
|
||||||
})?;
|
.ok_or_else(|| GeoError::MissingLongitude { document_id: primary_key() })?;
|
||||||
|
|
||||||
// then we extract the values
|
// then we extract the values
|
||||||
let lat = extract_value(serde_json::from_slice(lat).map_err(InternalError::SerdeJson)?)
|
let lat = extract_float_from_value(
|
||||||
.map_err(|lat| -> UserError {
|
serde_json::from_slice(lat).map_err(InternalError::SerdeJson)?,
|
||||||
GeoError::BadLatitude { document_id: primary_key(), value: lat }.into()
|
)
|
||||||
})?;
|
.map_err(|lat| GeoError::BadLatitude { document_id: primary_key(), value: lat })?;
|
||||||
|
|
||||||
let lng = extract_value(serde_json::from_slice(lng).map_err(InternalError::SerdeJson)?)
|
let lng = extract_float_from_value(
|
||||||
.map_err(|lng| -> UserError {
|
serde_json::from_slice(lng).map_err(InternalError::SerdeJson)?,
|
||||||
GeoError::BadLongitude { document_id: primary_key(), value: lng }.into()
|
)
|
||||||
})?;
|
.map_err(|lng| GeoError::BadLongitude { document_id: primary_key(), value: lng })?;
|
||||||
|
|
||||||
let bytes: [u8; 16] = concat_arrays![lat.to_ne_bytes(), lng.to_ne_bytes()];
|
let bytes: [u8; 16] = concat_arrays![lat.to_ne_bytes(), lng.to_ne_bytes()];
|
||||||
writer.insert(docid_bytes, bytes)?;
|
writer.insert(docid_bytes, bytes)?;
|
||||||
@ -60,7 +60,7 @@ pub fn extract_geo_points<R: io::Read + io::Seek>(
|
|||||||
Ok(writer_into_reader(writer)?)
|
Ok(writer_into_reader(writer)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_value(value: Value) -> StdResult<f64, Value> {
|
fn extract_float_from_value(value: Value) -> StdResult<f64, Value> {
|
||||||
match value {
|
match value {
|
||||||
Value::Number(ref n) => n.as_f64().ok_or(value),
|
Value::Number(ref n) => n.as_f64().ok_or(value),
|
||||||
Value::String(ref s) => s.parse::<f64>().map_err(|_| value),
|
Value::String(ref s) => s.parse::<f64>().map_err(|_| value),
|
||||||
|
Loading…
Reference in New Issue
Block a user