Author: natalia
Date: Mon Nov  3 13:35:52 2008
New Revision: 710170

URL: http://svn.apache.org/viewvc?rev=710170&view=rev
Log:
Updated Lucene to version 2.4.0

Added:
    xml/xindice/trunk/lib/lucene-core-2.4.0.jar   (with props)
Removed:
    xml/xindice/trunk/lib/lucene-core-2.3.2.jar
Modified:
    
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/LuceneIndexer.java
    
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/NodeReader.java
    
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/Searcher.java
    
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/SpecialQueryParser.java

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/LuceneIndexer.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/LuceneIndexer.java?rev=710170&r1=710169&r2=710170&view=diff
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/LuceneIndexer.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/LuceneIndexer.java 
Mon Nov  3 13:35:52 2008
@@ -21,35 +21,33 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.xindice.core.Collection;
-import org.apache.xindice.core.DBObject;
-import org.apache.xindice.core.DBException;
-import org.apache.xindice.core.data.Key;
-import org.apache.xindice.core.FaultCodes;
-import org.apache.xindice.core.query.CompilationException;
-import org.apache.xindice.core.query.ProcessingException;
-import org.apache.xindice.util.Configuration;
-import org.apache.xindice.util.XindiceException;
-import org.apache.xindice.util.StringUtilities;
-
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.Hit;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.TopDocs;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.DBException;
+import org.apache.xindice.core.DBObject;
+import org.apache.xindice.core.FaultCodes;
+import org.apache.xindice.core.data.Key;
+import org.apache.xindice.core.query.CompilationException;
+import org.apache.xindice.core.query.ProcessingException;
+import org.apache.xindice.util.Configuration;
+import org.apache.xindice.util.StringUtilities;
+import org.apache.xindice.util.XindiceException;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.ArrayList;
 
 /**
  * LuceneIndexer is used for maintaining full text indexes. It operates on
@@ -94,7 +92,6 @@
 
     // Default analyzer to use
     public static final String DEFANALYZER = 
"org.apache.lucene.analysis.SimpleAnalyzer";
-    private static final IndexMatch[] EMPTY_MATCHES = new IndexMatch[0];
 
     private File          idxFile;
     private IndexWriter   iw;
@@ -330,7 +327,7 @@
 
         try {
             if (iw == null) {
-                iw = new IndexWriter(getFile(), getAnalyzer(), create);
+                iw = new IndexWriter(getFile(), getAnalyzer(), create, 
IndexWriter.MaxFieldLength.UNLIMITED);
             }
         } catch (IOException e) {
             if (create) {
@@ -377,9 +374,9 @@
         try {
             assertOpen();
             if (iw != null) {
-                iw.flush();
+                iw.commit();
 
-                int nDocs = iw.docCount();
+                int nDocs = iw.maxDoc();
                 /* Fairly arbitrary rules for triggering index optimisation. 
Need to
                  * play with these.
                  */
@@ -446,11 +443,11 @@
             public void onValueAdded(IndexPattern pattern, String value, Key 
key, int pos, int len, short elemID, short attrID) {
                 if (doc == null) {
                     doc = new Document();
-                    doc.add(new Field(KEYNAME, key.toString(), 
Field.Store.YES, Field.Index.UN_TOKENIZED));
+                    doc.add(new Field(KEYNAME, key.toString(), 
Field.Store.YES, Field.Index.NOT_ANALYZED));
                 }
 
                 String field = (String) patterns.get(pattern);
-                doc.add(new Field(field, value, Field.Store.NO, 
Field.Index.TOKENIZED, Field.TermVector.YES));
+                doc.add(new Field(field, value, Field.Store.NO, 
Field.Index.ANALYZED, Field.TermVector.YES));
             }
         };
     }
@@ -478,15 +475,17 @@
      * @throws DBException if IOException prevented indexer from executing the 
query.
      */
     public IndexMatch[] queryMatches(Query query) throws DBException {
-        ArrayList matches = new ArrayList();
+        IndexMatch[] matches = null;
         Searcher searcher = getSearcher();
 
         try {
-            Hits hits = searcher.search(query);
-            for (Iterator i = hits.iterator(); i.hasNext(); ) {
-                Hit hit = (Hit) i.next();
-                Key key = new 
Key(hit.getDocument().getField(KEYNAME).stringValue());
-                matches.add(new IndexMatch(key, -1, -1));
+            TopDocs docs = searcher.is.search(query, searcher.ir.numDocs());
+            matches = new IndexMatch[docs.scoreDocs.length];
+
+            for (int i = 0; i < docs.scoreDocs.length; i++) {
+                int doc = docs.scoreDocs[i].doc;
+                Key key = new 
Key(searcher.ir.document(doc).getField(KEYNAME).stringValue());
+                matches[i] = new IndexMatch(key, -1, -1);
             }
         } catch (IOException e) {
             throw new ProcessingException("Failed to process a query", e);
@@ -494,7 +493,7 @@
             searcher.free();
         }
 
-        return (IndexMatch[]) matches.toArray(EMPTY_MATCHES);
+        return matches;
     }
 
     /**
@@ -504,7 +503,7 @@
      * return Searcher instance it created previously.
      *
      * @return current Searcher
-     * @throws DBException
+     * @throws DBException If index could not be accessed
      */
     private synchronized Searcher getSearcher() throws DBException {
 
@@ -590,6 +589,13 @@
             }
         }
 
