Implemented fulltext search support.
h3rald h3rald@h3rald.com
Sun, 11 Jan 2015 17:26:16 +0100
2 files changed,
10 insertions(+),
1 deletions(-)
M
litestore.nim
→
litestore.nim
@@ -156,5 +156,6 @@ store.createTag "test", id1
store.createTag "test", id2 store.createTag "test", id3 var opts = newQueryOptions() -opts.tags = "test,test2" +#opts.tags = "test,test2" +#opts.search = "another yet" echo store.retrieveDocuments(opts)
M
utils.nim
→
utils.nim
@@ -8,6 +8,12 @@
let PEG_USER_TAG* = peg""" ^[a-zA-Z0-9_-?~:.@#^%!]+$ """ +proc dbQuote(s: string): string = + result = "'" + for c in items(s): + if c == '\'': add(result, "''") + else: add(result, c) + add(result, '\'') proc selectDocumentsByTags(tags: string): string = var select_tagged = "SELECT document_id FROM tags WHERE tag_id = \""@@ -33,6 +39,8 @@ if options.single:
result = result & "AND id = ?" if options.tags.len > 0: result = result & options.tags.selectDocumentsByTags() + if options.search.len > 0: + result = result & "AND content MATCH \"" & options.search.dbQuote & "\"" if options.orderby.validOrderBy(): result = result & "ORDER BY " & options.orderby & " " if options.limit > 0: