jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r635552 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: AbstractIndex.java MultiIndex.java PersistentIndex.java SearchIndex.java VolatileIndex.java
Date Mon, 10 Mar 2008 13:34:37 GMT
Author: mreutegg
Date: Mon Mar 10 06:34:27 2008
New Revision: 635552

URL: http://svn.apache.org/viewvc?rev=635552&view=rev
Log:
JCR-1465: Configurable Similarity

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=635552&r1=635551&r2=635552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
Mon Mar 10 06:34:27 2008
@@ -23,6 +23,7 @@
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.search.Similarity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,6 +71,9 @@
     /** Analyzer we use to tokenize text */
     private Analyzer analyzer;
 
+    /** The similarity in use for indexing and searching. */
+    private final Similarity similarity;
+
     /** Compound file flag */
     private boolean useCompoundFile = true;
 
@@ -108,6 +112,7 @@
      * <code>directory</code>.
      *
      * @param analyzer      the analyzer for text tokenizing.
+     * @param similarity    the similarity implementation.
      * @param directory     the underlying directory.
      * @param cache         the document number cache if this index should use
      *                      one; otherwise <code>cache</code> is
@@ -116,10 +121,12 @@
      * @throws IOException if the index cannot be initialized.
      */
     AbstractIndex(Analyzer analyzer,
+                  Similarity similarity,
                   Directory directory,
                   DocNumberCache cache,
                   IndexingQueue indexingQueue) throws IOException {
         this.analyzer = analyzer;
+        this.similarity = similarity;
         this.directory = directory;
         this.cache = cache;
         this.indexingQueue = indexingQueue;
@@ -291,6 +298,7 @@
         }
         if (indexWriter == null) {
             indexWriter = new IndexWriter(getDirectory(), analyzer);
+            indexWriter.setSimilarity(similarity);
             // since lucene 2.0 setMaxBuffereDocs is equivalent to previous minMergeDocs
attribute
             indexWriter.setMaxBufferedDocs(minMergeDocs);
             indexWriter.setMaxMergeDocs(maxMergeDocs);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=635552&r1=635551&r2=635552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Mon Mar 10 06:34:27 2008
@@ -275,9 +275,9 @@
                 // move on to next index
                 continue;
             }
-            PersistentIndex index = new PersistentIndex(
-                    indexNames.getName(i), sub,
-                    handler.getTextAnalyzer(), cache, indexingQueue);
+            PersistentIndex index = new PersistentIndex(indexNames.getName(i),
+                    sub, handler.getTextAnalyzer(), handler.getSimilarity(),
+                    cache, indexingQueue);
             index.setMaxMergeDocs(handler.getMaxMergeDocs());
             index.setMergeFactor(handler.getMergeFactor());
             index.setMinMergeDocs(handler.getMinMergeDocs());
@@ -581,7 +581,8 @@
             sub = new File(indexDir, indexName);
         }
         PersistentIndex index = new PersistentIndex(indexName, sub,
-                handler.getTextAnalyzer(), cache, indexingQueue);
+                handler.getTextAnalyzer(), handler.getSimilarity(),
+                cache, indexingQueue);
         index.setMaxMergeDocs(handler.getMaxMergeDocs());
         index.setMergeFactor(handler.getMergeFactor());
         index.setMinMergeDocs(handler.getMinMergeDocs());
