summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2019-09-05 09:37:28 +0900
committerGitHub <noreply@github.com>2019-09-05 09:37:28 +0900
commit4b9c1dce69413c989a8dad26c8e171ee22e58b17 (patch)
tree4e1811edcae8de8e0cf7b71863cbca3feff3427c
parentd74f71bbef10bb5c98c65350277fcc3058d122e4 (diff)
Moving queyr grammar to a different crate. (#645)
-rw-r--r--Cargo.toml5
-rw-r--r--Makefile3
-rw-r--r--ci/script.sh5
-rw-r--r--examples/multiple_producer.rs10
-rw-r--r--query-grammar/Cargo.toml16
-rw-r--r--query-grammar/src/lib.rs17
-rw-r--r--query-grammar/src/occur.rs (renamed from src/query/occur.rs)32
-rw-r--r--query-grammar/src/query_grammar.rs (renamed from src/query/query_parser/query_grammar.rs)3
-rw-r--r--query-grammar/src/user_input_ast.rs (renamed from src/query/query_parser/user_input_ast.rs)2
-rwxr-xr-xsrc/lib.rs1
-rw-r--r--src/query/mod.rs3
-rw-r--r--src/query/query_parser/mod.rs2
-rw-r--r--src/query/query_parser/query_parser.rs15
13 files changed, 71 insertions, 43 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3644832..e05fafa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,7 +24,6 @@ snap = {version="0.2"}
atomicwrites = {version="0.2.2", optional=true}
tempfile = "3.0"
log = "0.4"
-combine = ">=3.6.0,<4.0.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
@@ -42,6 +41,7 @@ owning_ref = "0.4"
stable_deref_trait = "1.0.0"
rust-stemmers = "1.1"
downcast-rs = { version="1.0" }
+tantivy-query-grammar = { path="./query-grammar" }
bitpacking = {version="0.8", default-features = false, features=["bitpacker4x"]}
census = "0.2"
fnv = "1.0.6"
@@ -80,6 +80,9 @@ failpoints = ["fail/failpoints"]
unstable = [] # useful for benches.
wasm-bindgen = ["uuid/wasm-bindgen"]
+[workspace]
+members = ["query-grammar"]
+
[badges]
travis-ci = { repository = "tantivy-search/tantivy" }
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..05f0f44
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,3 @@
+test:
+ echo "Run test only... No examples."
+ cargo test --tests --lib
diff --git a/ci/script.sh b/ci/script.sh
index 9f3cf88..87f8902 100644
--- a/ci/script.sh
+++ b/ci/script.sh
@@ -7,7 +7,7 @@ set -ex
main() {
if [ ! -z $CODECOV ]; then
echo "Codecov"
- cargo build --verbose && cargo coverage --verbose && bash <(curl -s https://codecov.io/bash) -s target/kcov
+ cargo build --verbose && cargo coverage --verbose --all && bash <(curl -s https://codecov.io/bash) -s target/kcov
else
echo "Build"
cross build --target $TARGET
@@ -15,7 +15,8 @@ main() {
return
fi
echo "Test"
- cross test --target $TARGET --no-default-features --features mmap -- --test-threads 1
+ cross test --target $TARGET --no-default-features --features mmap
+ cross test --target $TARGET --no-default-features --features mmap query-grammar
fi
for example in $(ls examples/*.rs)
do
diff --git a/examples/multiple_producer.rs b/examples/multiple_producer.rs
index 6841cf8..8c2ab56 100644
--- a/examples/multiple_producer.rs
+++ b/examples/multiple_producer.rs
@@ -46,10 +46,9 @@ fn main() -> tantivy::Result<()> {
thread::spawn(move || {
// we index 100 times the document... for the sake of the example.
for i in 0..100 {
- let opstamp = {
- // A read lock is sufficient here.
- let index_writer_rlock = index_writer_clone_1.read().unwrap();
- index_writer_rlock.add_document(
+ let opstamp = index_writer_clone_1
+ .read().unwrap() //< A read lock is sufficient here.
+ .add_document(
doc!(
title => "Of Mice and Men",
body => "A few miles south of Soledad, the Salinas River drops in close to the hillside \
@@ -60,8 +59,7 @@ fn main() -> tantivy::Result<()> {
fresh and green with every spring, carrying in their lower leaf junctures the \
debris of the winter’s flooding; and sycamores with mottled, white, recumbent \
limbs and branches that arch over the pool"
- ))
- };
+ ));
println!("add doc {} from thread 1 - opstamp {}", i, opstamp);
thread::sleep(Duration::from_millis(20));
}
diff --git a/query-grammar/Cargo.toml b/query-grammar/Cargo.toml
new file mode 100644
index 0000000..e6b2e0b
--- /dev/null
+++ b/query-grammar/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "tantivy-query-grammar"
+version = "0.11.0"
+authors = ["Paul Masurel <paul.masurel@gmail.com>"]
+license = "MIT"
+categories = ["database-implementations", "data-structures"]
+description = """Search engine library"""
+documentation = "https://tantivy-search.github.io/tantivy/tantivy/index.html"
+homepage = "https://github.com/tantivy-search/tantivy"
+repository = "https://github.com/tantivy-search/tantivy"
+readme = "README.md"
+keywords = ["search", "information", "retrieval"]
+edition = "2018"
+
+[dependencies]
+combine = ">=3.6.0,<4.0.0"
diff --git a/query-grammar/src/lib.rs b/query-grammar/src/lib.rs
new file mode 100644
index 0000000..e6f8090
--- /dev/null
+++ b/query-grammar/src/lib.rs
@@ -0,0 +1,17 @@
+#![recursion_limit = "100"]
+
+mod occur;
+mod query_grammar;
+mod user_input_ast;
+use combine::parser::Parser;
+
+pub use crate::occur::Occur;
+use crate::query_grammar::parse_to_ast;
+pub use crate::user_input_ast::{UserInputAST, UserInputBound, UserInputLeaf, UserInputLiteral};
+
+pub struct Error;
+
+pub fn parse_query(query: &str) -> Result<UserInputAST, Error> {
+ let (user_input_ast, _remaining) = parse_to_ast().parse(query).map_err(|_| Error)?;
+ Ok(user_input_ast)
+}
diff --git a/src/query/occur.rs b/query-grammar/src/occur.rs
index 96ff901..62cfb6b 100644
--- a/src/query/occur.rs
+++ b/query-grammar/src/occur.rs
@@ -25,24 +25,24 @@ impl Occur {
Occur::MustNot => '-',
}
}
-}
-/// Compose two occur values.
-pub fn compose_occur(left: Occur, right: Occur) -> Occur {
- match left {
- Occur::Should => right,
- Occur::Must => {
- if right == Occur::MustNot {
- Occur::MustNot
- } else {
- Occur::Must
+ /// Compose two occur values.
+ pub fn compose(left: Occur, right: Occur) -> Occur {
+ match left {
+ Occur::Should => right,
+ Occur::Must => {
+ if right == Occur::MustNot {
+ Occur::MustNot
+ } else {
+ Occur::Must
+ }
}
- }
- Occur::MustNot => {
- if right == Occur::MustNot {
- Occur::Must
- } else {
- Occur::MustNot
+ Occur::MustNot => {
+ if right == Occur::MustNot {
+ Occur::Must
+ } else {
+ Occur::MustNot
+ }
}
}
}
diff --git a/src/query/query_parser/query_grammar.rs b/query-grammar/src/query_grammar.rs
index 004bd29..1e2c3d7 100644
--- a/src/query/query_parser/query_grammar.rs
+++ b/query-grammar/src/query_grammar.rs
@@ -1,6 +1,5 @@
use super::user_input_ast::*;
-use crate::query::occur::Occur;
-use crate::query::query_parser::user_input_ast::UserInputBound;
+use crate::Occur;
use combine::char::*;
use combine::error::StreamError;
use combine::stream::StreamErrorFor;
diff --git a/src/query/query_parser/user_input_ast.rs b/query-grammar/src/user_input_ast.rs
index 6965243..daf3c9a 100644
--- a/src/query/query_parser/user_input_ast.rs
+++ b/query-grammar/src/user_input_ast.rs
@@ -1,7 +1,7 @@
use std::fmt;
use std::fmt::{Debug, Formatter};
-use crate::query::Occur;
+use crate::Occur;
#[derive(PartialEq)]
pub enum UserInputLeaf {
diff --git a/src/lib.rs b/src/lib.rs
index bee8659..3bbfe16 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,4 @@
#![doc(html_logo_url = "http://fulmicoton.com/tantivy-logo/tantivy-logo.png")]
-#![recursion_limit = "100"]
#![cfg_attr(all(feature = "unstable", test), feature(test))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
diff --git a/src/query/mod.rs b/src/query/mod.rs
index c039121..82653cb 100644
--- a/src/query/mod.rs
+++ b/src/query/mod.rs
@@ -12,7 +12,6 @@ mod exclude;
mod explanation;
mod fuzzy_query;
mod intersection;
-mod occur;
mod phrase_query;
mod query;
mod query_parser;
@@ -43,7 +42,6 @@ pub use self::exclude::Exclude;
pub use self::explanation::Explanation;
pub use self::fuzzy_query::FuzzyTermQuery;
pub use self::intersection::intersect_scorers;
-pub use self::occur::Occur;
pub use self::phrase_query::PhraseQuery;
pub use self::query::Query;
pub use self::query_parser::QueryParser;
@@ -55,6 +53,7 @@ pub use self::scorer::ConstScorer;
pub use self::scorer::Scorer;
pub use self::term_query::TermQuery;
pub use self::weight::Weight;
+pub use tantivy_query_grammar::Occur;
#[cfg(test)]
mod tests {
diff --git a/src/query/query_parser/mod.rs b/src/query/query_parser/mod.rs
index 2fd5815..ee7a5b4 100644
--- a/src/query/query_parser/mod.rs
+++ b/src/query/query_parser/mod.rs
@@ -1,6 +1,4 @@
-mod query_grammar;
mod query_parser;
-mod user_input_ast;
pub mod logical_ast;
pub use self::query_parser::QueryParser;
diff --git a/src/query/query_parser/query_parser.rs b/src/query/query_parser/query_parser.rs
index 9356b8a..7648cdc 100644
--- a/src/query/query_parser/query_parser.rs
+++ b/src/query/query_parser/query_parser.rs
@@ -1,9 +1,5 @@
use super::logical_ast::*;
-use super::query_grammar::parse_to_ast;
-use super::user_input_ast::*;
use crate::core::Index;
-use crate::query::occur::compose_occur;
-use crate::query::query_parser::logical_ast::LogicalAST;
use crate::query::AllQuery;
use crate::query::BooleanQuery;
use crate::query::EmptyQuery;
@@ -16,11 +12,11 @@ use crate::schema::IndexRecordOption;
use crate::schema::{Field, Schema};
use crate::schema::{FieldType, Term};
use crate::tokenizer::TokenizerManager;
-use combine::Parser;
use std::borrow::Cow;
use std::num::{ParseFloatError, ParseIntError};
use std::ops::Bound;
use std::str::FromStr;
+use tantivy_query_grammar::{UserInputAST, UserInputBound, UserInputLeaf};
/// Possible error that may happen when parsing a query.
#[derive(Debug, PartialEq, Eq, Fail)]
@@ -222,9 +218,8 @@ impl QueryParser {
/// Parse the user query into an AST.
fn parse_query_to_logical_ast(&self, query: &str) -> Result<LogicalAST, QueryParserError> {
- let (user_input_ast, _remaining) = parse_to_ast()
- .parse(query)
- .map_err(|_| QueryParserError::SyntaxError)?;
+ let user_input_ast =
+ tantivy_query_grammar::parse_query(query).map_err(|_| QueryParserError::SyntaxError)?;
self.compute_logical_ast(user_input_ast)
}
@@ -399,7 +394,7 @@ impl QueryParser {
let mut logical_sub_queries: Vec<(Occur, LogicalAST)> = Vec::new();
for sub_query in sub_queries {
let (occur, sub_ast) = self.compute_logical_ast_with_occur(sub_query)?;
- let new_occur = compose_occur(default_occur, occur);
+ let new_occur = Occur::compose(default_occur, occur);
logical_sub_queries.push((new_occur, sub_ast));
}
Ok((Occur::Should, LogicalAST::Clause(logical_sub_queries)))
@@ -407,7 +402,7 @@ impl QueryParser {
UserInputAST::Unary(left_occur, subquery) => {
let (right_occur, logical_sub_queries) =
self.compute_logical_ast_with_occur(*subquery)?;
- Ok((compose_occur(left_occur, right_occur), logical_sub_queries))
+ Ok((Occur::compose(left_occur, right_occur), logical_sub_queries))
}
UserInputAST::Leaf(leaf) => {
let result_ast = self.compute_logical_ast_from_leaf(*leaf)?;