mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-22 20:50:04 +01:00
Revert "feat: Allow Matches to be constructed"
This reverts commit d21406a93908b2b3ed8cd57b2182996b43cf7806.
This commit is contained in:
parent
f32a59720d
commit
a78b5d225f
@ -66,7 +66,10 @@ mod tests {
|
||||
word_area: WordArea::new_faillible(0, 6)
|
||||
},
|
||||
];
|
||||
Document::from_unsorted_matches(DocumentId(0), matches)
|
||||
Document {
|
||||
id: DocumentId(0),
|
||||
matches: matches,
|
||||
}
|
||||
};
|
||||
|
||||
let doc1 = {
|
||||
@ -86,7 +89,10 @@ mod tests {
|
||||
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);
|
||||
@ -117,7 +123,10 @@ mod tests {
|
||||
word_area: WordArea::new_faillible(0, 6)
|
||||
},
|
||||
];
|
||||
Document::from_unsorted_matches(DocumentId(0), matches)
|
||||
Document {
|
||||
id: DocumentId(0),
|
||||
matches: matches,
|
||||
}
|
||||
};
|
||||
|
||||
let doc1 = {
|
||||
@ -130,7 +139,10 @@ mod tests {
|
||||
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);
|
||||
@ -161,7 +173,10 @@ mod tests {
|
||||
word_area: WordArea::new_faillible(0, 6)
|
||||
},
|
||||
];
|
||||
Document::from_unsorted_matches(DocumentId(0), matches)
|
||||
Document {
|
||||
id: DocumentId(0),
|
||||
matches: matches,
|
||||
}
|
||||
};
|
||||
|
||||
let doc1 = {
|
||||
@ -174,7 +189,10 @@ mod tests {
|
||||
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);
|
||||
|
@ -90,8 +90,8 @@ mod tests {
|
||||
// soup -> of = 8
|
||||
// + of -> the = 1
|
||||
// + the -> day = 8 (not 1)
|
||||
let matches = Matches::from_unsorted(matches.to_vec());
|
||||
assert_eq!(matches_proximity(&matches), 17);
|
||||
let matches = Matches::from_unsorted_matches(matches.to_vec());
|
||||
assert_eq!(matches_proximity(matches), 17);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -118,8 +118,7 @@ mod tests {
|
||||
// soup -> of = 1
|
||||
// + of -> the = 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_);
|
||||
}
|
||||
|
||||
let matches = Matches::from_unsorted(matches.to_vec());
|
||||
|
||||
bench.iter(|| {
|
||||
let proximity = matches_proximity(&matches);
|
||||
test::black_box(move || proximity)
|
||||
|
@ -23,19 +23,28 @@ pub struct 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_]);
|
||||
Self::from_matches(id, matches)
|
||||
Self::from_matches(doc, matches)
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
|
||||
pub fn from_unsorted_matches(id: DocumentId, matches: Vec<Match>) -> Self {
|
||||
let matches = Matches::from_unsorted(matches);
|
||||
Self { id, matches }
|
||||
pub fn from_unsorted_matches(doc: DocumentId, mut matches: Vec<Match>) -> Self {
|
||||
matches.sort_unstable();
|
||||
let matches = SetBuf::new_unchecked(matches);
|
||||
Self::from_matches(doc, matches)
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,25 +55,6 @@ pub struct 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 {
|
||||
QueryIndexGroups {
|
||||
matches: &self.matches,
|
||||
@ -85,7 +75,7 @@ impl<'a, 'b> Iterator for QueryIndexGroups<'a, 'b> {
|
||||
self.windows.next().map(|range| {
|
||||
match *range {
|
||||
[left, right] => &self.matches[left..right],
|
||||
_ => unreachable!(),
|
||||
_ => unreachable!()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user