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

jswordcvs at crosswire.org jswordcvs at crosswire.org
Tue Mar 22 05:40:05 MST 2005


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

Modified Files:
	LuceneIndex.java LuceneIndexManager.java 
Log Message:
changed calls like book.getBookMetaData().xxx() to book.xxx().
Added a "Remove Index" button on the Book Installer.

Index: LuceneIndex.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/lucene/LuceneIndex.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** LuceneIndex.java	20 Mar 2005 02:34:44 -0000	1.9
--- LuceneIndex.java	22 Mar 2005 12:40:03 -0000	1.10
***************
*** 72,83 ****
      {
          this.book = book;
-         this.storage = storage;
  
          try
          {
!             // Opening Lucene indexes is quite quick I think, so we can try
!             // it to see if it works to report errors that we want to drop
!             // later
!             searcher = new IndexSearcher(NetUtil.getAsFile(storage).getCanonicalPath());
          }
          catch (IOException ex)
--- 72,79 ----
      {
          this.book = book;
  
          try
          {
!             this.path = NetUtil.getAsFile(storage).getCanonicalPath();
          }
          catch (IOException ex)
***************
*** 96,100 ****
  
          this.book = book;
!         this.storage = storage;
  
          Job job = JobManager.createJob(Msg.INDEX_START.toString(), Thread.currentThread(), false);
--- 92,105 ----
  
          this.book = book;
!         File finalPath = null;
!         try
!         {
!             finalPath = NetUtil.getAsFile(storage);
!             this.path = finalPath.getCanonicalPath();
!         }
!         catch (IOException ex)
!         {
!             throw new BookException(Msg.LUCENE_INIT, ex);
!         }
  
          Job job = JobManager.createJob(Msg.INDEX_START.toString(), Thread.currentThread(), false);
***************
*** 105,112 ****
              synchronized (CREATING)
              {
!                 book.getBookMetaData().setIndexStatus(IndexStatus.CREATING);
!                 File finalPath = NetUtil.getAsFile(storage);
!                 String finalCanonicalPath = finalPath.getCanonicalPath();
!                 File tempPath = new File(finalCanonicalPath + '.' + IndexStatus.CREATING.toString());
  
                  // An index is created by opening an IndexWriter with the
--- 110,115 ----
              synchronized (CREATING)
              {
!                 book.setIndexStatus(IndexStatus.CREATING);
!                 File tempPath = new File(path + '.' + IndexStatus.CREATING.toString());
  
                  // An index is created by opening an IndexWriter with the
***************
*** 124,131 ****
                  if (!job.isFinished())
                  {
- 
                      tempPath.renameTo(finalPath);
- 
-                     searcher = new IndexSearcher(finalPath.getCanonicalPath());
                  }
  
--- 127,131 ----
***************
*** 143,147 ****
          finally
          {
!             book.getBookMetaData().setIndexStatus(finalStatus);
              job.done();
          }
--- 143,147 ----
          finally
          {
!             book.setIndexStatus(finalStatus);
              job.done();
          }
***************
*** 160,187 ****
          if (search != null)
          {
!             if (searcher != null)
              {
!                 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);
!                     }
!                 }
!                 catch (Exception ex)
                  {
!                     throw new BookException(Msg.SEARCH_FAILED, ex);
                  }
              }
!             else
              {
!                 log.warn("Missing searcher, skipping search for: " + search); //$NON-NLS-1$
              }
          }
--- 160,184 ----
          if (search != null)
          {
!             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);
                  }
              }
!             catch (Exception ex)
              {
!                 throw new BookException(Msg.SEARCH_FAILED, ex);
!             }
!             finally
!             {
!                 Activator.deactivate(this);
              }
          }
***************
*** 205,209 ****
          try
          {
!             searcher = new IndexSearcher(NetUtil.getAsFile(storage).getCanonicalPath());
          }
          catch (IOException ex)
--- 202,206 ----
          try
          {
!             searcher = new IndexSearcher(path);
          }
          catch (IOException ex)
***************
*** 338,342 ****
       * The location of this index
       */
!     private URL storage;
  
      /**
--- 335,339 ----
       * The location of this index
       */
!     private String path;
  
      /**

Index: LuceneIndexManager.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/lucene/LuceneIndexManager.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** LuceneIndexManager.java	19 Mar 2005 01:56:47 -0000	1.8
--- LuceneIndexManager.java	22 Mar 2005 12:40:03 -0000	1.9
***************
*** 92,96 ****
      public void scheduleIndexCreation(final Book book)
      {
!         book.getBookMetaData().setIndexStatus(IndexStatus.SCHEDULED);
  
          Thread work = new Thread(new Runnable()
--- 92,96 ----
      public void scheduleIndexCreation(final Book book)
      {
!         book.setIndexStatus(IndexStatus.SCHEDULED);
  
          Thread work = new Thread(new Runnable()
***************
*** 117,121 ****
                  finally
                  {
!                     book.getBookMetaData().setIndexStatus(finalStatus);
                  }
              }
--- 117,121 ----
                  finally
                  {
!                     book.setIndexStatus(finalStatus);
                  }
              }
***************
*** 159,163 ****
              FileUtil.delete(tempPath);
              storage.renameTo(tempPath);
!             book.getBookMetaData().setIndexStatus(IndexStatus.UNDONE);
          }
          catch (IOException ex)
--- 159,163 ----
              FileUtil.delete(tempPath);
              storage.renameTo(tempPath);
!             book.setIndexStatus(IndexStatus.UNDONE);
          }
          catch (IOException ex)



More information about the jsword-svn mailing list