[PATCHES] lucene plugin

Klaus Trainer <klaus.trainer-S0/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
As I didn't want to increase my dependency on google, I have integrated
the Lucene search engine into my Pyblosxom.

In the last years, there have been some small changes in the Lucene API
so I had to realign BlosxomIndexer.java and LuceneSearch.java.

In addition, since the recent Lucene releases now support leading
wildcards e.g. "*u*x" to match both "Unix" and "Linux", I enable this
feature by setting the appropriate property in LuceneSearch.java to "true".


Klaus

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Pyblosxom-devel mailing list
Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
BlosxomIndexer.diff (text/x-patch, 1.8 KB)
--- BlosxomIndexer.java	2008-02-20 20:14:37.000000000 +0100
+++ MyBlosxomIndexer.java	2008-02-20 20:08:19.000000000 +0100
@@ -60,10 +60,10 @@
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.*;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.util.Arrays;
 import org.apache.lucene.demo.html.HTMLParser;
 import org.apache.lucene.demo.HTMLDocument;
 
+import java.util.Arrays;
 import java.io.File;
 import java.util.Date;
 
@@ -106,7 +106,7 @@
       }
 
       writer = new IndexWriter(index, new StandardAnalyzer(), create);
-      writer.maxFieldLength = 1000000;
+      writer.setMaxFieldLength(1000000);
 
       indexDocs(root, index, create);		  // add new docs
 
@@ -144,7 +144,7 @@
 	while (uidIter.term() != null && uidIter.term().field() == "uid") {
 	  System.out.println("deleting " +
 			     HTMLDocument.uid2url(uidIter.term().text()));
-	  reader.delete(uidIter.term());
+	  reader.deleteDocuments(uidIter.term());
 	  uidIter.next();
 	}
 	deleting = false;
@@ -176,7 +176,7 @@
 	  if (deleting) {			  // delete stale docs
 	    System.out.println("deleting " +
 			       HTMLDocument.uid2url(uidIter.term().text()));
-	    reader.delete(uidIter.term());
+	    reader.deleteDocuments(uidIter.term());
 	  }
 	  uidIter.next();
 	}
@@ -185,12 +185,12 @@
 	  uidIter.next();			  // keep matching docs
 	} else if (!deleting) {			  // add new docs
 	  Document doc = HTMLDocument.Document(f);
-	  System.out.println("adding " + doc.get("url"));
+	  System.out.println("adding " + doc.get("path"));
 	writer.addDocument(doc);
 	}
       } else {					  // creating a new index
 	Document doc = HTMLDocument.Document(f);
-	System.out.println("adding " + doc.get("url"));
+	System.out.println("adding " + doc.get("path"));
 	writer.addDocument(doc);		  // add docs unconditionally
       }
     }
LuceneSearch.diff (text/x-patch, 793 B)
--- LuceneSearch.java	2008-02-20 20:15:18.000000000 +0100
+++ MyLuceneSearch.java	2008-02-20 20:08:19.000000000 +0100
@@ -38,14 +38,17 @@
 	    Searcher searcher = new IndexSearcher(args[0]);
 	    Analyzer analyzer = new StandardAnalyzer();
 
-	    String line = URLDecoder.decode(args[1]);
+	    String line = URLDecoder.decode(args[1], "UTF-8");
 
-	    Query query = QueryParser.parse(line, "contents", analyzer);
+	    QueryParser parser = new QueryParser("contents", analyzer);
+	    parser.setAllowLeadingWildcard(true);
+
+	    Query query = parser.parse(line);
 
 	    Hits hits = searcher.search(query);
 
 	    for (int i = 0; i < hits.length(); i++) {
-		System.out.println(hits.doc(i).get("url"));
+		System.out.println(hits.doc(i).get("path"));
 	    }
 
 	    searcher.close();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.