|
|
@ -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.
|
|
|
|