Skip to content

Commit

Permalink
Fix non-stored fields appearing as nulls in JSON search response (#100)
Browse files Browse the repository at this point in the history
* Fix non-stored fields being returned as nulls
  • Loading branch information
oka-tan authored Jul 14, 2022
1 parent 6437423 commit 95280de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lnx-engine/search-index/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,17 @@ impl FieldDeclaration {
FieldDeclaration::Facet { .. } => true,
}
}

#[inline]
pub fn is_stored(&self) -> bool {
match self {
FieldDeclaration::F64 { opts } => opts.base.stored,
FieldDeclaration::U64 { opts } => opts.base.stored,
FieldDeclaration::I64 { opts } => opts.base.stored,
FieldDeclaration::Date { opts } => opts.base.stored,
FieldDeclaration::Text { opts } => opts.stored,
FieldDeclaration::String { opts } => opts.stored,
FieldDeclaration::Facet { opts } => opts.stored,
}
}
}
4 changes: 4 additions & 0 deletions lnx-engine/search-index/src/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ impl DocumentHit {
) -> Self {
let mut compliant = HashMap::with_capacity(doc.0.len());
for (name, info) in ctx.fields() {
if !info.is_stored() {
continue;
}

let val = match doc.0.remove(name) {
Some(mut val) => {
if info.is_multi() {
Expand Down

0 comments on commit 95280de

Please sign in to comment.