You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1013 B
40 lines
1013 B
2 years ago
|
M = {}
|
||
|
|
||
|
local config = require('note-workflow.notes').config_values
|
||
|
local prefix = config.prefix
|
||
|
local server = config.server
|
||
|
|
||
|
local function file_exists(name)
|
||
|
local f = io.open(name, "r")
|
||
|
if f ~= nil then
|
||
|
io.close(f)
|
||
|
return true
|
||
|
else
|
||
|
return false
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function M.prune_search_db()
|
||
|
local curl = require "plenary.curl"
|
||
|
local json = require('json')
|
||
|
local hits = {}
|
||
|
|
||
|
local res = curl.get(server .. '/indexes/notes/documents?limit=99999999&fields=title,id', {
|
||
|
accept = "application/json",
|
||
|
})
|
||
|
|
||
|
if res then
|
||
|
local tab = json.parse(res.body)
|
||
|
if tab and tab['total'] > 0 then
|
||
|
for i, v in ipairs(tab['results']) do
|
||
|
if not file_exists(prefix .. v['title']) then
|
||
|
print('Delete ' .. v['title'] .. ' from search index')
|
||
|
curl.delete('http://localhost:7700/indexes/notes/documents/' .. v['id'], {})
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return M
|