SQLite search backend

This commit is contained in:
2023-05-18 14:16:11 -04:00
parent 1cfceba518
commit 944c224904
46 changed files with 3261 additions and 1296 deletions

View File

@@ -362,11 +362,10 @@ void sist2_sqlite_index(sqlite_index_args_t *args) {
database_fts_attach(db, args->search_index_path);
database_fts_index(db);
if (args->optimize_database) {
database_fts_optimize(db);
}
database_fts_optimize(db);
database_close(db, FALSE);
database_close(search_db, FALSE);
}
void sist2_exec_script(exec_args_t *args) {
@@ -391,6 +390,7 @@ void sist2_exec_script(exec_args_t *args) {
void sist2_web(web_args_t *args) {
WebCtx.es_url = args->es_url;
WebCtx.search_backend = args->search_backend;
WebCtx.es_index = args->es_index;
WebCtx.es_insecure_ssl = args->es_insecure_ssl;
WebCtx.index_count = args->index_count;
@@ -407,15 +407,27 @@ void sist2_web(web_args_t *args) {
WebCtx.auth0_audience = args->auth0_audience;
strcpy(WebCtx.lang, args->lang);
if (args->search_backend == SQLITE_SEARCH_BACKEND) {
WebCtx.search_db = database_create(args->search_index_path, FTS_DATABASE);
database_open(WebCtx.search_db);
}
for (int i = 0; i < args->index_count; i++) {
char *abs_path = abspath(args->indices[i]);
strcpy(WebCtx.indices[i].path, abs_path);
WebCtx.indices[i].db = database_create(abs_path, INDEX_DATABASE);
database_open(WebCtx.indices[i].db);
database_t *db = database_create(abs_path, INDEX_DATABASE);
database_open(db);
if (WebCtx.search_backend == SQLITE_SEARCH_BACKEND) {
database_fts_attach(db, args->search_index_path);
database_fts_sync_tags(db);
database_fts_detach(db);
}
index_descriptor_t *desc = database_read_index_descriptor(WebCtx.indices[i].db);
WebCtx.indices[i].db = db;
index_descriptor_t *desc = database_read_index_descriptor(db);
WebCtx.indices[i].desc = *desc;
free(desc);
@@ -465,6 +477,7 @@ int main(int argc, const char *argv[]) {
int common_async_script = 0;
int common_threads = 0;
int common_optimize_database = 0;
char *common_search_index = NULL;
struct argparse_option options[] = {
OPT_HELP(),
@@ -541,14 +554,14 @@ int main(int argc, const char *argv[]) {
OPT_BOOLEAN('f', "force-reset", &index_args->force_reset, "Reset Elasticsearch mappings and settings."),
OPT_GROUP("sqlite-index options"),
OPT_STRING(0, "search-index", &sqlite_index_args->search_index_path, "Path to search index. Will be created if it does not exist yet."),
OPT_BOOLEAN(0, "optimize-index", &common_optimize_database,
"Optimize search index file for smaller size and faster queries."),
OPT_STRING(0, "search-index", &common_search_index, "Path to search index. Will be created if it does not exist yet."),
OPT_GROUP("Web options"),
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT: http://localhost:9200"),
OPT_BOOLEAN(0, "es-insecure-ssl", &common_es_insecure_ssl,
"Do not verify SSL connections to Elasticsearch."),
// TODO: change arg name (?)
OPT_STRING(0, "search-index", &common_search_index, "Path to SQLite search index."),
OPT_STRING(0, "es-index", &common_es_index, "Elasticsearch index name. DEFAULT: sist2"),
OPT_STRING(0, "bind", &web_args->listen_address,
"Listen for connections on this address. DEFAULT: localhost:4090"),
@@ -584,7 +597,7 @@ int main(int argc, const char *argv[]) {
argc = argparse_parse(&argparse, argc, argv);
if (arg_version) {
printf(Version);
printf("%s", Version);
goto end;
}
@@ -612,7 +625,9 @@ int main(int argc, const char *argv[]) {
index_args->async_script = common_async_script;
scan_args->optimize_database = common_optimize_database;
sqlite_index_args->optimize_database = common_optimize_database;
sqlite_index_args->search_index_path = common_search_index;
web_args->search_index_path = common_search_index;
if (argc == 0) {
argparse_usage(&argparse);