[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/search/lucene s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Fri Apr 1 10:09:49 MST 2005


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/lucene
In directory www.crosswire.org:/tmp/cvs-serv5088/java/jsword/org/crosswire/jsword/book/search/lucene

Modified Files:
	LuceneThesarus.java LuceneIndex.java 
Log Message:
Improved ranking, bible display and fixed a few bugs.

Index: LuceneIndex.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/lucene/LuceneIndex.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** LuceneIndex.java	25 Mar 2005 04:02:52 -0000	1.13
--- LuceneIndex.java	1 Apr 2005 17:09:47 -0000	1.14
***************
*** 31,35 ****
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.IndexStatus;
! import org.crosswire.jsword.book.search.Index;
  import org.crosswire.jsword.passage.BibleInfo;
  import org.crosswire.jsword.passage.Key;
--- 31,36 ----
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.IndexStatus;
! import org.crosswire.jsword.book.search.SearchModifier;
! import org.crosswire.jsword.book.search.basic.AbstractIndex;
  import org.crosswire.jsword.passage.BibleInfo;
  import org.crosswire.jsword.passage.Key;
***************
*** 65,69 ****
   * @version $Id$
   */
! public class LuceneIndex implements Index, Activatable
  {
      /**
--- 66,70 ----
   * @version $Id$
   */
! public class LuceneIndex extends AbstractIndex implements Activatable
  {
      /**
***************
*** 146,152 ****
                          buf.append('\n');
                      }
!                     Reporter.informUser(this, Msg.BAD_VERSE, buf);                    
                  }
!                     
              }
          }
--- 147,153 ----
                          buf.append('\n');
                      }
!                     Reporter.informUser(this, Msg.BAD_VERSE, buf);
                  }
! 
              }
          }
***************
*** 164,168 ****
  
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.search.SearchEngine#findKeyList(org.crosswire.jsword.book.Search)
       */
      public Key findWord(String search) throws BookException
--- 165,169 ----
  
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.search.Index#findWord(java.lang.String)
       */
      public Key findWord(String search) throws BookException
***************
*** 170,175 ****
          checkActive();
  
! //        Key tally = book.createEmptyKeyList();
!          PassageTally tally = new PassageTally();
  
          if (search != null)
--- 171,176 ----
          checkActive();
  
!         SearchModifier modifier = getSearchModifier();
!         Key results = null;
  
          if (search != null)
***************
*** 177,190 ****
              try
              {
                  Analyzer analyzer = new SimpleAnalyzer();
                  Query query = QueryParser.parse(search, LuceneIndex.FIELD_BODY, analyzer);
                  Hits hits = searcher.search(query);
  
!                 for (int i = 0; i < hits.length(); i++)
                  {
!                     Verse verse = VerseFactory.fromString(hits.doc(i).get(LuceneIndex.FIELD_NAME));
!                   int score = (int) (hits.score(i) * 100);
!                   tally.add(verse, score);
! //                    tally.addAll(verse);
                  }
              }
--- 178,207 ----
              try
              {
+ 
                  Analyzer analyzer = new SimpleAnalyzer();
                  Query query = QueryParser.parse(search, LuceneIndex.FIELD_BODY, analyzer);
                  Hits hits = searcher.search(query);
  
!                 // For ranking we use a PassageTally
!                 if (modifier != null && modifier.isRanked())
                  {
!                     PassageTally tally = new PassageTally();
!                     results = tally;
!                     for (int i = 0; i < hits.length(); i++)
!                     {
!                         Verse verse = VerseFactory.fromString(hits.doc(i).get(LuceneIndex.FIELD_NAME));
!                         int score = (int) (hits.score(i) * 100);
!                         tally.add(verse, score);
!                     }
!                 }
!                 else
!                 {
!                     results = book.createEmptyKeyList();
!                     for (int i = 0; i < hits.length(); i++)
!                     {
!                         Verse verse = VerseFactory.fromString(hits.doc(i).get(LuceneIndex.FIELD_NAME));
!                         results.addAll(verse);
!                     }
! 
                  }
              }
***************
*** 199,203 ****
          }
  
!         return tally;
      }
  
--- 216,231 ----
          }
  
