all repos — litestore @ c5e97550c3aa07c2abe812a1321491c63984a368

A minimalist nosql document store.

Implemented fulltext search support.
h3rald h3rald@h3rald.com
Sun, 11 Jan 2015 17:26:16 +0100
commit

c5e97550c3aa07c2abe812a1321491c63984a368

parent

f3d199e0ab78503d44889ba03e18ef775219c926

2 files changed, 10 insertions(+), 1 deletions(-)

jump to
M litestore.nimlitestore.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.nimutils.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: