From f0846ff5465e3e28807570f0110437098f60efa1 Mon Sep 17 00:00:00 2001 From: Violet White Date: Sun, 3 Nov 2019 11:51:10 -0500 Subject: [PATCH] Make the search index creation during migration respect SEARCH_INDEX (#689) * Make the search index creation during migration respect SEARCH_INDEX * Make the search subcommand respect it too --- .../up.sql | 6 +++--- .../up.sql | 6 +++--- plume-cli/src/search.rs | 16 +++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql b/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql index 2cdec21e..9d331b4e 100644 --- a/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql +++ b/migrations/postgres/2019-04-28-201506_create_tantivy_index/up.sql @@ -1,10 +1,10 @@ -- Your SQL goes here --#!|conn: &Connection, path: &Path| { ---#! let mut pb = path.to_path_buf(); ---#! pb.push("search_index"); +--#! use std::env::var; +--#! let mut pb = Path::new(&var("SEARCH_INDEX") +--#! .unwrap_or_else(|_|"search_index".to_owned())).to_path_buf(); --#! let searcher = super::search::Searcher::create(&pb)?; --#! searcher.fill(conn)?; --#! searcher.commit(); --#! Ok(()) --#!} - diff --git a/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql b/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql index 2cdec21e..9d331b4e 100644 --- a/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql +++ b/migrations/sqlite/2019-04-28-201506_create_tantivy_index/up.sql @@ -1,10 +1,10 @@ -- Your SQL goes here --#!|conn: &Connection, path: &Path| { ---#! let mut pb = path.to_path_buf(); ---#! pb.push("search_index"); +--#! use std::env::var; +--#! let mut pb = Path::new(&var("SEARCH_INDEX") +--#! .unwrap_or_else(|_|"search_index".to_owned())).to_path_buf(); --#! let searcher = super::search::Searcher::create(&pb)?; --#! searcher.fill(conn)?; --#! searcher.commit(); --#! Ok(()) --#!} - diff --git a/plume-cli/src/search.rs b/plume-cli/src/search.rs index 4eadd8e7..ee68393d 100644 --- a/plume-cli/src/search.rs +++ b/plume-cli/src/search.rs @@ -93,8 +93,11 @@ fn init<'a>(args: &ArgMatches<'a>, conn: &Connection) { } fn refill<'a>(args: &ArgMatches<'a>, conn: &Connection, searcher: Option) { - let path = args.value_of("path").unwrap_or("."); - let path = Path::new(path).join("search_index"); + let path = args.value_of("path"); + let path = match path { + Some(path) => Path::new(path).join("search_index"), + None => Path::new(&CONFIG.search_index).to_path_buf(), + }; let searcher = searcher.unwrap_or_else(|| Searcher::open(&path).unwrap()); searcher.fill(conn).expect("Couldn't import post"); @@ -103,9 +106,12 @@ fn refill<'a>(args: &ArgMatches<'a>, conn: &Connection, searcher: Option(args: &ArgMatches<'a>) { - let path = args.value_of("path").unwrap_or("."); - let meta = Path::new(path).join("search_index/.tantivy-meta.lock"); + let path = match args.value_of("path") { + None => Path::new(&CONFIG.search_index), + Some(x) => Path::new(x), + }; + let meta = Path::new(path).join(".tantivy-meta.lock"); remove_file(meta).unwrap(); - let writer = Path::new(path).join("search_index/.tantivy-writer.lock"); + let writer = Path::new(path).join(".tantivy-writer.lock"); remove_file(writer).unwrap(); }