summary refs log tree commit diff stats
path: root/tools/dochack/dochack.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-09-09 20:42:02 +0200
committerAraq <rumpf_a@web.de>2016-09-09 20:42:02 +0200
commit3dfc86671005d033f6a7f3b68e0aeabeb1f4cfb9 (patch)
treeea250749d8b1b0ae4db6ad295a6143e1c6a96001 /tools/dochack/dochack.nim
parent3a3aeb94ecf2b0a0f91470719f5e22dc6ff475c6 (diff)
downloadNim-3dfc86671005d033f6a7f3b68e0aeabeb1f4cfb9.tar.gz
docgen: working search feature
Diffstat (limited to 'tools/dochack/dochack.nim')
-rw-r--r--tools/dochack/dochack.nim20
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/dochack/dochack.nim b/tools/dochack/dochack.nim
index 8d95fc5fd..fbfbea007 100644
--- a/tools/dochack/dochack.nim
+++ b/tools/dochack/dochack.nim
@@ -241,7 +241,7 @@ proc dosearch(value: cstring): Element =
     var stuff: Element
     {.emit: """
     var request = new XMLHttpRequest();
-    request.open("GET", "theindex.html", false);
+    request.open("GET", "http://nim-lang.org/0.15.0/theindex.html", false);
     request.send(null);
 
     var doc = document.implementation.createHTMLDocument("theindex");
@@ -259,16 +259,22 @@ proc dosearch(value: cstring): Element =
   let ul = tree("UL")
   result = tree("DIV")
   result.setClass"search_results"
-  var matches = 0
+  var matches: seq[(Element, int)] = @[]
   let key = value.normalize
   for i in 0..<db.len:
-    if containsWord(key, contents[i]):
-      ul.add(tree("LI", db[i]))
-      inc matches
-      if matches > 10: break
+    let c = contents[i]
+    if c.containsWord(key):
+      matches.add((db[i], -(30_000 - c.len)))
+    elif c.contains(key):
+      matches.add((db[i], c.len))
+  matches.sort do (a, b: auto) -> int:
+    a[1] - b[1]
+  for i in 0..min(<matches.len, 19):
+    ul.add(tree("LI", matches[i][0]))
   if ul.len == 0:
-    result.add text"no search results"
+    result.add tree("B", text"no search results")
   else:
+    result.add tree("B", text"search results")
     result.add ul
 
 var oldtoc: Element
href='#n208'>208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283