Changeset 24724

Show
Ignore:
Timestamp:
05.10.2011 15:38:30 (8 years ago)
Author:
davidb
Message:

Changes necessary to make LuceneSearch? work with Lucene version 3.3

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/LuceneSearch.java

    r24722 r24724  
    1717import org.apache.lucene.search.Searcher; 
    1818import org.apache.lucene.search.IndexSearcher; 
     19import org.apache.lucene.index.IndexReader; 
    1920import org.apache.lucene.search.Query; 
    20 import org.apache.lucene.search.Hits; 
    2121import org.apache.lucene.queryParser.QueryParser; 
     22//import org.apache.lucene.search.Hits; 
    2223import org.apache.lucene.search.TermQuery; 
     24import org.apache.lucene.search.TopDocs; 
    2325import org.apache.lucene.index.Term; 
    24  
     26import org.apache.lucene.store.FSDirectory; 
     27import org.apache.lucene.store.Directory; 
     28 
     29import org.greenstone.LuceneWrapper.GS2Analyzer; 
    2530import java.io.File; 
    2631 
     
    171176        String index_dir = GSFile.collectionIndexDir(this.site_home, this.cluster_name); 
    172177        index_dir += File.separator+index; 
    173         Searcher searcher = new IndexSearcher(index_dir); 
    174         Analyzer analyzer = new StandardAnalyzer(); 
     178        Directory index_dir_dir = FSDirectory.open(new File(index_dir)); 
     179        Searcher searcher = new IndexSearcher(index_dir_dir); 
     180        Analyzer analyzer = new GS2Analyzer(); 
    175181         
    176182        Term term = new Term("content", query_string); 
     
    178184        Query query = new TermQuery(term); 
    179185         
    180         Hits hits = searcher.search(query); 
    181         GSXML.addMetadata(this.doc, metadata_list, "numDocsMatched", ""+hits.length()); 
    182          
    183         for (int i=0; i<hits.length(); i++) { 
    184         org.apache.lucene.document.Document luc_doc = hits.doc(i); 
     186        TopDocs hits = searcher.search(query, Integer.MAX_VALUE); 
     187 
     188        GSXML.addMetadata(this.doc, metadata_list, "numDocsMatched", ""+hits.scoreDocs.length); 
     189         
     190            IndexReader reader = ((IndexSearcher) searcher).getIndexReader(); 
     191 
     192        for (int i=0; i<hits.scoreDocs.length; i++) { 
     193        int lucene_doc_num = hits.scoreDocs[i].doc; 
     194        org.apache.lucene.document.Document luc_doc = reader.document(lucene_doc_num); 
    185195        String node_id = luc_doc.get("nodeID"); 
    186196        Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);