|
|
@ -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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|