mirror of
https://github.com/simon987/sist2.git
synced 2025-04-10 14:06:45 +00:00
Add option to search in path for sqlite #402
This commit is contained in:
parent
49a21a5a25
commit
f423863acb
@ -155,7 +155,6 @@ indices, but it uses much less memory and is easier to set up.
|
||||
| Query syntax | [fts5](https://www.sqlite.org/fts5.html) | [query_string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax) |
|
||||
| Fuzzy search | | ✓ |
|
||||
| Media Types tree real-time updating | | ✓ |
|
||||
| Search in file `path` | [WIP](https://github.com/simon987/sist2/issues/402) | ✓ |
|
||||
| Manual tagging | ✓ | ✓ |
|
||||
| User scripts | ✓ | ✓ |
|
||||
| Media Type breakdown for search results | | ✓ |
|
||||
|
@ -106,6 +106,8 @@ class Sist2ElasticsearchQuery {
|
||||
q["sortAsc"] = true;
|
||||
}
|
||||
|
||||
q["searchInPath"] = getters.optSearchInPath;
|
||||
|
||||
return q;
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@
|
||||
{{ $t("opt.fuzzy") }}
|
||||
</b-form-checkbox>
|
||||
|
||||
<b-form-checkbox :disabled="uiSqliteMode" :checked="optSearchInPath" @input="setOptSearchInPath">{{
|
||||
<b-form-checkbox :checked="optSearchInPath" @input="setOptSearchInPath">{{
|
||||
$t("opt.searchInPath")
|
||||
}}
|
||||
</b-form-checkbox>
|
||||
|
@ -160,7 +160,8 @@ void database_fts_index(database_t *db) {
|
||||
|
||||
CRASH_IF_NOT_SQLITE_OK(sqlite3_exec(
|
||||
db->db,
|
||||
"INSERT INTO search(rowid, name, content, title) SELECT id, name, content, title from document_view",
|
||||
"INSERT INTO search(rowid, name, content, title, path) "
|
||||
"SELECT id, name, content, title, path from document_view",
|
||||
NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
|
@ -75,23 +75,25 @@ const char *FtsDatabaseSchema =
|
||||
" WHERE id = OLD.id;"
|
||||
" END;"
|
||||
""
|
||||
"CREATE VIEW IF NOT EXISTS document_view (id, name, content, title)"
|
||||
"CREATE VIEW IF NOT EXISTS document_view (id, name, content, title, path)"
|
||||
" AS"
|
||||
" SELECT id,"
|
||||
" json_data->>'name',"
|
||||
" json_data->>'content',"
|
||||
" json_data->>'title'"
|
||||
" json_data->>'title',"
|
||||
" json_data->>'path'"
|
||||
" FROM document_index;"
|
||||
""
|
||||
"CREATE VIRTUAL TABLE IF NOT EXISTS search USING fts5 ("
|
||||
" name,"
|
||||
" content,"
|
||||
" title,"
|
||||
" path,"
|
||||
" content='document_view',"
|
||||
" content_rowid='id'"
|
||||
");"
|
||||
// name^8, content^3, title^8
|
||||
"INSERT INTO search(search, rank) VALUES('rank', 'bm25(8, 3, 8)');"
|
||||
// name^8, content^3, title^8, path^5
|
||||
"INSERT INTO search(search, rank) VALUES('rank', 'bm25(8, 3, 8, 5)');"
|
||||
"";
|
||||
|
||||
const char *IpcDatabaseSchema =
|
||||
|
@ -51,11 +51,11 @@
|
||||
#include <ctype.h>
|
||||
#include "git_hash.h"
|
||||
|
||||
#define VERSION "3.3.6"
|
||||
#define VERSION "3.4.0"
|
||||
static const char *const Version = VERSION;
|
||||
static const int VersionMajor = 3;
|
||||
static const int VersionMinor = 3;
|
||||
static const int VersionPatch = 6;
|
||||
static const int VersionMinor = 4;
|
||||
static const int VersionPatch = 0;
|
||||
|
||||
#ifndef SIST_PLATFORM
|
||||
#define SIST_PLATFORM unknown
|
||||
|
@ -179,7 +179,8 @@ fts_search_req_t *get_search_req(struct mg_http_message *hm) {
|
||||
|
||||
json_value req_query, req_path, req_size_min, req_size_max, req_date_min, req_date_max, req_page_size,
|
||||
req_index_ids, req_mime_types, req_tags, req_sort_asc, req_sort, req_seed, req_after,
|
||||
req_fetch_aggregations, req_highlight, req_highlight_context_size, req_embedding, req_model;
|
||||
req_fetch_aggregations, req_highlight, req_highlight_context_size, req_embedding, req_model,
|
||||
req_search_in_path;
|
||||
|
||||
if (!cJSON_IsObject(json) ||
|
||||
(req_query = get_json_string(json, "query")).invalid ||
|
||||
@ -197,6 +198,7 @@ fts_search_req_t *get_search_req(struct mg_http_message *hm) {
|
||||
(req_index_ids = get_json_number_array(json, "indexIds")).invalid ||
|
||||
(req_mime_types = get_json_array(json, "mimeTypes")).invalid ||
|
||||
(req_highlight = get_json_bool(json, "highlight")).invalid ||
|
||||
(req_search_in_path = get_json_bool(json, "searchInPath")).invalid ||
|
||||
(req_highlight_context_size = get_json_number(json, "highlightContextSize")).invalid ||
|
||||
(req_embedding = get_json_number_array(json, "embedding")).invalid ||
|
||||
(req_model = get_json_number(json, "model")).invalid ||
|
||||
@ -252,7 +254,6 @@ fts_search_req_t *get_search_req(struct mg_http_message *hm) {
|
||||
fts_search_req_t *req = malloc(sizeof(fts_search_req_t));
|
||||
|
||||
req->sort = sort;
|
||||
req->query = req_query.val ? strdup(req_query.val->valuestring) : NULL;
|
||||
req->path = req_path.val ? strdup(req_path.val->valuestring) : NULL;
|
||||
req->size_min = req_size_min.val ? req_size_min.val->valuedouble : 0;
|
||||
req->size_max = req_size_max.val ? req_size_max.val->valuedouble : 0;
|
||||
@ -271,6 +272,16 @@ fts_search_req_t *get_search_req(struct mg_http_message *hm) {
|
||||
? req_highlight_context_size.val->valueint
|
||||
: DEFAULT_HIGHLIGHT_CONTEXT_SIZE;
|
||||
req->model = req_model.val ? req_model.val->valueint : 0;
|
||||
|
||||
if (req_search_in_path.val->valueint == FALSE && req_query.val) {
|
||||
if (asprintf(&req->query, "- path : %s", req_query.val->valuestring) == -1) {
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
req->query = req_query.val ? strdup(req_query.val->valuestring) : NULL;
|
||||
}
|
||||
|
||||
req->embedding = req_model.val
|
||||
? get_float_buffer(req_embedding.val, &req->embedding_size)
|
||||
: NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user