Implement an actor around Searcher

this compiles, but isn't used yet.
pull/813/head
Mina Galić 4 years ago
parent 4b0b03b848
commit 54496c1527
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,

@ -5,6 +5,7 @@ use crate::{
use chrono::{Datelike, Utc}; use chrono::{Datelike, Utc};
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use itertools::Itertools; use itertools::Itertools;
use riker::actors::*;
use std::{ use std::{
cmp, cmp,
fs::create_dir_all, fs::create_dir_all,
@ -34,6 +35,43 @@ pub struct Searcher {
dbpool: DbPool, dbpool: DbPool,
} }
#[derive(Clone, Debug)]
pub struct AddDocument(Post);
#[derive(Clone, Debug)]
pub struct UpdateDocument(Post);
#[derive(Clone, Debug)]
pub struct DeleteDocument(Post);
#[actor(AddDocument)]
pub struct SearcherActor(Searcher);
impl Actor for SearcherActor {
type Msg = SearcherActorMsg;
// forwards Msg to the respective Receive<T> implementation
fn recv(&mut self, ctx: &Context<Self::Msg>, msg: Self::Msg, sender: Sender) {
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 _ = self.0.add_document(&msg.0);
}
}
impl Receive<UpdateDocument> for SearcherActor {
type Msg = SearcherActorMsg;
fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: UpdateDocument, _sender: Sender) {
let _ = self.0.update_document(&msg.0);
}
}
impl Searcher { impl Searcher {
/// Initializes a new `Searcher`, ready to be used by /// Initializes a new `Searcher`, ready to be used by
/// Plume. /// Plume.

Loading…
Cancel
Save