!         if (results == null)
!         {
!             if (modifier.isRanked())
!             {
!                 results = new PassageTally();
!             }
!             else
!             {
!                 results = book.createEmptyKeyList();
!             }
!         }
!         return results;
      }
  
***************
*** 211,215 ****
  
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.search.SearchEngine#activate()
       */
      public final void activate(Lock lock)
--- 239,243 ----
  
      /* (non-Javadoc)
!      * @see org.crosswire.common.activate.Activatable#activate(org.crosswire.common.activate.Lock)
       */
      public final void activate(Lock lock)
***************
*** 228,232 ****
  
      /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.search.SearchEngine#deactivate()
       */
      public final void deactivate(Lock lock)
--- 256,260 ----
  
      /* (non-Javadoc)
!      * @see org.crosswire.common.activate.Activatable#deactivate(org.crosswire.common.activate.Lock)
       */
      public final void deactivate(Lock lock)
***************
*** 281,286 ****
                  catch (BookException e)
                  {
-                     // ignore
-                     // TODO(DM): report these to the user as verses that could not be indexed.
                      errors.add(subkey);
                      continue;
--- 309,312 ----

Index: LuceneThesarus.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/lucene/LuceneThesarus.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LuceneThesarus.java	25 Mar 2005 04:02:52 -0000	1.1
--- LuceneThesarus.java	1 Apr 2005 17:09:47 -0000	1.2
***************
*** 1,46 ****
  package org.crosswire.jsword.book.search.lucene;
  
- import java.io.File;
- import java.io.IOException;
- import java.io.StringReader;
- import java.net.URL;
- import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collection;
- import java.util.Iterator;
- import java.util.List;
  
- import org.apache.lucene.analysis.Analyzer;
- import org.apache.lucene.analysis.SimpleAnalyzer;
- import org.apache.lucene.document.Document;
- import org.apache.lucene.document.Field;
- import org.apache.lucene.index.IndexWriter;
- import org.apache.lucene.queryParser.QueryParser;
- import org.apache.lucene.search.Hits;
- import org.apache.lucene.search.IndexSearcher;
- import org.apache.lucene.search.Query;
- import org.apache.lucene.search.Searcher;
- import org.crosswire.common.activate.Activatable;
- import org.crosswire.common.activate.Activator;
- import org.crosswire.common.activate.Lock;
- import org.crosswire.common.progress.Job;
- import org.crosswire.common.progress.JobManager;
- import org.crosswire.common.util.Logger;
- import org.crosswire.common.util.NetUtil;
- import org.crosswire.common.util.Reporter;
- import org.crosswire.jsword.book.Book;
- import org.crosswire.jsword.book.BookData;
  import org.crosswire.jsword.book.BookException;
- import org.crosswire.jsword.book.IndexStatus;
- import org.crosswire.jsword.book.search.Index;
  import org.crosswire.jsword.book.search.Thesaurus;
- import org.crosswire.jsword.passage.BibleInfo;
- import org.crosswire.jsword.passage.Key;
- import org.crosswire.jsword.passage.KeyUtil;
- import org.crosswire.jsword.passage.NoSuchKeyException;
- import org.crosswire.jsword.passage.NoSuchVerseException;
- import org.crosswire.jsword.passage.PassageTally;
- import org.crosswire.jsword.passage.Verse;
- import org.crosswire.jsword.passage.VerseFactory;
  
  /**
--- 1,9 ----
***************
*** 76,81 ****
      public Collection getSynonyms(String word) throws BookException
      {
!         // Use fuzzy search
!         Object[] synonymns =  { (word + '~') };
          return Arrays.asList(synonymns);
      }
--- 39,44 ----
      public Collection getSynonyms(String word) throws BookException
      {
!         // Use fuzzy search and wildcard search
!         Object[] synonymns =  { word + '*', word + '~' };
          return Arrays.asList(synonymns);
      }



More information about the jsword-svn mailing list