+        /**
+         * Internal search method.
+         * @param query Search query
+         * @return Hits for the search
+         * @throws DBException Index could not be accessed
+         * @deprecated Deprecated following Lucene changes
+         */
         public Hits search(Query query) throws DBException {
             try {
                 return is.search(query);

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/NodeReader.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/NodeReader.java?rev=710170&r1=710169&r2=710170&view=diff
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/NodeReader.java
 (original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/NodeReader.java
 Mon Nov  3 13:35:52 2008
@@ -80,9 +80,10 @@
 
             TokenStream stream = analyzer.tokenStream("", new 
StringReader(text));
             try {
+                Token reusableToken = new Token();
                 Token token;
-                while ((token = stream.next()) != null) {
-                    nodes[i].add(new String(token.termBuffer(), 0, 
token.termLength()));
+                while ((token = stream.next(reusableToken)) != null) {
+                    nodes[i].add(token.term());
                 }
             } catch (IOException e) {
                 // won't happen

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/Searcher.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/Searcher.java?rev=710170&r1=710169&r2=710170&view=diff
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/Searcher.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/Searcher.java 
Mon Nov  3 13:35:52 2008
@@ -19,14 +19,14 @@
 
 package org.apache.xindice.core.query.ftsearch;
 
-import org.w3c.dom.NodeList;
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TopDocs;
 import org.apache.xindice.core.data.NodeSet;
+import org.w3c.dom.NodeList;
 
 import java.io.IOException;
 
@@ -69,36 +69,31 @@
         Query compQuery = new QueryParser("", analyzer).parse(query);
         NodeReader reader = new NodeReader(nodes, analyzer);
         IndexSearcher searcher = new IndexSearcher(reader);
-        Hits hits = null;
+
+        TopDocs docs = null;
         try {
-            hits = searcher.search(compQuery);
+            docs = searcher.search(compQuery, reader.numDocs());
         } catch (IOException e) {
             // this searcher does not use file IO, exception won't happen
         }
 
-        return new ResultSet(hits);
+        return new ResultSet(docs);
     }
 
     private class ResultSet implements NodeSet {
-        private Hits hits;
+        private TopDocs docs;
         private int count;
 
-        private ResultSet(Hits hits) {
-            this.hits = hits;
+        private ResultSet(TopDocs docs) {
+            this.docs = docs;
         }
 
         public boolean hasMoreNodes() {
-            return count < hits.length();
+            return count < docs.scoreDocs.length;
         }
 
         public Object getNextNode() {
-            try {
-                return nodes.item(hits.id(count++));
-            } catch (IOException e) {
-                // ignore, does not use IO
-            }
-
-            return null;
+            return nodes.item(docs.scoreDocs[count++].doc);
         }
     }
 }

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/SpecialQueryParser.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/SpecialQueryParser.java?rev=710170&r1=710169&r2=710170&view=diff
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/SpecialQueryParser.java
 (original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/core/query/ftsearch/SpecialQueryParser.java
 Mon Nov  3 13:35:52 2008
@@ -19,14 +19,14 @@
 
 package org.apache.xindice.core.query.ftsearch;
 
-import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.queryParser.CharStream;
+import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.queryParser.QueryParserTokenManager;
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.search.Query;
 import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.Query;
 
-import java.util.Vector;
+import java.util.List;
 
 /**
  * Specialized parser for text queries that ignores query clauses that have
@@ -59,12 +59,12 @@
      * boolean clauses that have 'prohibited' modifier.
      * @see QueryParser#addClause(java.util.Vector, int, int, 
org.apache.lucene.search.Query)
      */
-    protected void addClause(Vector clauses, int conj, int mods, Query q) {
+    protected void addClause(List clauses, int conj, int mods, Query q) {
 
         // If this term is introduced by AND, make the preceding term required,
         // unless it's already prohibited
         if (clauses.size() > 0 && conj == CONJ_AND) {
-            BooleanClause c = (BooleanClause) 
clauses.elementAt(clauses.size()-1);
+            BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);
             if (!c.isProhibited())
                 c.setOccur(BooleanClause.Occur.MUST);
         }
@@ -74,7 +74,7 @@
             // unless it's prohibited (that means we leave -a OR b but +a OR 
b-->a OR b)
             // notice if the input is a OR b, first term is parsed as 
required; without
             // this modification a OR b would parsed as +a OR b
-            BooleanClause c = (BooleanClause) 
clauses.elementAt(clauses.size()-1);
+            BooleanClause c = (BooleanClause) clauses.get(clauses.size()-1);
             if (!c.isProhibited())
                 c.setOccur(BooleanClause.Occur.SHOULD);
         }
@@ -100,9 +100,9 @@
             required = (!prohibited && conj != CONJ_OR);
         }
         if (required && !prohibited) {
-            clauses.addElement(new BooleanClause(q, BooleanClause.Occur.MUST));
+            clauses.add(new BooleanClause(q, BooleanClause.Occur.MUST));
         } else if (!required && !prohibited) {
-            clauses.addElement(new BooleanClause(q, 
BooleanClause.Occur.SHOULD));
+            clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
         } else if (required && prohibited) {
             throw new RuntimeException("Clause cannot be both required and 
prohibited");
         }

Added: xml/xindice/trunk/lib/lucene-core-2.4.0.jar
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/lib/lucene-core-2.4.0.jar?rev=710170&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xml/xindice/trunk/lib/lucene-core-2.4.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream


Reply via email to