Browse Source

Implement an actor around Searcher

this compiles, but isn't used yet.
pull/813/head
Mina Galić 4 months ago
parent
commit
54496c1527
Signed by: igalic <me+github@igalic.co> GPG Key ID: ACFEFF7F6A123A86
2 changed files with 39 additions and 1 deletions
  1. +1
    -1
      plume-models/src/posts.rs
  2. +38
    -0
      plume-models/src/search/searcher.rs

+ 1
- 1
plume-models/src/posts.rs View File

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


+ 38
- 0
plume-models/src/search/searcher.rs View File

@@ -5,6 +5,7 @@ use crate::{
use chrono::{Datelike, Utc};
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use itertools::Itertools;
use riker::actors::*;
use std::{
cmp,
fs::create_dir_all,
@@ -34,6 +35,43 @@ pub struct Searcher {
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 {
/// Initializes a new `Searcher`, ready to be used by
/// Plume.


Loading…
Cancel
Save