Permalink
Browse files

Fixed search

  • Loading branch information...
1 parent 0b3e085 commit 5dca30909c8e7d39b37b4bb09fb1190f26ad9cd9 @vsedach committed Nov 16, 2011
Showing with 47 additions and 52 deletions.
  1. +0 −2 TODO
  2. +1 −1 src/html-rendering.lisp
  3. +1 −1 src/readtable.lisp
  4. +34 −38 src/search.lisp
  5. +11 −10 static/css/style.css
View
@@ -1,3 +1 @@
* user and IP blacklists
-* allow anonymous edits
-* allow users to change their email
@@ -46,7 +46,7 @@
</ul>
<div id="search">
<form action="$(#/site/search)">
- <input type="text" name="query" value="${(or (hunchentoot:get-parameter "query") "")}" />
+ <input type="text" name="query" value="${(or (get-parameter "query") "")}" />
<input type="submit" value="search" />
</form>
</div>
View
@@ -6,7 +6,7 @@
(defvar *html-stream* *standard-output*)
(defreadtable cliki2
- (:merge :standard)
+ (:merge :standard uri-template:uri-template)
(:case :invert)
(:dispatch-macro-char
#\# #\?
View
@@ -1,7 +1,7 @@
(in-package #:cliki2)
(in-readtable cliki2)
-(defparameter *search-index* nil)
+(defvar *search-index* nil)
(defun close-search-index ()
(when *search-index*
@@ -22,49 +22,45 @@
(montezuma:update *search-index* id index-data)
(montezuma:add-document-to-index *search-index* index-data))))
-(defun search-articles (query start &key (page-size 10))
- (let ((revisionables ()))
- (montezuma:each
- (montezuma:search *search-index*
- (format nil "content:\"~A\"" (remove #\" query))
- :num-docs page-size
- :first-doc start)
+(defun search-articles (query start page-size)
+ (let ((revisionables ())
+ (documents (montezuma:search
+ *search-index*
+ (format nil "content:\"~A\"" (remove #\" query))
+ :num-docs page-size
+ :first-doc start)))
+ (montezuma:each ;; montezuma sucks goat dick
+ documents
(lambda (doc)
(push (store-object-with-id
(parse-integer
(montezuma:document-value
(montezuma:get-document *search-index* (montezuma:doc doc))
"id")))
revisionables)))
- (reverse revisionables)))
+ (values (reverse revisionables) (montezuma::total-hits documents))))
-(defpage /site/search "CLiki: Search results" (query index)
- (let* ((start (or (parse-integer index :junk-allowed t) 0))
- (articles (search-articles query start)))
- #H[<h1>Search results</h1>]
- (if articles
- (progn
- #H[<ol start="${(1+ start)}">]
- (dolist (article articles)
- #H[<li><a href="/${(title article)}">${(title article)}</a>
- <div>${(article-description article)}</div>
- </li>])
- #H[</ol>
-
- <div id="paginator">
- <span>Result page:</span>
- <ul>
- {for $p in range( ceiling( $total / $pageSize))}
- <li>
- {if $p*$pageSize == $start}
- {$p + 1}
- {else}
- <a href="?query={$query |escapeUri}&start={$p*$pageSize |escapeUri}">{$p + 1}</a>
- {/if}
- </li>
- {/for}
- </ul>
- <div class="clear"></div>
- </div>])
- #H[No results found])))
+(defpage /site/search "CLiki: Search results" (query start)
+ (let ((page-size 10)
+ (start (or (parse-integer (or start "0") :junk-allowed t) 0)))
+ (multiple-value-bind (articles total)
+ (search-articles query start page-size)
+ #H[<h1>Search results</h1>]
+ (if articles
+ (progn
+ #H[<ol start="${(1+ start)}">]
+ (dolist (article articles)
+ #H[<li>] (pprint-article-link (title article))
+ #H[<div>${(article-description article)}</div></li>])
+ #H[</ol>
+ <div id="paginator">
+ <span>Result page:</span>
+ <ul>]
+ (dotimes (p (ceiling total page-size))
+ #H[<li>]
+ (if (= start (* p page-size))
+ #H[${(1+ p)}]
+ #H[<a href="$(#U?query={query}&start={(* p page-size)})">${(1+ p)}</a></li>]))
+ #H[</ul></div>])
+ #H[No results found]))))
View
@@ -152,31 +152,34 @@
margin-right: 20px;
}
-#search input {margin:0;padding:0 10px;}
#search input[type=text] {border:none;background:white;color:black;width:208px;height: 23px;line-height:23px;float:left;}
#search input[type=submit] {border:none;background:#175487;width: 65px; height: 23px;line-height:23px;color:white;cursor:pointer;}
#search input[type=submit]:hover { background: #256aa3 ; }
#paginator {
- padding: 16px;
- margin: 20px 0;
color: #333;
background: #eee;
+ margin-top:20px;
+ height:36px;
}
-#paginator span {float:left;font-style:oblique;}
+#paginator span {
+ float:left;
+ font-style:oblique;
+ line-height:36px;
+ margin-right:12px;
+}
#paginator ul {
list-style: none;
list-style-position: outside;
- margin-left: 105px;
}
#paginator ul li {
- margin: 0 !important;
- display: block;
+ margin: 0;
float: left;
- width: 36px;
+ line-height:36px;
+ padding: 0 12px;
}
#content {
@@ -223,8 +226,6 @@
margin-top: 20px;
}
-.clear {clear:both;}
-
pre, pre *, .code, .code * { font-family: monospace; }
#pagehistory {

0 comments on commit 5dca309

Please sign in to comment.