Browse files

Redoing core.

  • Loading branch information...
1 parent 524da73 commit 19c6ce906f5470108b960fea86556f70f72d764a @rdrake committed Mar 26, 2012
Showing with 35 additions and 50 deletions.
  1. +16 −40 src/molly/core.clj
  2. +5 −3 src/molly/datatypes/entity.clj
  3. +5 −5 src/molly/search/query_builder.clj
  4. +9 −2 src/molly/server/serve.clj
View
56 src/molly/core.clj
@@ -1,51 +1,27 @@
(ns molly.core
(:gen-class)
- (:use molly.server.serve))
+ (:use molly.server.serve
+ molly.index.build
+ molly.search.lucene
+ molly.search.query-builder
+ [clojure.tools.cli :only (cli)]))
-(defn -main
- [& args]
- (println "Starting Molly...")
- (start!))
-
- ;(:use molly.datatypes.entity
- ; molly.index.build
- ; molly.search.lucene
- ; molly.search.query-builder
- ; [clojure.tools.cli :only (cli)]))
-
-(comment
(defn parse-args
[args]
(cli args
+ ["-a" "--action" "Action to perform [serve|index]"]
["-d" "--database" "Database location."]
["-i" "--index" "Index location."]))
-(defn main
- [args]
- (let [[opts arguments banner] (parse-args args)
- database (opts :database)
- index (opts :index)]
- (build database index)))
-
-(defn -main
- [& args]
- (main (flatten args)))
-)
-(comment
(defn -main
[& args]
- (let [path (idx-path "mycampus.idx")
- searcher (idx-searcher path)
- q1 (query :type :entity)
- q2 (query :class :courses)
- ;q3 (query :code "csci")
- q4 (query :code "3030u")
- bq (boolean-query
- [q1 :and]
- [q2 :and]
- ;[q3 :and]
- [q4 :and])
- results (map doc->data (idx-search searcher bq))]
- (doseq [result results]
- (doseq [[K V] result]
- (println (str (name K) ": " V)))))))
+ (println "args")
+ (let [[opts arguments banner] (parse-args (flatten args))
+ action (opts :action)]
+ (println "if")
+ (if (= action "serve")
+ ((println "Starting Molly...")
+ (start!))
+ (let [database (opts :database)
+ index (opts :index)]
+ (build database index)))))
View
8 src/molly/datatypes/entity.clj
@@ -40,7 +40,9 @@
(select-keys this attr-cols))
meta-data {:type T :class C}
id-col (schema :ID)]
- (with-meta attrs
+ (with-meta (if (= T :group)
+ (conj attrs {:entities (uid this id-col)})
+ attrs)
(condp = T
:value (assoc meta-data
:class
@@ -49,7 +51,7 @@
[C
(first attr-cols)])))
:entity (assoc meta-data :id (uid this C id-col))
- :group (assoc meta-data :entities (uid this id-col))
+ :group meta-data
(throw (IllegalArgumentException. "I only know how to deal with types :value, :entity, and :group"))))))
(defn doc->data
@@ -81,5 +83,5 @@
(condp = (int-meta :type)
:value []
:entity [[:__id__ (int-meta :id)]]
- :group [[:__entities__ (int-meta :entities)]]))]
+ :group [[:entities (int-meta :entities)]]))]
(document raw-doc)))
View
10 src/molly/search/query_builder.clj
@@ -6,11 +6,11 @@
(defn query
[kind & args]
- (let [field-name (condp = kind
- :type "__type__"
- :class "__class__"
- :id "__ID__"
- :text "__all__"
+ (let [field-name (condp = kind
+ :type "__type__"
+ :class "__class__"
+ :id "__ID__"
+ :text "__all__"
; Assume "kind" is an attribute name.
(condp = (type kind)
clojure.lang.Keyword (name kind)
View
11 src/molly/server/serve.clj
@@ -10,11 +10,11 @@
(def searcher (idx-searcher (idx-path "mycampus.idx")))
(defn dox
- [q1 S]
+ [q1 field S]
(let [bq (boolean-query
(concat [[q1 :and]]
(for [s S]
- [(query :text s) :or])))]
+ [(query field s) :or])))]
(map doc->data (idx-search searcher bq))))
(defpage "/" []
@@ -23,13 +23,20 @@
(defpage "/suggest/:q" {:keys [q]}
(response/json
(dox (query :type :value)
+ :text
(clojure.string/split (q-gram q) #"\s{1}"))))
(defpage "/entity/:q" {:keys [q]}
(response/json
(dox (query :type :entity)
+ :text
(clojure.string/split q #"\s{1}"))))
+(defpage "/group/:q" {:keys [q]}
+ (println q)
+ (response/json
+ (dox (query :type :group) :entity [q])))
+
(defn start!
[]
(server/start 8080))

0 comments on commit 19c6ce9

Please sign in to comment.