mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-28 17:21:03 +00:00
update tokio and disable all routes
This commit is contained in:
@ -2,7 +2,7 @@ use std::collections::{HashSet, BTreeMap};
|
||||
use std::mem;
|
||||
use std::time::Instant;
|
||||
|
||||
use anyhow::{bail, Context};
|
||||
use anyhow::bail;
|
||||
use either::Either;
|
||||
use heed::RoTxn;
|
||||
use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
|
||||
@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use super::Data;
|
||||
use crate::index_controller::IndexController;
|
||||
|
||||
pub const DEFAULT_SEARCH_LIMIT: usize = 20;
|
||||
|
||||
@ -202,107 +201,110 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
|
||||
impl Data {
|
||||
pub fn search<S: AsRef<str>>(
|
||||
&self,
|
||||
index: S,
|
||||
search_query: SearchQuery,
|
||||
_index: S,
|
||||
_search_query: SearchQuery,
|
||||
) -> anyhow::Result<SearchResult> {
|
||||
match self.index_controller.index(&index)? {
|
||||
Some(index) => Ok(search_query.perform(index)?),
|
||||
None => bail!("index {:?} doesn't exists", index.as_ref()),
|
||||
}
|
||||
todo!()
|
||||
//match self.index_controller.index(&index)? {
|
||||
//Some(index) => Ok(search_query.perform(index)?),
|
||||
//None => bail!("index {:?} doesn't exists", index.as_ref()),
|
||||
//}
|
||||
}
|
||||
|
||||
pub async fn retrieve_documents<S>(
|
||||
&self,
|
||||
index: impl AsRef<str> + Send + Sync + 'static,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
attributes_to_retrieve: Option<Vec<S>>,
|
||||
_index: String,
|
||||
_offset: usize,
|
||||
_limit: usize,
|
||||
_attributes_to_retrieve: Option<Vec<S>>,
|
||||
) -> anyhow::Result<Vec<Map<String, Value>>>
|
||||
where
|
||||
S: AsRef<str> + Send + Sync + 'static,
|
||||
{
|
||||
let index_controller = self.index_controller.clone();
|
||||
let documents: anyhow::Result<_> = tokio::task::spawn_blocking(move || {
|
||||
let index = index_controller
|
||||
.index(&index)?
|
||||
.with_context(|| format!("Index {:?} doesn't exist", index.as_ref()))?;
|
||||
todo!()
|
||||
//let index_controller = self.index_controller.clone();
|
||||
//let documents: anyhow::Result<_> = tokio::task::spawn_blocking(move || {
|
||||
//let index = index_controller
|
||||
//.index(index.clone())?
|
||||
//.with_context(|| format!("Index {:?} doesn't exist", index))?;
|
||||
|
||||
let txn = index.read_txn()?;
|
||||
//let txn = index.read_txn()?;
|
||||
|
||||
let fields_ids_map = index.fields_ids_map(&txn)?;
|
||||
//let fields_ids_map = index.fields_ids_map(&txn)?;
|
||||
|
||||
let attributes_to_retrieve_ids = match attributes_to_retrieve {
|
||||
Some(attrs) => attrs
|
||||
.iter()
|
||||
.filter_map(|f| fields_ids_map.id(f.as_ref()))
|
||||
.collect::<Vec<_>>(),
|
||||
None => fields_ids_map.iter().map(|(id, _)| id).collect(),
|
||||
};
|
||||
//let attributes_to_retrieve_ids = match attributes_to_retrieve {
|
||||
//Some(attrs) => attrs
|
||||
//.iter()
|
||||
//.filter_map(|f| fields_ids_map.id(f.as_ref()))
|
||||
//.collect::<Vec<_>>(),
|
||||
//None => fields_ids_map.iter().map(|(id, _)| id).collect(),
|
||||
//};
|
||||
|
||||
let iter = index.documents.range(&txn, &(..))?.skip(offset).take(limit);
|
||||
//let iter = index.documents.range(&txn, &(..))?.skip(offset).take(limit);
|
||||
|
||||
let mut documents = Vec::new();
|
||||
//let mut documents = Vec::new();
|
||||
|
||||
for entry in iter {
|
||||
let (_id, obkv) = entry?;
|
||||
let object = obkv_to_json(&attributes_to_retrieve_ids, &fields_ids_map, obkv)?;
|
||||
documents.push(object);
|
||||
}
|
||||
//for entry in iter {
|
||||
//let (_id, obkv) = entry?;
|
||||
//let object = obkv_to_json(&attributes_to_retrieve_ids, &fields_ids_map, obkv)?;
|
||||
//documents.push(object);
|
||||
//}
|
||||
|
||||
Ok(documents)
|
||||
})
|
||||
.await?;
|
||||
documents
|
||||
//Ok(documents)
|
||||
//})
|
||||
//.await?;
|
||||
//documents
|
||||
}
|
||||
|
||||
pub async fn retrieve_document<S>(
|
||||
&self,
|
||||
index: impl AsRef<str> + Sync + Send + 'static,
|
||||
document_id: impl AsRef<str> + Sync + Send + 'static,
|
||||
attributes_to_retrieve: Option<Vec<S>>,
|
||||
_index: impl AsRef<str> + Sync + Send + 'static,
|
||||
_document_id: impl AsRef<str> + Sync + Send + 'static,
|
||||
_attributes_to_retrieve: Option<Vec<S>>,
|
||||
) -> anyhow::Result<Map<String, Value>>
|
||||
where
|
||||
S: AsRef<str> + Sync + Send + 'static,
|
||||
{
|
||||
let index_controller = self.index_controller.clone();
|
||||
let document: anyhow::Result<_> = tokio::task::spawn_blocking(move || {
|
||||
let index = index_controller
|
||||
.index(&index)?
|
||||
.with_context(|| format!("Index {:?} doesn't exist", index.as_ref()))?;
|
||||
let txn = index.read_txn()?;
|
||||
todo!()
|
||||
//let index_controller = self.index_controller.clone();
|
||||
//let document: anyhow::Result<_> = tokio::task::spawn_blocking(move || {
|
||||
//let index = index_controller
|
||||
//.index(&index)?
|
||||
//.with_context(|| format!("Index {:?} doesn't exist", index.as_ref()))?;
|
||||
//let txn = index.read_txn()?;
|
||||
|
||||
let fields_ids_map = index.fields_ids_map(&txn)?;
|
||||
//let fields_ids_map = index.fields_ids_map(&txn)?;
|
||||
|
||||
let attributes_to_retrieve_ids = match attributes_to_retrieve {
|
||||
Some(attrs) => attrs
|
||||
.iter()
|
||||
.filter_map(|f| fields_ids_map.id(f.as_ref()))
|
||||
.collect::<Vec<_>>(),
|
||||
None => fields_ids_map.iter().map(|(id, _)| id).collect(),
|
||||
};
|
||||
//let attributes_to_retrieve_ids = match attributes_to_retrieve {
|
||||
//Some(attrs) => attrs
|
||||
//.iter()
|
||||
//.filter_map(|f| fields_ids_map.id(f.as_ref()))
|
||||
//.collect::<Vec<_>>(),
|
||||
//None => fields_ids_map.iter().map(|(id, _)| id).collect(),
|
||||
//};
|
||||
|
||||
let internal_id = index
|
||||
.external_documents_ids(&txn)?
|
||||
.get(document_id.as_ref().as_bytes())
|
||||
.with_context(|| format!("Document with id {} not found", document_id.as_ref()))?;
|
||||
//let internal_id = index
|
||||
//.external_documents_ids(&txn)?
|
||||
//.get(document_id.as_ref().as_bytes())
|
||||
//.with_context(|| format!("Document with id {} not found", document_id.as_ref()))?;
|
||||
|
||||
let document = index
|
||||
.documents(&txn, std::iter::once(internal_id))?
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|(_, d)| d);
|
||||
//let document = index
|
||||
//.documents(&txn, std::iter::once(internal_id))?
|
||||
//.into_iter()
|
||||
//.next()
|
||||
//.map(|(_, d)| d);
|
||||
|
||||
match document {
|
||||
Some(document) => Ok(obkv_to_json(
|
||||
&attributes_to_retrieve_ids,
|
||||
&fields_ids_map,
|
||||
document,
|
||||
)?),
|
||||
None => bail!("Document with id {} not found", document_id.as_ref()),
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
document
|
||||
//match document {
|
||||
//Some(document) => Ok(obkv_to_json(
|
||||
//&attributes_to_retrieve_ids,
|
||||
//&fields_ids_map,
|
||||
//document,
|
||||
//)?),
|
||||
//None => bail!("Document with id {} not found", document_id.as_ref()),
|
||||
//}
|
||||
//})
|
||||
//.await?;
|
||||
//document
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user