@@ -908,8 +909,8 @@
      * Resets the volatile index to a new instance.
      */
     private void resetVolatileIndex() throws IOException {
-        volatileIndex = new VolatileIndex(
-                handler.getTextAnalyzer(), indexingQueue);
+        volatileIndex = new VolatileIndex(handler.getTextAnalyzer(),
+                handler.getSimilarity(), indexingQueue);
         volatileIndex.setUseCompoundFile(handler.getUseCompoundFile());
         volatileIndex.setMaxFieldLength(handler.getMaxFieldLength());
         volatileIndex.setBufferSize(handler.getBufferSize());

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java?rev=635552&r1=635551&r2=635552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
Mon Mar 10 06:34:27 2008
@@ -24,6 +24,7 @@
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.NativeFSLockFactory;
+import org.apache.lucene.search.Similarity;
 
 import java.io.IOException;
 import java.io.File;
@@ -49,6 +50,7 @@
      * @param name the name of this index.
      * @param indexDir the directory to store the index.
      * @param analyzer the analyzer for text tokenizing.
+     * @param similarity the similarity implementation.
      * @param cache the document number cache
      * @param indexingQueue the indexing queue.
      * @throws IOException if an error occurs while opening / creating the
@@ -56,11 +58,11 @@
      * @throws IOException if an error occurs while opening / creating
      *  the index.
      */
-    PersistentIndex(String name, File indexDir,
-                    Analyzer analyzer, DocNumberCache cache,
+    PersistentIndex(String name, File indexDir, Analyzer analyzer,
+                    Similarity similarity, DocNumberCache cache,
                     IndexingQueue indexingQueue)
             throws IOException {
-        super(analyzer, FSDirectory.getDirectory(indexDir, new NativeFSLockFactory(indexDir)),
+        super(analyzer, similarity, FSDirectory.getDirectory(indexDir, new NativeFSLockFactory(indexDir)),
                 cache, indexingQueue);
         this.name = name;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=635552&r1=635551&r2=635552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Mon Mar 10 06:34:27 2008
@@ -49,6 +49,7 @@
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
+import org.apache.lucene.search.Similarity;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
@@ -362,6 +363,11 @@
     private SpellChecker spellChecker;
 
     /**
+     * The similarity in use for indexing and searching.
+     */
+    private Similarity similarity = Similarity.getDefault();
+
+    /**
      * Indicates if this <code>SearchIndex</code> is closed and cannot be used
      * anymore.
      */
@@ -655,8 +661,9 @@
         Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
 
         final IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
-        return new FilterMultiColumnQueryHits(new JackrabbitIndexSearcher(
-                session, reader).execute(query, sort)) {
+        JackrabbitIndexSearcher searcher = new JackrabbitIndexSearcher(session, reader);
+        searcher.setSimilarity(getSimilarity());
+        return new FilterMultiColumnQueryHits(searcher.execute(query, sort)) {
             public void close() throws IOException {
                 try {
                     super.close();
@@ -749,6 +756,13 @@
     }
 
     /**
+     * @return the similarity, which should be used for indexing and searching.
+     */
+    public Similarity getSimilarity() {
+        return similarity;
+    }
+
+    /**
      * Returns an index reader for this search index. The caller of this method
      * is responsible for closing the index reader when he is finished using
      * it.
@@ -1783,6 +1797,28 @@
      */
     public String getSynonymProviderConfigPath() {
         return synonymProviderConfigPath;
+    }
+
+    /**
+     * Sets the similarity implementation, which will be used for indexing and
+     * searching. The implementation must extend {@link Similarity}.
+     *
+     * @param className a {@link Similarity} implementation.
+     */
+    public void setSimilarityClass(String className) {
+        try {
+            Class similarityClass = Class.forName(className);
+            similarity = (Similarity) similarityClass.newInstance();
+        } catch (Exception e) {
+            log.warn("Invalid Similarity class: " + className, e);
+        }
+    }
+
+    /**
+     * @return the name of the similarity class.
+     */
+    public String getSimilarityClass() {
+        return similarity.getClass().getName();
     }
 
     //----------------------------< internal >----------------------------------

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java?rev=635552&r1=635551&r2=635552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
Mon Mar 10 06:34:27 2008
@@ -19,12 +19,11 @@
 import org.apache.commons.collections.map.LinkedMap;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.search.Similarity;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -56,11 +55,14 @@
      * Creates a new <code>VolatileIndex</code> using an <code>analyzer</code>.
      *
      * @param analyzer the analyzer to use.
+     * @param similarity the similarity implementation.
      * @param indexingQueue the indexing queue.
      * @throws IOException if an error occurs while opening the index.
      */
-    VolatileIndex(Analyzer analyzer, IndexingQueue indexingQueue) throws IOException {
-        super(analyzer, new RAMDirectory(), null, indexingQueue);
+    VolatileIndex(Analyzer analyzer,
+                  Similarity similarity,
+                  IndexingQueue indexingQueue) throws IOException {
+        super(analyzer, similarity, new RAMDirectory(), null, indexingQueue);
     }
 
     /**



Mime
View raw message