mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-26 21:20:40 +00:00
No influence from starting and trailing spaces.
This commit is contained in:
@@ -21,7 +21,10 @@ impl PartialOrd for GlobalScoredDoc {
|
||||
impl Ord for GlobalScoredDoc {
|
||||
#[inline(always)]
|
||||
fn cmp(&self, other: &GlobalScoredDoc) -> Ordering {
|
||||
other.0.partial_cmp(&self.0).unwrap_or(Ordering::Equal)
|
||||
other.0.partial_cmp(&self.0)
|
||||
.unwrap_or(
|
||||
other.1.cmp(&self.1)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ pub type Score = f32;
|
||||
/// It only makes sense for a given searcher.
|
||||
pub type SegmentLocalId = u32;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct DocAddress(pub SegmentLocalId, pub DocId);
|
||||
|
||||
impl DocAddress {
|
||||
@@ -84,6 +84,7 @@ impl DocAddress {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ScoredDoc(Score, DocId);
|
||||
|
||||
|
||||
@@ -88,10 +88,9 @@ impl<TPostings: Postings> DocSet for UnionPostings<TPostings> {
|
||||
|
||||
fn next(&mut self,) -> bool {
|
||||
self.scorer.clear();
|
||||
let cur_doc: DocId;
|
||||
match self.queue.peek() {
|
||||
Some(&HeapItem(doc, ord)) => {
|
||||
cur_doc = doc;
|
||||
self.doc = doc;
|
||||
let ord: usize = ord as usize;
|
||||
let fieldnorm = self.get_field_norm(ord, doc);
|
||||
let tf = self.term_frequencies[ord];
|
||||
@@ -106,21 +105,20 @@ impl<TPostings: Postings> DocSet for UnionPostings<TPostings> {
|
||||
loop {
|
||||
match self.queue.peek() {
|
||||
Some(&HeapItem(peek_doc, peek_ord)) => {
|
||||
if peek_doc != cur_doc {
|
||||
if peek_doc != self.doc {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
let peek_ord: usize = peek_ord as usize;
|
||||
let peek_tf = self.term_frequencies[peek_ord];
|
||||
let fieldnorm = self.get_field_norm(peek_ord, peek_doc);
|
||||
self.scorer.update(peek_ord, peek_tf, fieldnorm);
|
||||
let peek_fieldnorm = self.get_field_norm(peek_ord, peek_doc);
|
||||
self.scorer.update(peek_ord, peek_tf, peek_fieldnorm);
|
||||
}
|
||||
}
|
||||
None => { break; }
|
||||
}
|
||||
self.advance_head();
|
||||
}
|
||||
self.doc = cur_doc;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ impl QueryParser {
|
||||
}
|
||||
|
||||
pub fn parse_query(&self, query: &str) -> Result<StandardQuery, ParsingError> {
|
||||
match parser(query_language).parse(query) {
|
||||
match parser(query_language).parse(query.trim()) {
|
||||
Ok(literals) => {
|
||||
let mut terms_result: Vec<Term> = Vec::new();
|
||||
for literal in literals.0.into_iter() {
|
||||
@@ -139,7 +139,7 @@ pub fn query_language(input: State<&str>) -> ParseResult<Vec<Literal>, &str>
|
||||
.or(term_default_field)
|
||||
};
|
||||
(sep_by(literal(), spaces()), eof())
|
||||
.map(|(first,_)| first)
|
||||
.map(|(first, _)| first)
|
||||
.parse_state(input)
|
||||
}
|
||||
|
||||
@@ -153,11 +153,13 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
pub fn test_query_grammar() {
|
||||
let mut query_parser = parser(query_language);
|
||||
assert_eq!(query_parser.parse("abc:toto").unwrap().0,
|
||||
vec!(Literal::WithField(String::from("abc"), String::from("toto"))));
|
||||
vec!(Literal::WithField(String::from("abc"), String::from("toto"))));
|
||||
assert_eq!(query_parser.parse("\"some phrase query\"").unwrap().0,
|
||||
vec!(Literal::DefaultField(String::from("some phrase query"))));
|
||||
assert_eq!(query_parser.parse("field:\"some phrase query\"").unwrap().0,
|
||||
@@ -176,9 +178,9 @@ mod tests {
|
||||
vec!(Literal::DefaultField(String::from("a9e3")),));
|
||||
assert_eq!(query_parser.parse("field:タンタイビーって早い").unwrap().0,
|
||||
vec!(Literal::WithField(String::from("field"), String::from("タンタイビーって早い")),));
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
pub fn test_invalid_queries() {
|
||||
let mut query_parser = parser(query_language);
|
||||
@@ -189,6 +191,7 @@ mod tests {
|
||||
assert!(query_parser.parse("field:").is_err());
|
||||
assert!(query_parser.parse(":field").is_err());
|
||||
assert!(query_parser.parse("f:@e!e").is_err());
|
||||
assert!(query_parser.parse("f:@e!e").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -218,6 +221,18 @@ mod tests {
|
||||
query
|
||||
);
|
||||
}
|
||||
{
|
||||
let terms = vec!(Term::from_field_text(title_field, "abctitle"));
|
||||
let query = StandardQuery::MultiTerm(MultiTermQuery::new(terms));
|
||||
assert_eq!(
|
||||
query_parser.parse_query("title:abctitle ").unwrap(),
|
||||
query
|
||||
);
|
||||
assert_eq!(
|
||||
query_parser.parse_query(" title:abctitle").unwrap(),
|
||||
query
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user