aboutsummaryrefslogtreecommitdiff
path: root/sx-search.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-02-26 23:02:20 -0300
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-02-26 23:02:20 -0300
commitbe15643b64b64e5fcbcdc213c90a5fa9cd41e9df (patch)
treec0ad93572654e164ffe3b0ca90c6a80e1ac4c96e /sx-search.el
parenta746338150587a400a0fc09a7607341ac10a5159 (diff)
parentcd72f5f03dcc3490318920ef95fc09b07ae900da (diff)
Merge branch 'master' into handle-html-tags
Diffstat (limited to 'sx-search.el')
-rw-r--r--sx-search.el36
1 files changed, 28 insertions, 8 deletions
diff --git a/sx-search.el b/sx-search.el
index c22a554..b245cbe 100644
--- a/sx-search.el
+++ b/sx-search.el
@@ -40,7 +40,9 @@
;;; Basic function
-(defun sx-search-get-questions (site page query &optional tags excluded-tags keywords)
+(defun sx-search-get-questions (site page query
+ &optional tags excluded-tags
+ &rest keywords)
"Like `sx-question-get-questions', but restrict results by a search.
Perform search on SITE. PAGE is an integer indicating which page
@@ -53,7 +55,6 @@ fail. EXCLUDED-TAGS is only is used if TAGS is also provided.
KEYWORDS is passed to `sx-method-call'."
(sx-method-call 'search
:keywords `((page . ,page)
- (sort . activity)
(intitle . ,query)
(tagged . ,tags)
(nottagged . ,excluded-tags)
@@ -62,8 +63,18 @@ KEYWORDS is passed to `sx-method-call'."
:auth t
:filter sx-browse-filter))
+(defconst sx-search--order-methods
+ (cons '("Relevance" . relevance)
+ (cl-remove-if (lambda (x) (eq (cdr x) 'hot))
+ (default-value 'sx-question-list--order-methods)))
+ "Alist of possible values to be passed to the `sort' keyword.")
+
+(defvar sx-search-default-order 'activity
+ "Default ordering method used on new searches.
+Possible values are the cdrs of `sx-search--order-methods'.")
+
-;;; User command
+;;;###autoload
(defun sx-search (site query &optional tags excluded-tags)
"Display search on SITE for question titles containing QUERY.
When TAGS is given, it is a lists of tags, one of which must
@@ -85,7 +96,7 @@ prefix argument, the user is asked for everything."
(when current-prefix-arg
(setq tags (sx-tag-multiple-read
site (concat "Tags" (when query " (optional)"))))
- (when (and (not query) (string= "" tags))
+ (unless (or query tags)
(sx-user-error "Must supply either QUERY or TAGS"))
(setq excluded-tags
(sx-tag-multiple-read site "Excluded tags (optional)")))
@@ -99,8 +110,11 @@ prefix argument, the user is asked for everything."
(lambda (page)
(sx-search-get-questions
sx-question-list--site page
- query tags excluded-tags)))
+ query tags excluded-tags
+ (cons 'sort sx-question-list--order))))
(setq sx-question-list--site site)
+ (setq sx-question-list--order sx-search-default-order)
+ (setq sx-question-list--order-methods sx-search--order-methods)
(sx-question-list-refresh 'redisplay)
(switch-to-buffer (current-buffer))))
@@ -112,9 +126,15 @@ prefix argument, the user is asked for everything."
(let ((tag (save-excursion
(when pos (goto-char pos))
(or (get-text-property (point) 'sx-tag)
- (thing-at-point 'symbol)))))
- (sx-search (or sx-question-list--site
- (sx-assoc-let sx-question-mode--data .site_par))
+ (thing-at-point 'symbol))))
+ (meta (save-excursion
+ (when pos (goto-char pos))
+ (get-text-property (point) 'sx-tag-meta)))
+ (site (replace-regexp-in-string
+ (rx string-start "meta.") ""
+ (or sx-question-list--site
+ (sx-assoc-let sx-question-mode--data .site_par)))))
+ (sx-search (concat (when meta "meta.") site)
nil tag)))
(provide 'sx-search)