Skip to content

Commit

Permalink
Rename search ==> multi-word
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull authored and Richard Hull committed Mar 26, 2016
1 parent 3690ac0 commit fae0b8b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ and can be downloaded and started with:

## Example API usage

From a Clojure REPL:
### Multi-word anagrams

Using all the letters to find multi-word anagrams, from a Clojure REPL:

```clojure
(use 'ars-magna.dict)
Expand All @@ -44,14 +46,14 @@ From a Clojure REPL:
(let [dict (load-word-list :en-GB)
index (partition-by-word-length dict)]
(sort
(search index "compute" 3 nil)))
(multi-word index "compute" 3 nil)))
; ("come put" "compute" "cote ump" "cut mope" "cut poem"
; "cute mop" "met coup" "mote cup" "mute cop" "tome cup")
```

or querying the web service for the word 'compute':

$ curl -s http://localhost:3000/search/compute | jq .
$ curl -s http://localhost:3000/multi-word/compute | jq .

returns the same anagrams:

Expand Down
4 changes: 2 additions & 2 deletions src/ars_magna/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
(defroutes app-routes
(let [dict (load-word-list :en-GB)
index (partition-by-word-length dict)]
(GET "/search/:word" [word :as req]
(GET "/multi-word" [word :as req]
(json-exception-handler
(to-json identity
(let [min-size (Integer/parseInt (or (get-in req [:params :min]) "3"))]
(sort
(search index (clean word) min-size nil))))))))
(multi-word index (clean word) min-size nil))))))))

(def app
(->
Expand Down
4 changes: 2 additions & 2 deletions src/ars_magna/solver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
[clojure.string :as s]
[ars-magna.dict :refer :all]))

(defn search [index word min-size prefix]
(defn multi-word [index word min-size prefix]
(if (empty? word)
(s/trim prefix)
(flatten
(for [w (find-in index word min-size :en-GB)]
(search
(multi-word
index
(remaining-chars word w)
min-size
Expand Down
2 changes: 1 addition & 1 deletion test/ars_magna/solver_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
(deftest check-solver
(let [dict (load-word-list :en-GB)
index (partition-by-word-length dict)]
(is (= (sort (search index "compute" 3 nil))
(is (= (sort (multi-word index "compute" 3 nil))
["come put" "compute" "cote ump" "cut mope" "cut poem"
"cute mop" "met coup" "mote cup" "mute cop" "tome cup"]))))

0 comments on commit fae0b8b

Please sign in to comment.