-
Notifications
You must be signed in to change notification settings - Fork 5
/
dev.clj
60 lines (52 loc) · 2.89 KB
/
dev.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;; [[file:../README.org::*Preamble][Preamble:1]]
(ns dev
(:require [msync.lucene :as lucene]
[msync.lucene
[document :as ld]
[tests-common :as common]]))
;; Preamble:1 ends here
;; [[file:../README.org::*Create an index][Create an index:1]]
(defonce album-index (lucene/create-index! :type :memory
:analyzer common/album-data-analyzer))
;; Create an index:1 ends here
;; [[file:../README.org::*Index documents][Index documents:1]]
(lucene/index! album-index common/album-data
{:stored-fields [:Number :Year :Album :Artist :Genre :Subgenre]
:suggest-fields [:Album :Artist]
:context-fn :Genre})
;; Index documents:1 ends here
;; [[file:../README.org::*Now, we can search][Now, we can search:1]]
(clojure.pprint/pprint (do (lucene/search album-index {:Year "1977"}
{:results-per-page 2})))
;; Now, we can search:1 ends here
;; [[file:../README.org::*Now, we can search][Now, we can search:3]]
(clojure.pprint/pprint (do (lucene/search album-index {:Year "1977"}
{:results-per-page 2
:hit->doc ld/document->map})))
;; Now, we can search:3 ends here
;; [[file:../README.org::*Now, we can search][Now, we can search:5]]
(clojure.pprint/pprint (do (lucene/search album-index
{:Year "1977"}
{:results-per-page 2
:hit->doc #(ld/document->map % :multi-fields [:Genre :Subgenre])})))
;; Now, we can search:5 ends here
;; [[file:../README.org::*Now, we can search][Now, we can search:7]]
(clojure.pprint/pprint (do (lucene/search album-index
{:Year "1968"} ;; Map of field-values to search with
{:results-per-page 5 ;; Control the number of results returned
:page 2 ;; Page number, starting 0 as default
:hit->doc #(-> %
ld/document->map
(select-keys [:Year :Album]))})))
;; Now, we can search:7 ends here
;; [[file:../README.org::*Suggestions support for fields passed via ~:suggest-fields~][Suggestions support for fields passed via ~:suggest-fields~:1]]
(clojure.pprint/pprint (do (lucene/suggest album-index :Album "par"
{:hit->doc #(ld/document->map % :multi-fields [:Genre :Subgenre])
:contexts ["Electronic"]})))
;; Suggestions support for fields passed via ~:suggest-fields~:1 ends here
;; [[file:../README.org::*Suggestions support for fields passed via ~:suggest-fields~][Suggestions support for fields passed via ~:suggest-fields~:3]]
(clojure.pprint/pprint (do (lucene/suggest album-index :Album "per"
{:hit->doc #(ld/document->map % :multi-fields [:Genre :Subgenre])
:fuzzy? true
:contexts ["Electronic"]})))
;; Suggestions support for fields passed via ~:suggest-fields~:3 ends here