Add an SearcherActor, wrapping Searcher & DbPool

and implement AddDocument message!
This code compiles, but hasn't been put to use yet.
pull/813/head
Mina Galić 4 years ago
parent d344e06efd
commit 5e17636b9d
Signed by: igalic
GPG Key ID: ACFEFF7F6A123A86

@ -24,7 +24,7 @@ use std::collections::HashSet;
pub type LicensedArticle = CustomObject<Licensed, Article>; pub type LicensedArticle = CustomObject<Licensed, Article>;
#[derive(Queryable, Identifiable, Clone, AsChangeset)] #[derive(Debug, Queryable, Identifiable, Clone, AsChangeset)]
#[changeset_options(treat_none_as_null = "true")] #[changeset_options(treat_none_as_null = "true")]
pub struct Post { pub struct Post {
pub id: i32, pub id: i32,

@ -1,10 +1,11 @@
use crate::{ 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, search::query::PlumeQuery, tags::Tag, Connection, Result,
}; };
use chrono::Datelike; use chrono::Datelike;
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use itertools::Itertools; use itertools::Itertools;
use riker::actors::*;
use std::{cmp, fs::create_dir_all, io, path::Path, sync::Mutex}; use std::{cmp, fs::create_dir_all, io, path::Path, sync::Mutex};
use tantivy::{ use tantivy::{
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter, collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter,
@ -254,3 +255,31 @@ impl Searcher {
self.writer.lock().unwrap().take(); 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…
Cancel
Save