-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored FTSClause and TSQuery structures to improve parsing logic …
…and support for complex queries.
- Loading branch information
1 parent
e87d1fb
commit 0e32379
Showing
10 changed files
with
312 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
mod clause; | ||
pub mod operator; | ||
pub mod query; | ||
mod language; | ||
mod ranking; | ||
pub mod term; | ||
pub mod types; | ||
pub mod clause; | ||
pub mod weight; | ||
|
||
pub use operator::QueryOperator; | ||
pub use query::{TSQuery, ParsedTSQuery}; | ||
pub use term::ParsedTerm; | ||
pub use types::{QueryType, Language, ParseError}; | ||
pub use clause::FTSClause; | ||
pub use query::{TSQuery, QueryType}; | ||
pub use language::Language; | ||
pub use ranking::TSRanking; | ||
pub use weight::TextWeight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum QueryOperator { | ||
And, | ||
Or, | ||
Not, | ||
} | ||
|
||
impl QueryOperator { | ||
pub fn from_str(s: &str) -> Option<Self> { | ||
match s.to_uppercase().as_str() { | ||
"AND" => Some(QueryOperator::And), | ||
"OR" => Some(QueryOperator::Or), | ||
"NOT" => Some(QueryOperator::Not), | ||
_ => None, | ||
} | ||
} | ||
|
||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
QueryOperator::And => "AND", | ||
QueryOperator::Or => "OR", | ||
QueryOperator::Not => "NOT", | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_operator_from_str() { | ||
assert_eq!(QueryOperator::from_str("AND"), Some(QueryOperator::And)); | ||
assert_eq!(QueryOperator::from_str("OR"), Some(QueryOperator::Or)); | ||
assert_eq!(QueryOperator::from_str("NOT"), Some(QueryOperator::Not)); | ||
assert_eq!(QueryOperator::from_str("INVALID"), None); | ||
} | ||
|
||
#[test] | ||
fn test_operator_as_str() { | ||
assert_eq!(QueryOperator::And.as_str(), "AND"); | ||
assert_eq!(QueryOperator::Or.as_str(), "OR"); | ||
assert_eq!(QueryOperator::Not.as_str(), "NOT"); | ||
} | ||
} |
Oops, something went wrong.