Browse Source

Add an SearcherActor, wrapping Searcher & DbPool

and implement AddDocument message!
This code compiles, but hasn't been put to use yet.
undefined
Mina Galić 4 months ago
parent
commit
0757f84397
Signed by: igalic <me+github@igalic.co> GPG Key ID: ACFEFF7F6A123A86
2 changed files with 31 additions and 2 deletions
  1. +1
    -1
      plume-models/src/posts.rs
  2. +30
    -1
      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,


+ 30
- 1
plume-models/src/search/searcher.rs View File

@@ -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…
Cancel
Save