aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid 'arrdem' McKenzie <reid@factual.com>2015-08-12 19:20:55 -0700
committerReid 'arrdem' McKenzie <reid@factual.com>2015-08-12 19:20:55 -0700
commit18da2d6fd124d4666353796c840359b581ae5153 (patch)
treee5782e35aaa5415c22debd4c7174a58cdb9e01f0
parent3534b2334f71c86a48fd79149bb7a8af50c24dc7 (diff)
downloadclucy-18da2d6fd124d4666353796c840359b581ae5153.tar.gz
clucy-18da2d6fd124d4666353796c840359b581ae5153.tar.xz
clucy-18da2d6fd124d4666353796c840359b581ae5153.zip
Fixup the count of :all to be unbounded
-rw-r--r--src/clucy/core.clj59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/clucy/core.clj b/src/clucy/core.clj
index 9dd831b..6c6a394 100644
--- a/src/clucy/core.clj
+++ b/src/clucy/core.clj
@@ -192,32 +192,45 @@ fragments."
"Search the supplied index with a query string."
[index query max-results
& {:keys [highlight default-field default-operator page results-per-page]
- :or {page 0 results-per-page max-results}}]
+ :or {page 0}}]
(if (every? false? [default-field *content*])
(throw (Exception. "No default search field specified"))
(with-open [reader (index-reader index)]
- (let [default-field (or default-field :_content)
- searcher (IndexSearcher. reader)
- parser (doto (QueryParser. *version*
- (as-str default-field)
- *analyzer*)
- (.setDefaultOperator
- (case (or default-operator :or)
- :and
- ,,QueryParser/AND_OPERATOR
-
- :or
- ,,QueryParser/OR_OPERATOR)))
- query (if (= query :all)
- (MatchAllDocsQuery.)
- (.parse parser query))
- hits (if (= max-results :all)
- (.search searcher query)
- (.search searcher query (int max-results)))
- highlighter (make-highlighter query searcher highlight)
- start (* page results-per-page)
- end (min (+ start results-per-page)
- (.totalHits hits))]
+ (let [default-field (or default-field :_content)
+
+ searcher (IndexSearcher. reader)
+
+ parser (doto (QueryParser. *version*
+ (as-str default-field)
+ *analyzer*)
+ (.setDefaultOperator
+ (case (or default-operator :or)
+ :and
+ ,,QueryParser/AND_OPERATOR
+
+ :or
+ ,,QueryParser/OR_OPERATOR)))
+
+ max-results (if (= query :all)
+ Integer/MAX_VALUE
+ max-results)
+
+ results-per-page (or results-per-page max-results)
+
+ query (if (= query :all)
+ (MatchAllDocsQuery.)
+ (.parse parser query))
+
+ _ (println max-results query)
+
+ hits (.search searcher query (int max-results))
+
+ highlighter (make-highlighter query searcher highlight)
+
+ start (* page results-per-page)
+
+ end (min (+ start results-per-page)
+ (.totalHits hits))]
(doall
(with-meta
(for [hit (map (partial aget (.scoreDocs hits))