Allow using 'like' for finding documents which name matches the pattern given as id
kaminski kaminski@naew.nato.int
Thu, 25 Mar 2021 23:07:17 +0100
3 files changed,
22 insertions(+),
3 deletions(-)
M
src/admin/md/api_docs.md
→
src/admin/md/api_docs.md
@@ -195,6 +195,20 @@ > Tip
> > If **search** is specified, each result will contain a **highlight** property with a highlighted search snippet, and a **rank** property identified the rank of the result within the search. Results will also be automatically ordered by descending rank. +##### `like` option + +If this option is specified, retrieves a single document which id matches the specified pattern. The value give to `like` option is not used so the search pattern is specified as the regular document id as a part of the path. The regular SQL wildcards `%` and `_` can be used. To escape them use `\` encoded in the URL as `%5C`. + +Example: http://127.0.0.1:9500/docs/%/api%5C_%.md?like=1&raw=true&contents=false&search=API%20v7%Required + +If finds the first markdown file which name starts with _api\__ and which contains string _API v7 Required_. + +> %tip% +> Tip +> +> Only the first matching document is returned even if there was more than one which id matched the pattern. To get the subsequent documents use `offset` option and increase its value from _1_ up. + + ##### `tags` option Retrieve only documents with matching tag(s).
M
src/litestorepkg/lib/config.nim
→
src/litestorepkg/lib/config.nim
@@ -1,6 +1,6 @@
const pkgName* = "litestore" - pkgVersion* = "1.9.3" + pkgVersion* = "1.9.4" pkgAuthor* = "Fabio Cevasco" pkgDescription* = "Self-contained, lightweight, RESTful document store." pkgLicense* = "MIT"
M
src/litestorepkg/lib/utils.nim
→
src/litestorepkg/lib/utils.nim
@@ -107,9 +107,12 @@ tables = options.tables & @[documents_table]
result = result & options.select.join(", ") result = result & " FROM "&tables.join(", ")&" WHERE 1=1 " if options.single: - result = result & "AND id = ?" + if options.like.len > 0: + options.limit = 1 + else: + result = result & "AND id = ?" var doc_id_col: string - if options.tags.len > 0 or options.folder.len > 0: + if options.tags.len > 0 or options.folder.len > 0 or options.like.len > 0: if options.jsonFilter.len > 0 or (options.search.len > 0 and options.select[0] != "COUNT(docid)"): doc_id_col = "$1.id" % documents_table else:@@ -124,6 +127,8 @@ if options.modifiedBefore != "":
result = result & "AND modified < \"" & $options.modifiedBefore & "\" " if options.folder.len > 0: result = result & "AND " & doc_id_col & " BETWEEN ? and ? " + if options.like.len > 0: + result = result & "AND " & doc_id_col & " LIKE ? ESCAPE '\\' " if options.tags.len > 0: result = result & options.tags.selectDocumentsByTags(doc_id_col) if options.jsonFilter.len > 0: