Add an SearcherActor, wrapping Searcher & DbPool
and implement AddDocument message! This code compiles, but hasn't been put to use yet.
This commit is contained in:
parent
b59af45802
commit
ae4ec4f9bd
2 changed files with 31 additions and 2 deletions
|
@ -24,7 +24,7 @@ use std::collections::HashSet;
|
|||
|
||||
pub type LicensedArticle = CustomObject<Licensed, Article>;
|
||||
|
||||
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
||||
#[derive(Debug, Queryable, Identifiable, Clone, AsChangeset)]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
pub struct Post {
|
||||
pub id: i32,
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::{
|
||||
config::SearchTokenizerConfig, instance::Instance, posts::Post, schema::posts,
|
||||
config::SearchTokenizerConfig, db_conn::DbPool, instance::Instance, posts::Post, schema::posts,
|
||||
search::query::PlumeQuery, tags::Tag, Connection, Result,
|
||||
};
|
||||
use chrono::Datelike;
|
||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use itertools::Itertools;
|
||||
use riker::actors::*;
|
||||
use std::{cmp, fs::create_dir_all, io, path::Path, sync::Mutex};
|
||||
use tantivy::{
|
||||
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter,
|
||||
|
@ -254,3 +255,31 @@ impl Searcher {
|
|||
self.writer.lock().unwrap().take();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AddDocument(Post);
|
||||
|
||||
#[actor(AddDocument)]
|
||||
pub struct SearcherActor {
|
||||
searcher: Searcher,
|
||||
db_pool: DbPool,
|
||||
}
|
||||
|
||||
impl Actor for SearcherActor {
|
||||
// we used the #[actor] attribute so SearcherActorMsg is the Msg type
|
||||
type Msg = SearcherActorMsg;
|
||||
|
||||
fn recv(&mut self, ctx: &Context<Self::Msg>, msg: Self::Msg, sender: Sender) {
|
||||
// Use the respective Receive<T> implementation
|
||||
self.receive(ctx, msg, sender);
|
||||
}
|
||||
}
|
||||
|
||||
impl Receive<AddDocument> for SearcherActor {
|
||||
type Msg = SearcherActorMsg;
|
||||
|
||||
fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: AddDocument, _sender: Sender) {
|
||||
let conn = self.db_pool.get().unwrap();
|
||||
let _ = self.searcher.add_document(&conn, &msg.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue