Revision: 16107
          http://gate.svn.sourceforge.net/gate/?rev=16107&view=rev
Author:   valyt
Date:     2012-10-03 14:09:23 +0000 (Wed, 03 Oct 2012)
Log Message:
-----------
Lazy construction of the stop words set.

Modified Paths:
--------------
    
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java 
    2012-10-03 01:19:06 UTC (rev 16106)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java 
    2012-10-03 14:09:23 UTC (rev 16107)
@@ -28,6 +28,7 @@
 
 import java.io.IOException;
 import java.util.HashSet;
+import java.util.Set;
 
 /**
  * Base class for terms queries that use an MG4J direct index for their search.
@@ -72,10 +73,10 @@
   protected boolean stopWordsBlocked = false;
   
   /**
-   * Stop words list used for filtering out stop words. See 
+   * Stop words set used for filtering out stop words. See 
    * {@link #stopWordsBlocked}. 
    */
-  protected String[] stopWords = null;
+  protected Set<String> stopWords = null;
   
   /**
    * The query engine used to execute this query.
@@ -206,11 +207,9 @@
       counterSetupVisitor.prepare();
       documentIterator.accept( counterSetupVisitor ); 
     }
-    HashSet<String> stopWordsSet = null;
     if(stopWordsBlocked) {
-      String[] sws = stopWords == null ?  DEFAULT_STOP_WORDS : stopWords;
-      stopWordsSet = new HashSet<String>(sws.length);
-      for(String sw : sws) stopWordsSet.add(sw);
+      // use the default list if no custom one was set
+      if(stopWords == null) setStopWords(DEFAULT_STOP_WORDS);
     }
     
     long termId = documentIterator.nextDocument();
@@ -227,7 +226,7 @@
          indexType == IndexType.ANNOTATIONS) {
         termString = indirectIndexPool.getTerm(termId);
       }
-      if(stopWordsBlocked && stopWordsSet.contains(termString)) {
+      if(stopWordsBlocked && stopWords.contains(termString)) {
         // skip this term
         termId = documentIterator.nextDocument();
         continue terms;
@@ -284,10 +283,14 @@
    * Gets the current custom list of stop words.
    * @return the stopWords
    */
-  public String[] getStopWords() {
+  public Set<String> getStopWords() {
     return stopWords;
   }
 
+  public void setStopWords(Set<String> stopWords) {
+    this.stopWords = new HashSet<String>(stopWords);
+  }
+  
   /**
    * Sets the custom list of stop words that should be blocked from query 
    * results. The actual blocking also needs to be enabled by calling 
@@ -298,7 +301,8 @@
    * @param stopWords the stopWords to set
    */
   public void setStopWords(String[] stopWords) {
-    this.stopWords = stopWords;
+    this.stopWords = new HashSet<String>(stopWords.length);
+    for(String sw : stopWords) this.stopWords.add(sw); 
   }
   
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to