Mercurial Hosting > luan
comparison src/luan/modules/lucene/LuceneIndex.java @ 1459:b04b8fc5f4f4
GoodQueryParser
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 20 Mar 2020 11:06:53 -0600 |
parents | 6b6c11c9164e |
children | 13cbce740e1e |
comparison
equal
deleted
inserted
replaced
1458:6b6c11c9164e | 1459:b04b8fc5f4f4 |
---|---|
66 import org.apache.lucene.search.highlight.Fragmenter; | 66 import org.apache.lucene.search.highlight.Fragmenter; |
67 import org.apache.lucene.search.highlight.NullFragmenter; | 67 import org.apache.lucene.search.highlight.NullFragmenter; |
68 import org.apache.lucene.search.highlight.SimpleSpanFragmenter; | 68 import org.apache.lucene.search.highlight.SimpleSpanFragmenter; |
69 import org.apache.lucene.search.highlight.QueryScorer; | 69 import org.apache.lucene.search.highlight.QueryScorer; |
70 import org.apache.lucene.search.highlight.TokenGroup; | 70 import org.apache.lucene.search.highlight.TokenGroup; |
71 import goodjava.lucene.queryparser.SaneQueryParser; | 71 import goodjava.lucene.queryparser.GoodQueryParser; |
72 import goodjava.lucene.queryparser.FieldParser; | 72 import goodjava.lucene.queryparser.FieldParser; |
73 import goodjava.lucene.queryparser.MultiFieldParser; | 73 import goodjava.lucene.queryparser.MultiFieldParser; |
74 import goodjava.lucene.queryparser.StringFieldParser; | 74 import goodjava.lucene.queryparser.StringFieldParser; |
75 import goodjava.lucene.queryparser.NumberFieldParser; | 75 import goodjava.lucene.queryparser.NumberFieldParser; |
76 import goodjava.parser.ParseException; | 76 import goodjava.parser.ParseException; |
245 } | 245 } |
246 | 246 |
247 public void delete(String queryStr) | 247 public void delete(String queryStr) |
248 throws IOException, ParseException, SQLException, LuanException | 248 throws IOException, ParseException, SQLException, LuanException |
249 { | 249 { |
250 Query query = SaneQueryParser.parseQuery(mfp,queryStr); | 250 Query query = GoodQueryParser.parseQuery(mfp,queryStr); |
251 | 251 |
252 boolean commit = !writeLock.isHeldByCurrentThread(); | 252 boolean commit = !writeLock.isHeldByCurrentThread(); |
253 writeLock.lock(); | 253 writeLock.lock(); |
254 try { | 254 try { |
255 backupDelete(query); | 255 backupDelete(query); |
509 | 509 |
510 public int advanced_search( String queryStr, LuanFunction fn, Integer n, String sortStr ) | 510 public int advanced_search( String queryStr, LuanFunction fn, Integer n, String sortStr ) |
511 throws LuanException, IOException, ParseException | 511 throws LuanException, IOException, ParseException |
512 { | 512 { |
513 Utils.checkNotNull(queryStr); | 513 Utils.checkNotNull(queryStr); |
514 Query query = SaneQueryParser.parseQuery(mfp,queryStr); | 514 Query query = GoodQueryParser.parseQuery(mfp,queryStr); |
515 IndexSearcher searcher = threadLocalSearcher.get(); | 515 IndexSearcher searcher = threadLocalSearcher.get(); |
516 boolean inTransaction = searcher != null; | 516 boolean inTransaction = searcher != null; |
517 if( !inTransaction ) | 517 if( !inTransaction ) |
518 searcher = openSearcher(); | 518 searcher = openSearcher(); |
519 try { | 519 try { |
541 if( fn==null || n==0 ) { | 541 if( fn==null || n==0 ) { |
542 TotalHitCountCollector thcc = new TotalHitCountCollector(); | 542 TotalHitCountCollector thcc = new TotalHitCountCollector(); |
543 searcher.search(query,thcc); | 543 searcher.search(query,thcc); |
544 return thcc.getTotalHits(); | 544 return thcc.getTotalHits(); |
545 } | 545 } |
546 Sort sort = sortStr==null ? null : SaneQueryParser.parseSort(mfp,sortStr); | 546 Sort sort = sortStr==null ? null : GoodQueryParser.parseSort(mfp,sortStr); |
547 TopDocs td = sort==null ? searcher.search(query,n) : searcher.search(query,n,sort); | 547 TopDocs td = sort==null ? searcher.search(query,n) : searcher.search(query,n,sort); |
548 final ScoreDoc[] scoreDocs = td.scoreDocs; | 548 final ScoreDoc[] scoreDocs = td.scoreDocs; |
549 DocFn docFn = new DocFn(fn.luan(),searcher,query); | 549 DocFn docFn = new DocFn(fn.luan(),searcher,query); |
550 for( int i=0; i<scoreDocs.length; i++ ) { | 550 for( int i=0; i<scoreDocs.length; i++ ) { |
551 ScoreDoc scoreDoc = scoreDocs[i]; | 551 ScoreDoc scoreDoc = scoreDocs[i]; |
727 }; | 727 }; |
728 | 728 |
729 public LuanFunction highlighter(String queryStr,final LuanFunction formatter,final Integer fragmentSize,String dotdotdot) | 729 public LuanFunction highlighter(String queryStr,final LuanFunction formatter,final Integer fragmentSize,String dotdotdot) |
730 throws ParseException | 730 throws ParseException |
731 { | 731 { |
732 Query query = SaneQueryParser.parseQuery(mfp,queryStr); | 732 Query query = GoodQueryParser.parseQuery(mfp,queryStr); |
733 Formatter fmt = new Formatter() { | 733 Formatter fmt = new Formatter() { |
734 public String highlightTerm(String originalText,TokenGroup tokenGroup) { | 734 public String highlightTerm(String originalText,TokenGroup tokenGroup) { |
735 if( tokenGroup.getTotalScore() <= 0 ) | 735 if( tokenGroup.getTotalScore() <= 0 ) |
736 return originalText; | 736 return originalText; |
737 try { | 737 try { |