Mercurial Hosting > luan
comparison lucene/src/luan/modules/lucene/LuceneSearcher.java @ 257:c5c60eca33dd
allow Lucene search for 0 rows
git-svn-id: https://luan-java.googlecode.com/svn/trunk@258 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 28 Oct 2014 03:05:37 +0000 |
parents | b25feac318d8 |
children | 8afe9f2fdfec |
comparison
equal
deleted
inserted
replaced
256:15122d724ce4 | 257:c5c60eca33dd |
---|---|
14 import org.apache.lucene.search.SortField; | 14 import org.apache.lucene.search.SortField; |
15 import org.apache.lucene.search.ScoreDoc; | 15 import org.apache.lucene.search.ScoreDoc; |
16 import org.apache.lucene.search.TermQuery; | 16 import org.apache.lucene.search.TermQuery; |
17 import org.apache.lucene.search.BooleanQuery; | 17 import org.apache.lucene.search.BooleanQuery; |
18 import org.apache.lucene.search.BooleanClause; | 18 import org.apache.lucene.search.BooleanClause; |
19 import org.apache.lucene.search.TotalHitCountCollector; | |
19 import luan.Luan; | 20 import luan.Luan; |
20 import luan.LuanState; | 21 import luan.LuanState; |
21 import luan.LuanTable; | 22 import luan.LuanTable; |
22 import luan.LuanFunction; | 23 import luan.LuanFunction; |
23 import luan.LuanJavaFunction; | 24 import luan.LuanJavaFunction; |
157 flds[i] = sortField(luan,fldTbl.asList()," at position "+(i+1)); | 158 flds[i] = sortField(luan,fldTbl.asList()," at position "+(i+1)); |
158 } | 159 } |
159 return new Sort(flds); | 160 return new Sort(flds); |
160 } | 161 } |
161 | 162 |
163 private static final LuanFunction nothingFn = new LuanFunction() { | |
164 @Override public Object call(LuanState luan,Object[] args) { | |
165 return LuanFunction.NOTHING; | |
166 } | |
167 }; | |
168 | |
162 public Object[] search( LuanState luan, LuanTable queryTbl, int n, LuanTable sortTbl ) throws LuanException, IOException { | 169 public Object[] search( LuanState luan, LuanTable queryTbl, int n, LuanTable sortTbl ) throws LuanException, IOException { |
163 Query query = query(queryTbl); | 170 Query query = query(queryTbl); |
164 if( query == null ) | 171 if( query == null ) |
165 throw luan.exception("invalid query"); | 172 throw luan.exception("invalid query"); |
173 if( n==0 ) { | |
174 TotalHitCountCollector thcc = new TotalHitCountCollector(); | |
175 searcher.search(query,thcc); | |
176 return new Object[]{ nothingFn, 0, thcc.getTotalHits() }; | |
177 } | |
166 TopDocs td = sortTbl==null ? searcher.search(query,n) : searcher.search(query,n,sort(luan,sortTbl)); | 178 TopDocs td = sortTbl==null ? searcher.search(query,n) : searcher.search(query,n,sort(luan,sortTbl)); |
167 final ScoreDoc[] scoreDocs = td.scoreDocs; | 179 final ScoreDoc[] scoreDocs = td.scoreDocs; |
168 LuanFunction results = new LuanFunction() { | 180 LuanFunction results = new LuanFunction() { |
169 int i = 0; | 181 int i = 0; |
170 | 182 |