Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Supply default analyzer.

  • Loading branch information...
commit 4904f3f35c62d74db557afd5a32d81fdfe688b5c 1 parent 015d61f
Drew Raines drewr authored

Showing 2 changed files with 18 additions and 17 deletions. Show diff stats Hide diff stats

  1. +16 9 src/esperanto/lucene.clj
  2. +2 8 test/esperanto/test/lucene.clj
25 src/esperanto/lucene.clj
... ... @@ -1,10 +1,12 @@
1 1 (ns esperanto.lucene
2 2 (:import (java.io StringReader)
  3 + (org.apache.lucene.analysis.standard StandardAnalyzer)
3 4 (org.apache.lucene.analysis.tokenattributes TermAttribute)
4 5 (org.apache.lucene.document Document Field
5 6 Field$Store Field$Index)
6 7 (org.apache.lucene.index IndexWriter IndexWriter$MaxFieldLength
7   - Term)))
  8 + Term)
  9 + (org.apache.lucene.util Version)))
8 10
9 11 (defn index [writer fields]
10 12 (let [doc (Document.)]
@@ -20,12 +22,17 @@
20 22 (recur st (conj! v (.term term)))
21 23 (persistent! v)))))
22 24
23   -(defn token-seq [analyzer rdr]
24   - (let [stream (.tokenStream analyzer "field" rdr)
25   - term (.addAttribute stream TermAttribute)
26   - step (fn step [st v]
27   - (lazy-seq
28   - (when (.incrementToken st)
29   - (cons (.term term) (step st v)))))]
30   - (step stream [])))
  25 +(defn token-seq
  26 + ([rdr]
  27 + (token-seq (StandardAnalyzer. Version/LUCENE_CURRENT) rdr))
  28 + ([analyzer rdr]
  29 + (let [stream (.tokenStream analyzer "field" rdr)
  30 + term (.addAttribute stream TermAttribute)
  31 + step (fn step [st v]
  32 + (lazy-seq
  33 + (when (.incrementToken st)
  34 + (cons (.term term) (step st v)))))]
  35 + (step stream []))))
  36 +
  37 +
31 38
10 test/esperanto/test/lucene.clj
... ... @@ -1,9 +1,7 @@
1 1 (ns esperanto.test.lucene
2 2 (:use [esperanto.lucene] :reload)
3 3 (:use [clojure.test])
4   - (:import (java.io File StringReader)
5   - (org.apache.lucene.analysis.standard StandardAnalyzer)
6   - (org.apache.lucene.util Version)))
  4 + (:import (java.io File StringReader)))
7 5
8 6 (def ^:dynamic *dir* nil)
9 7
@@ -25,8 +23,4 @@
25 23 (deftest t-analyze
26 24 (let [tokens ["quick" "brown" "fox"
27 25 "jumps" "over" "lazy" "dog"]]
28   - (is (= tokens (analyze
29   - (StandardAnalyzer. Version/LUCENE_31) text)))
30   - (is (= tokens (token-seq
31   - (StandardAnalyzer. Version/LUCENE_31)
32   - (StringReader. text))))))
  26 + (is (= tokens (token-seq (StringReader. text))))))

0 comments on commit 4904f3f

Please sign in to comment.
Something went wrong with that request. Please try again.