From: <Kp...@us...> - 2009-06-12 12:10:00
|
Revision: 15429 http://jedit.svn.sourceforge.net/jedit/?rev=15429&view=rev Author: Kpouer Date: 2009-06-12 12:09:55 +0000 (Fri, 12 Jun 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2009-06-12 12:08:50 UTC (rev 15428) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2009-06-12 12:09:55 UTC (rev 15429) @@ -20,21 +20,13 @@ */ package gatchan.jedit.lucene; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.queryParser.QueryParser; -import org.apache.lucene.queryParser.MultiFieldQueryParser; -import org.apache.lucene.queryParser.ParseException; -import org.apache.lucene.analysis.SimpleAnalyzer; -import org.apache.lucene.analysis.KeywordAnalyzer; -import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.Term; +import org.apache.lucene.search.*; +import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.EBComponent; import org.gjt.sp.jedit.EBMessage; -import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.msg.BufferUpdate; import java.io.File; @@ -45,8 +37,6 @@ */ public class CentralIndex extends AbstractIndex implements EBComponent { - private QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "indexName"}, new StandardAnalyzer()); - public CentralIndex(File indexFile) { super(indexFile); @@ -78,39 +68,38 @@ try { - Query query = parser.parse("+path:" + path + " +indexName:" + indexName); + BooleanQuery query = getPathIndexQuery(path, indexName); TopDocs docs = searcher.search(query, 1); if (docs.scoreDocs.length == 0) { Document document = new Document(); - document.add(new Field("path", path, Field.Store.NO, Field.Index.ANALYZED)); - document.add(new Field("indexName", indexName, Field.Store.NO, Field.Index.ANALYZED)); + document.add(new Field("path", path, Field.Store.YES, Field.Index.NOT_ANALYZED)); + document.add(new Field("indexName", indexName, Field.Store.YES, Field.Index.NOT_ANALYZED)); writer.addDocument(document); } } - catch (ParseException e) - { - e.printStackTrace(); - } catch (IOException e) { e.printStackTrace(); } } + private BooleanQuery getPathIndexQuery(String path, String indexName) + { + BooleanQuery query = new BooleanQuery(); + query.add(new BooleanClause(new TermQuery(new Term("path", path)), BooleanClause.Occur.MUST)); + query.add(new BooleanClause(new TermQuery(new Term("indexName", indexName)), BooleanClause.Occur.MUST)); + return query; + } + void removeFile(String path, String indexName) { openWriter(); - QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "indexName"}, new SimpleAnalyzer()); try { - Query query = parser.parse("+path:" + path + " +indexName:" + indexName); + Query query = getPathIndexQuery(path, indexName); writer.deleteDocuments(query); } - catch (ParseException e) - { - e.printStackTrace(); - } catch (IOException e) { e.printStackTrace(); @@ -133,7 +122,7 @@ { try { - Query query = parser.parse("path:" + buffer.getPath()); + Query query = new TermQuery(new Term("path", buffer.getPath())); openSearcher(); TopDocs docs = searcher.search(query, 100); ScoreDoc[] scoreDocs = docs.scoreDocs; @@ -148,10 +137,6 @@ } } } - catch (ParseException e) - { - e.printStackTrace(); - } catch (IOException e) { e.printStackTrace(); Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-12 12:08:50 UTC (rev 15428) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-12 12:09:55 UTC (rev 15429) @@ -103,7 +103,7 @@ } catch (IOException e) { - Log.log(Log.ERROR, this, "Unable to lsit directory " + file.getPath(), e); + Log.log(Log.ERROR, this, "Unable to list directory " + file.getPath(), e); } } else if (file.getType() == VFSFile.FILE) @@ -119,7 +119,7 @@ return; try { - writer.deleteDocuments(new Term("path", path)); + writer.deleteDocuments(new Term("_path", path)); LucenePlugin.CENTRAL.removeFile(path, name); } catch (IOException e) @@ -165,7 +165,8 @@ { Log.log(Log.DEBUG, this, "Index:"+name + " add " + file); Document doc = new Document(); - doc.add(new Field("path", file.getPath(), Field.Store.YES, Field.Index.ANALYZED)); + doc.add(new Field("path", file.getPath(), Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("_path", file.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED)); Reader reader = null; try { @@ -174,7 +175,7 @@ jEdit.getActiveView()))); doc.add(new Field("content", reader)); LucenePlugin.CENTRAL.addFile(file.getPath(), name); - writer.updateDocument(new Term("path", file.getPath()), doc); + writer.updateDocument(new Term("_path", file.getPath()), doc); } catch (IOException e) { Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-12 12:08:50 UTC (rev 15428) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-12 12:09:55 UTC (rev 15429) @@ -26,6 +26,7 @@ import org.gjt.sp.jedit.EditPlugin; import org.gjt.sp.jedit.io.VFS; import org.gjt.sp.jedit.io.VFSManager; +import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.jEdit; import org.gjt.sp.util.Log; @@ -144,7 +145,7 @@ * @param indexName the index name * @param files the file array to add */ - public void addToIndex(final String indexName, final File[] files) + public void addToIndex(final String indexName, final VFSFile[] files) { VFSManager.runInWorkThread(new Runnable() { @@ -156,7 +157,7 @@ Log.log(Log.ERROR, this, "Unable to get index " + indexName); return; } - for (File file : files) + for (VFSFile file : files) { index.addFile(file.getPath()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |