From 9b08f48dbd91c6a010c5e42c182cc560f059385d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 2 Nov 2020 13:01:32 +0100 Subject: [PATCH] Construct the documents based on the displayed fields or fields ids order --- src/subcommand/serve.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/subcommand/serve.rs b/src/subcommand/serve.rs index c4965491c..ff87ca80e 100644 --- a/src/subcommand/serve.rs +++ b/src/subcommand/serve.rs @@ -1,11 +1,12 @@ +use std::borrow::Cow; use std::collections::HashSet; use std::fs::{File, create_dir_all}; -use std::{mem, io}; use std::net::SocketAddr; use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; use std::time::Instant; +use std::{mem, io}; use askama_warp::Template; use flate2::read::GzDecoder; @@ -440,9 +441,14 @@ pub fn run(opt: Opt) -> anyhow::Result<()> { let mut documents = Vec::new(); let fields_ids_map = index.fields_ids_map(&rtxn).unwrap(); + let displayed_fields = match index.displayed_fields(&rtxn).unwrap() { + Some(fields) => Cow::Borrowed(fields), + None => Cow::Owned(fields_ids_map.iter().map(|(id, _)| id).collect()), + }; for (_id, record) in index.documents(&rtxn, documents_ids).unwrap() { - let mut record = record.iter() + let mut record = displayed_fields.iter() + .flat_map(|&id| record.get(id).map(|val| (id, val))) .map(|(key_id, value)| { let key = fields_ids_map.name(key_id).unwrap().to_owned(); // TODO we must deserialize a Json Value and highlight it.