mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
Revert "feat: Allow Matches to be constructed"
This reverts commit d21406a939
.
This commit is contained in:
parent
f32a59720d
commit
a78b5d225f
@ -66,7 +66,10 @@ mod tests {
|
|||||||
word_area: WordArea::new_faillible(0, 6)
|
word_area: WordArea::new_faillible(0, 6)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Document::from_unsorted_matches(DocumentId(0), matches)
|
Document {
|
||||||
|
id: DocumentId(0),
|
||||||
|
matches: matches,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let doc1 = {
|
let doc1 = {
|
||||||
@ -86,7 +89,10 @@ mod tests {
|
|||||||
word_area: WordArea::new_faillible(0, 6)
|
word_area: WordArea::new_faillible(0, 6)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Document::from_unsorted_matches(DocumentId(1), matches)
|
Document {
|
||||||
|
id: DocumentId(1),
|
||||||
|
matches: matches,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lhs = sum_matches_typos(&doc0.matches);
|
let lhs = sum_matches_typos(&doc0.matches);
|
||||||
@ -117,7 +123,10 @@ mod tests {
|
|||||||
word_area: WordArea::new_faillible(0, 6)
|
word_area: WordArea::new_faillible(0, 6)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Document::from_unsorted_matches(DocumentId(0), matches)
|
Document {
|
||||||
|
id: DocumentId(0),
|
||||||
|
matches: matches,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let doc1 = {
|
let doc1 = {
|
||||||
@ -130,7 +139,10 @@ mod tests {
|
|||||||
word_area: WordArea::new_faillible(0, 6)
|
word_area: WordArea::new_faillible(0, 6)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Document::from_unsorted_matches(DocumentId(1), matches)
|
Document {
|
||||||
|
id: DocumentId(1),
|
||||||
|
matches: matches,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lhs = sum_matches_typos(&doc0.matches);
|
let lhs = sum_matches_typos(&doc0.matches);
|
||||||
@ -161,7 +173,10 @@ mod tests {
|
|||||||
word_area: WordArea::new_faillible(0, 6)
|
word_area: WordArea::new_faillible(0, 6)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Document::from_unsorted_matches(DocumentId(0), matches)
|
Document {
|
||||||
|
id: DocumentId(0),
|
||||||
|
matches: matches,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let doc1 = {
|
let doc1 = {
|
||||||
@ -174,7 +189,10 @@ mod tests {
|
|||||||
word_area: WordArea::new_faillible(0, 6)
|
word_area: WordArea::new_faillible(0, 6)
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
Document::from_unsorted_matches(DocumentId(1), matches)
|
Document {
|
||||||
|
id: DocumentId(1),
|
||||||
|
matches: matches,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lhs = sum_matches_typos(&doc0.matches);
|
let lhs = sum_matches_typos(&doc0.matches);
|
||||||
|
@ -90,8 +90,8 @@ mod tests {
|
|||||||
// soup -> of = 8
|
// soup -> of = 8
|
||||||
// + of -> the = 1
|
// + of -> the = 1
|
||||||
// + the -> day = 8 (not 1)
|
// + the -> day = 8 (not 1)
|
||||||
let matches = Matches::from_unsorted(matches.to_vec());
|
let matches = Matches::from_unsorted_matches(matches.to_vec());
|
||||||
assert_eq!(matches_proximity(&matches), 17);
|
assert_eq!(matches_proximity(matches), 17);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -118,8 +118,7 @@ mod tests {
|
|||||||
// soup -> of = 1
|
// soup -> of = 1
|
||||||
// + of -> the = 1
|
// + of -> the = 1
|
||||||
// + the -> day = 1
|
// + the -> day = 1
|
||||||
let matches = Matches::from_unsorted(matches.to_vec());
|
assert_eq!(matches_proximity(matches), 3);
|
||||||
assert_eq!(matches_proximity(&matches), 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +152,6 @@ mod bench {
|
|||||||
matches.push(match_);
|
matches.push(match_);
|
||||||
}
|
}
|
||||||
|
|
||||||
let matches = Matches::from_unsorted(matches.to_vec());
|
|
||||||
|
|
||||||
bench.iter(|| {
|
bench.iter(|| {
|
||||||
let proximity = matches_proximity(&matches);
|
let proximity = matches_proximity(&matches);
|
||||||
test::black_box(move || proximity)
|
test::black_box(move || proximity)
|
||||||
|
@ -23,19 +23,28 @@ pub struct Document {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Document {
|
impl Document {
|
||||||
pub fn new(id: DocumentId, match_: Match) -> Self {
|
pub fn new(doc: DocumentId, match_: Match) -> Self {
|
||||||
let matches = SetBuf::new_unchecked(vec![match_]);
|
let matches = SetBuf::new_unchecked(vec![match_]);
|
||||||
Self::from_matches(id, matches)
|
Self::from_matches(doc, matches)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_matches(id: DocumentId, matches: SetBuf<Match>) -> Self {
|
pub fn from_matches(id: DocumentId, matches: SetBuf<Match>) -> Self {
|
||||||
let matches = Matches::new(matches);
|
let mut last = 0;
|
||||||
|
let mut slices = vec![0];
|
||||||
|
for group in GroupBy::new(&matches, match_query_index) {
|
||||||
|
let index = last + group.len();
|
||||||
|
slices.push(index);
|
||||||
|
last = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
let matches = Matches { matches, slices };
|
||||||
Self { id, matches }
|
Self { id, matches }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_unsorted_matches(id: DocumentId, matches: Vec<Match>) -> Self {
|
pub fn from_unsorted_matches(doc: DocumentId, mut matches: Vec<Match>) -> Self {
|
||||||
let matches = Matches::from_unsorted(matches);
|
matches.sort_unstable();
|
||||||
Self { id, matches }
|
let matches = SetBuf::new_unchecked(matches);
|
||||||
|
Self::from_matches(doc, matches)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,25 +55,6 @@ pub struct Matches {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Matches {
|
impl Matches {
|
||||||
pub fn new(matches: SetBuf<Match>) -> Matches {
|
|
||||||
let mut last = 0;
|
|
||||||
let mut slices = vec![0];
|
|
||||||
|
|
||||||
for group in GroupBy::new(&matches, match_query_index) {
|
|
||||||
let index = last + group.len();
|
|
||||||
slices.push(index);
|
|
||||||
last = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
Matches { matches, slices }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_unsorted(mut matches: Vec<Match>) -> Matches {
|
|
||||||
matches.sort_unstable();
|
|
||||||
let matches = SetBuf::new_unchecked(matches);
|
|
||||||
Matches::new(matches)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn query_index_groups(&self) -> QueryIndexGroups {
|
pub fn query_index_groups(&self) -> QueryIndexGroups {
|
||||||
QueryIndexGroups {
|
QueryIndexGroups {
|
||||||
matches: &self.matches,
|
matches: &self.matches,
|
||||||
@ -85,7 +75,7 @@ impl<'a, 'b> Iterator for QueryIndexGroups<'a, 'b> {
|
|||||||
self.windows.next().map(|range| {
|
self.windows.next().map(|range| {
|
||||||
match *range {
|
match *range {
|
||||||
[left, right] => &self.matches[left..right],
|
[left, right] => &self.matches[left..right],
|
||||||
_ => unreachable!(),
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user