From 7a5f0cd40a0a4400a82b64d1f5be5a33c6f5ed0c Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Tue, 7 Jun 2011 01:06:28 +0530 Subject: [PATCH] Upgraded lucene version. Made changes for the results to take message time into consideration. --- .gitignore | 2 +- project.clj | 6 +++--- src/irc_search_bot/lucene.clj | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 268d6ae..5e42a14 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ pom.xml /classes/ .lein-deps-sum ignored_users -/index/ +/index*/ diff --git a/project.clj b/project.clj index 04c4828..9d93878 100644 --- a/project.clj +++ b/project.clj @@ -6,7 +6,7 @@ :releases false}} :dependencies [[org.clojure/clojure "1.2.1"] [org.clojure/clojure-contrib "1.2.0"] - [org.apache.lucene/lucene-core "3.1.0"] - [org.apache.lucene/lucene-wordnet "3.1.0"] - [org.apache.lucene/lucene-analyzers "3.1.0"] + [org.apache.lucene/lucene-core "3.2.0"] + [org.apache.lucene/lucene-wordnet "3.2.0"] + [org.apache.lucene/lucene-analyzers "3.2.0"] [org/pircbotx "1.3-SNAPSHOT"]]) diff --git a/src/irc_search_bot/lucene.clj b/src/irc_search_bot/lucene.clj index b01acfd..dd9d404 100644 --- a/src/irc_search_bot/lucene.clj +++ b/src/irc_search_bot/lucene.clj @@ -7,7 +7,7 @@ [org.apache.lucene.index IndexWriter IndexWriterConfig IndexReader] [org.apache.lucene.search IndexSearcher ScoreDoc Query BooleanQuery TermQuery BooleanClause - BooleanClause$Occur Filter QueryWrapperFilter] + BooleanClause$Occur Filter QueryWrapperFilter Sort SortField] [org.apache.lucene.queryParser QueryParser] [org.apache.lucene.wordnet AnalyzerUtil]) (:use [clojure.java.io :only (as-file)])) @@ -46,7 +46,15 @@ [query, nil])) (defn search [^IndexSearcher index-searcher ^Query query ^Filter filter ^Integer max-hits] - (let [top-docs (.search index-searcher query filter max-hits)] + (let [top-docs + (.search + index-searcher + query + filter + max-hits + (Sort. + (into-array + [SortField/FIELD_SCORE (SortField. "timestamp" SortField/LONG true)])))] (vector (.totalHits top-docs) (->> @@ -98,7 +106,7 @@ (defn add-document [^IndexWriter index-writer document] (.addDocument index-writer document)) - + (defn standard-analyzer [] (StandardAnalyzer. *lucene-version*))