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, err = pcall(curl.get(server .. '/indexes/notes/documents?limit=99999999&fields=title,id', { accept = "application/json", })) if er ~= nil and res.status ~= 404 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