all repos — litestore @ ad7f472c78f255f3f8b6e5680380693780f3b231

A minimalist nosql document store.

Greatly enhanced full-text search performance.
h3rald h3rald@h3rald.com
Fri, 24 Apr 2015 22:16:56 +0200
commit

ad7f472c78f255f3f8b6e5680380693780f3b231

parent

02943db68373dbf8f647784c1b3135d94047da93

3 files changed, 12 insertions(+), 12 deletions(-)

jump to
M lib/api_v1.nimlib/api_v1.nim

@@ -119,7 +119,6 @@ result.content = doc

result.code = Http200 proc getDocument(LS: LiteStore, id: string, options = newQueryOptions()): Response = - let id = id.decodeURL let doc = LS.store.retrieveDocument(id, options) if doc.data == "": result = resDocumentNotFound(id)

@@ -152,7 +151,7 @@ let orig_limit = options.limit

let orig_offset = options.offset options.limit = 0 options.offset = 0 - options.select = @["COUNT(documents.id)"] + options.select = @["COUNT(docid)"] let total = LS.store.retrieveRawDocuments(options)[0].num if docs.len == 0: result = resError(Http404, "No documents found.")

@@ -311,6 +310,7 @@ except:

return resError(Http400, "Bad request - $1" % getCurrentExceptionMsg()) proc get(req: Request, LS: LiteStore, resource: string, id = ""): Response = + let id = id.decodeURL case resource: of "docs": var options = newQueryOptions()
M lib/queries.nimlib/queries.nim

@@ -5,7 +5,7 @@ # SQL QUERIES

const SQL_CREATE_DOCUMENTS_TABLE* = sql""" CREATE TABLE documents ( -rowid INTEGER PRIMARY KEY, +docid INTEGER PRIMARY KEY, id TEST, data TEXT, content_type TEXT,
M lib/utils.nimlib/utils.nim

@@ -22,11 +22,11 @@

proc prepareSelectDocumentsQuery*(options: var QueryOptions): string = result = "SELECT " if options.search.len > 0: - if options.select[0] != "COUNT(documents.id)": - var rank = "rank(matchinfo(searchcontents, 'pcxnal'), 1.20, 0.75, 5.0, 0.5) AS rank" - options.select.add("snippet(searchcontents) AS highlight") + if options.select[0] != "COUNT(docid)": + let rank = "rank(matchinfo(searchcontents, 'pcxnal'), 1.20, 0.75, 5.0, 0.5) AS rank" + let snippet = "snippet(searchcontents, \"<strong>\", \"</strong>\", \"<strong>&hellip;</strong>\", -1, 30) as highlight" + options.select.add(snippet) options.select.add("ranktable.rank AS rank") - options.select.add(rank) options.orderby = "rank DESC" # Create inner select var innerSelect = "SELECT docid, " & rank & " FROM searchcontents WHERE searchcontents MATCH '" & options.search.replace("'", "''") & "' "

@@ -38,12 +38,12 @@ innerSelect = innerSelect & "LIMIT " & $options.limit

if options.offset > 0: innerSelect = innerSelect & " OFFSET " & $options.offset result = result & options.select.join(", ") - result = result & " FROM documents, searchcontents, (" & innerSelect & ") AS ranktable " - result = result & "WHERE ranktable.docid = documents.rowid AND documents.id = searchcontents.id " + result = result & " FROM documents JOIN (" & innerSelect & ") as ranktable USING(docid) JOIN searchcontents USING(docid) " + result = result & "WHERE 1=1 " else: result = result & options.select.join(", ") - result = result & " FROM documents, searchcontents " - result = result & "WHERE searchcontents.id = documents.id " + result = result & " FROM searchcontents " + result = result & "WHERE 1=1 " options.orderby = "" else: result = result & options.select.join(", ")

@@ -56,7 +56,7 @@ if options.search.len > 0:

result = result & "AND searchcontents MATCH '" & options.search.replace("'", "''") & "' " if options.orderby.len > 0 and options.select[0] != "COUNT(id)": result = result & "ORDER BY " & options.orderby & " " - if options.limit > 0: + if options.search.len == 0 and options.limit > 0: result = result & "LIMIT " & $options.limit & " " if options.offset > 0: result = result & "OFFSET " & $options.offset & " "