Return the correct response JSON object from the facet-search route

This commit is contained in:
Clément Renault 2023-04-26 17:09:59 +02:00 committed by Louis Dureuil
parent 893592c5e9
commit 93f30e65a9
No known key found for this signature in database
5 changed files with 28 additions and 58 deletions

View file

@ -1,6 +1,6 @@
use fst::Set;
use std::borrow::Cow;
use fst::Set;
use heed::{BytesDecode, BytesEncode};
/// A codec for values of type `Set<&[u8]>`.

View file

@ -57,7 +57,7 @@ pub use self::heed_codec::{
};
pub use self::index::Index;
pub use self::search::{
FacetDistribution, FacetSearchResult, Filter, FormatOptions, MatchBounds, MatcherBuilder,
FacetDistribution, FacetValueHit, Filter, FormatOptions, MatchBounds, MatcherBuilder,
MatchingWords, Search, SearchForFacetValue, SearchResult, TermsMatchingStrategy,
DEFAULT_VALUES_PER_FACET,
};

View file

@ -257,7 +257,7 @@ impl<'a> SearchForFacetValue<'a> {
self
}
pub fn execute(&self) -> Result<Vec<FacetSearchResult>> {
pub fn execute(&self) -> Result<Vec<FacetValueHit>> {
let index = self.search_query.index;
let rtxn = self.search_query.rtxn;
@ -304,7 +304,7 @@ impl<'a> SearchForFacetValue<'a> {
};
let count = search_candidates.intersection_len(&docids);
if count != 0 {
result.push(FacetSearchResult { value: value.to_string(), count });
result.push(FacetValueHit { value: value.to_string(), count });
length += 1;
}
if length >= MAX_NUMBER_OF_FACETS {
@ -327,7 +327,7 @@ impl<'a> SearchForFacetValue<'a> {
};
let count = search_candidates.intersection_len(&docids);
if count != 0 {
result.push(FacetSearchResult { value: value.to_string(), count });
result.push(FacetValueHit { value: value.to_string(), count });
length += 1;
}
if length >= MAX_NUMBER_OF_FACETS {
@ -341,8 +341,8 @@ impl<'a> SearchForFacetValue<'a> {
}
}
#[derive(Debug, serde::Serialize)]
pub struct FacetSearchResult {
#[derive(Debug, Clone, serde::Serialize, PartialEq)]
pub struct FacetValueHit {
/// The original facet value
pub value: String,
/// The number of documents associated to this facet