summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2019-08-01 17:26:21 +0900
committerGitHub <noreply@github.com>2019-08-01 17:26:21 +0900
commit280ea1209cab3c112578970dc8b9fd0fdefc63a9 (patch)
treed162067b4a9241f771ce1a3b0faad8e7645df4f0
parent0154dbe47778965af3772e08c046683456fe39a0 (diff)
Changes required for python binding (#610)
-rw-r--r--src/collector/top_score_collector.rs7
-rwxr-xr-xsrc/lib.rs7
-rw-r--r--src/query/query_parser/query_parser.rs18
-rw-r--r--src/reader/mod.rs3
-rw-r--r--src/reader/pool.rs4
-rw-r--r--src/schema/schema.rs5
6 files changed, 37 insertions, 7 deletions
diff --git a/src/collector/top_score_collector.rs b/src/collector/top_score_collector.rs
index 4ec09ce..21a88be 100644
--- a/src/collector/top_score_collector.rs
+++ b/src/collector/top_score_collector.rs
@@ -13,6 +13,7 @@ use crate::Result;
use crate::Score;
use crate::SegmentLocalId;
use crate::SegmentReader;
+use std::fmt;
/// The Top Score Collector keeps track of the K documents
/// sorted by their score.
@@ -68,6 +69,12 @@ use crate::SegmentReader;
/// ```
pub struct TopDocs(TopCollector<Score>);
+impl fmt::Debug for TopDocs {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "TopDocs({})", self.0.limit())
+ }
+}
+
impl TopDocs {
/// Creates a top score collector, with a number of documents equal to "limit".
///
diff --git a/src/lib.rs b/src/lib.rs
index b423f43..9947a2c 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -171,16 +171,16 @@ pub use self::snippet::{Snippet, SnippetGenerator};
mod docset;
pub use self::docset::{DocSet, SkipResult};
+pub use crate::common::{f64_to_u64, i64_to_u64, u64_to_f64, u64_to_i64};
pub use crate::core::SegmentComponent;
pub use crate::core::{Index, IndexMeta, Searcher, Segment, SegmentId, SegmentMeta};
pub use crate::core::{InvertedIndexReader, SegmentReader};
pub use crate::directory::Directory;
pub use crate::indexer::IndexWriter;
pub use crate::postings::Postings;
+pub use crate::reader::LeasedItem;
pub use crate::schema::{Document, Term};
-pub use crate::common::{i64_to_u64, u64_to_i64, f64_to_u64, u64_to_f64};
-
/// Expose the current version of tantivy, as well
/// whether it was compiled with the simd compression.
pub fn version() -> &'static str {
@@ -849,7 +849,8 @@ mod tests {
let index = Index::create_in_ram(schema);
let mut index_writer = index.writer_with_num_threads(1, 50_000_000).unwrap();
{
- let document = doc!(fast_field_unsigned => 4u64, fast_field_signed=>4i64, fast_field_float=>4f64);
+ let document =
+ doc!(fast_field_unsigned => 4u64, fast_field_signed=>4i64, fast_field_float=>4f64);
index_writer.add_document(document);
index_writer.commit().unwrap();
}
diff --git a/src/query/query_parser/query_parser.rs b/src/query/query_parser/query_parser.rs
index ffa7b20..715040f 100644
--- a/src/query/query_parser/query_parser.rs
+++ b/src/query/query_parser/query_parser.rs
@@ -18,42 +18,56 @@ use crate::schema::{FieldType, Term};
use crate::tokenizer::TokenizerManager;
use combine::Parser;
use std::borrow::Cow;
-use std::num::{ParseIntError, ParseFloatError};
+use std::num::{ParseFloatError, ParseIntError};
use std::ops::Bound;
use std::str::FromStr;
/// Possible error that may happen when parsing a query.
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq, Fail)]
pub enum QueryParserError {
/// Error in the query syntax
+ #[fail(display = "Syntax Error")]
SyntaxError,
/// `FieldDoesNotExist(field_name: String)`
/// The query references a field that is not in the schema
+ #[fail(display = "File does not exists: '{:?}'", _0)]
FieldDoesNotExist(String),
/// The query contains a term for a `u64` or `i64`-field, but the value
/// is neither.
+ #[fail(display = "Expected a valid integer: '{:?}'", _0)]
ExpectedInt(ParseIntError),
/// The query contains a term for a `f64`-field, but the value
/// is not a f64.
+ #[fail(display = "Invalid query: Only excluding terms given")]
ExpectedFloat(ParseFloatError),
/// It is forbidden queries that are only "excluding". (e.g. -title:pop)
+ #[fail(display = "Invalid query: Only excluding terms given")]
AllButQueryForbidden,
/// If no default field is declared, running a query without any
/// field specified is forbbidden.
+ #[fail(display = "No default field declared and no field specified in query")]
NoDefaultFieldDeclared,
/// The field searched for is not declared
/// as indexed in the schema.
+ #[fail(display = "The field '{:?}' is not declared as indexed", _0)]
FieldNotIndexed(String),
/// A phrase query was requested for a field that does not
/// have any positions indexed.
+ #[fail(display = "The field '{:?}' does not have positions indexed", _0)]
FieldDoesNotHavePositionsIndexed(String),
/// The tokenizer for the given field is unknown
/// The two argument strings are the name of the field, the name of the tokenizer
+ #[fail(
+ display = "The tokenizer '{:?}' for the field '{:?}' is unknown",
+ _0, _1
+ )]
UnknownTokenizer(String, String),
/// The query contains a range query with a phrase as one of the bounds.
/// Only terms can be used as bounds.
+ #[fail(display = "A range query cannot have a phrase as one of the bounds")]
RangeMustNotHavePhrase,
/// The format for the date field is not RFC 3339 compliant.
+ #[fail(display = "The date field has an invalid format")]
DateFormatError(chrono::ParseError),
}
diff --git a/src/reader/mod.rs b/src/reader/mod.rs
index ffd3305..f10aa98 100644
--- a/src/reader/mod.rs
+++ b/src/reader/mod.rs
@@ -1,6 +1,7 @@
mod pool;
-use self::pool::{LeasedItem, Pool};
+pub use self::pool::LeasedItem;
+use self::pool::Pool;
use crate::core::Segment;
use crate::directory::Directory;
use crate::directory::WatchHandle;
diff --git a/src/reader/pool.rs b/src/reader/pool.rs
index b24d0b3..0512e28 100644
--- a/src/reader/pool.rs
+++ b/src/reader/pool.rs
@@ -123,6 +123,10 @@ impl<T> Pool<T> {
}
}
+/// A LeasedItem holds an object borrowed from a Pool.
+///
+/// Upon drop, the object is automatically returned
+/// into the pool.
pub struct LeasedItem<T> {
gen_item: Option<GenerationItem<T>>,
recycle_queue: Arc<Queue<GenerationItem<T>>>,
diff --git a/src/schema/schema.rs b/src/schema/schema.rs
index 6094d4b..328b4d3 100644
--- a/src/schema/schema.rs
+++ b/src/schema/schema.rs
@@ -360,13 +360,16 @@ impl<'de> Deserialize<'de> for Schema {
/// Error that may happen when deserializing
/// a document from JSON.
-#[derive(Debug)]
+#[derive(Debug, Fail)]
pub enum DocParsingError {
/// The payload given is not valid JSON.
+ #[fail(display = "The provided string is not valid JSON")]
NotJSON(String),
/// One of the value node could not be parsed.
+ #[fail(display = "The field '{:?}' could not be parsed: {:?}", _0, _1)]
ValueError(String, ValueParsingError),
/// The json-document contains a field that is not declared in the schema.
+ #[fail(display = "The json-document contains an unknown field: {:?}", _0)]
NoSuchFieldInSchema(String),
}