mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
remove heed from http dependencies
This commit is contained in:
parent
d69180ec67
commit
c771694623
8 changed files with 61 additions and 61 deletions
|
@ -1,9 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use log::error;
|
||||
use meilisearch_core::{Database, DatabaseOptions, MResult, MainT, UpdateT};
|
||||
use meilisearch_core::{Database, DatabaseOptions};
|
||||
use sha2::Digest;
|
||||
use sysinfo::Pid;
|
||||
|
||||
|
@ -56,53 +54,6 @@ impl ApiKeys {
|
|||
}
|
||||
}
|
||||
|
||||
impl DataInner {
|
||||
pub fn is_indexing(&self, reader: &heed::RoTxn<UpdateT>, index: &str) -> MResult<Option<bool>> {
|
||||
match self.db.open_index(&index) {
|
||||
Some(index) => index.current_update_id(&reader).map(|u| Some(u.is_some())),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_stats(&self, writer: &mut heed::RwTxn<MainT>, index_uid: &str) -> MResult<()> {
|
||||
let index = match self.db.open_index(&index_uid) {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
error!("Impossible to retrieve index {}", index_uid);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let schema = match index.main.schema(&writer)? {
|
||||
Some(schema) => schema,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
let all_documents_fields = index
|
||||
.documents_fields_counts
|
||||
.all_documents_fields_counts(&writer)?;
|
||||
|
||||
// count fields frequencies
|
||||
let mut fields_distribution = HashMap::<_, usize>::new();
|
||||
for result in all_documents_fields {
|
||||
let (_, attr, _) = result?;
|
||||
if let Some(field_id) = schema.indexed_pos_to_field_id(attr) {
|
||||
*fields_distribution.entry(field_id).or_default() += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// convert attributes to their names
|
||||
let distribution: HashMap<_, _> = fields_distribution
|
||||
.into_iter()
|
||||
.filter_map(|(a, c)| schema.name(a).map(|name| (name.to_string(), c)))
|
||||
.collect();
|
||||
|
||||
index
|
||||
.main
|
||||
.put_fields_distribution(writer, &distribution)
|
||||
}
|
||||
}
|
||||
|
||||
impl Data {
|
||||
pub fn new(opt: Opt) -> Data {
|
||||
let db_path = opt.db_path.clone();
|
||||
|
|
|
@ -5,11 +5,11 @@ use std::time::Instant;
|
|||
|
||||
use indexmap::IndexMap;
|
||||
use log::error;
|
||||
use meilisearch_core::Filter;
|
||||
use meilisearch_core::{Filter, MainReader};
|
||||
use meilisearch_core::facets::FacetFilter;
|
||||
use meilisearch_core::criterion::*;
|
||||
use meilisearch_core::settings::RankingRule;
|
||||
use meilisearch_core::{Highlight, Index, MainT, RankedMap};
|
||||
use meilisearch_core::{Highlight, Index, RankedMap};
|
||||
use meilisearch_schema::{FieldId, Schema};
|
||||
use meilisearch_tokenizer::is_cjk;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -107,7 +107,7 @@ impl<'a> SearchBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn search(self, reader: &heed::RoTxn<MainT>) -> Result<SearchResult, ResponseError> {
|
||||
pub fn search(self, reader: &MainReader) -> Result<SearchResult, ResponseError> {
|
||||
let schema = self
|
||||
.index
|
||||
.main
|
||||
|
@ -257,7 +257,7 @@ impl<'a> SearchBuilder<'a> {
|
|||
|
||||
pub fn get_criteria(
|
||||
&self,
|
||||
reader: &heed::RoTxn<MainT>,
|
||||
reader: &MainReader,
|
||||
ranked_map: &'a RankedMap,
|
||||
schema: &Schema,
|
||||
) -> Result<Option<Criteria<'a>>, ResponseError> {
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn index_update_callback(index_uid: &str, data: &Data, status: ProcessedUpda
|
|||
if let Some(index) = data.db.open_index(&index_uid) {
|
||||
let db = &data.db;
|
||||
let res = db.main_write::<_, _, ResponseError>(|mut writer| {
|
||||
if let Err(e) = data.compute_stats(&mut writer, &index_uid) {
|
||||
if let Err(e) = data.db.compute_stats(&mut writer, &index_uid) {
|
||||
error!("Impossible to compute stats; {}", e)
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ async fn index_stats(
|
|||
let update_reader = data.db.update_read_txn()?;
|
||||
|
||||
let is_indexing =
|
||||
data.is_indexing(&update_reader, &path.index_uid)?
|
||||
data.db.is_indexing(&update_reader, &path.index_uid)?
|
||||
.ok_or(Error::internal(
|
||||
"Impossible to know if the database is indexing",
|
||||
))?;
|
||||
|
@ -86,7 +86,7 @@ async fn get_stats(data: web::Data<Data>) -> Result<HttpResponse, ResponseError>
|
|||
|
||||
let fields_distribution = index.main.fields_distribution(&reader)?.unwrap_or_default();
|
||||
|
||||
let is_indexing = data.is_indexing(&update_reader, &index_uid)?.ok_or(
|
||||
let is_indexing = data.db.is_indexing(&update_reader, &index_uid)?.ok_or(
|
||||
Error::internal("Impossible to know if the database is indexing"),
|
||||
)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue