From: <sh...@us...> - 2009-05-20 23:06:57
|
Revision: 15326 http://jedit.svn.sourceforge.net/jedit/?rev=15326&view=rev Author: shlomy Date: 2009-05-20 23:06:45 +0000 (Wed, 20 May 2009) Log Message: ----------- Replaced the fileIndex field, which connected the meta-data index and the content index, with the actual file path. This eliminates the need in running an additional query for each search result, and also eliminates the need in maintaining a file-index, which needs to provide different indices for each indexed project / tree. Modified Paths: -------------- plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java Modified: plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java 2009-05-20 22:54:43 UTC (rev 15325) +++ plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java 2009-05-20 23:06:45 UTC (rev 15326) @@ -30,7 +30,6 @@ public class LucenePlugin extends EBPlugin { static private Analyzer analyzer = new StandardAnalyzer(); - static private int fileIndex = 0; private static boolean validDir(String path) { Pattern exc = Pattern.compile(OptionPane.excludeDirs(),Pattern.CASE_INSENSITIVE); @@ -101,7 +100,7 @@ int index = 0; while ((line = input.readLine()) != null) { index++; - contentWriter.addDocument(createLineDocument(index, line)); + contentWriter.addDocument(createLineDocument(path, index, line)); } } finally { @@ -114,27 +113,20 @@ } } - private static Document createLineDocument(int index, String line) + private static Document createLineDocument(String file, int index, String line) { Document doc = new Document(); - doc.add(new Field("fileIndex", String.valueOf(fileIndex), - Field.Store.YES, Field.Index.NO)); - doc.add(new Field("line", String.valueOf(index), - Field.Store.YES, Field.Index.NOT_ANALYZED)); - doc.add(new Field("content", line, Field.Store.YES, - Field.Index.ANALYZED)); - //System.err.println("Created line: index=" + index + " fileIndex=" + fileIndex + " content=" + line); + doc.add(new Field("file", file, Field.Store.YES, Field.Index.NO)); + doc.add(new Field("line", String.valueOf(index), Field.Store.YES, + Field.Index.NOT_ANALYZED)); + doc.add(new Field("content", line, Field.Store.YES, Field.Index.ANALYZED)); return doc; } private static Document createFileDocument(File f) { - fileIndex++; Document doc = new Document(); doc.add(new Field("file", f.getPath(), Field.Store.YES, Field.Index.NO)); - doc.add(new Field("fileIndex", String.valueOf(fileIndex), - Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("modified", String.valueOf(f.lastModified()), Field.Store.YES, Field.Index.NO)); - //System.err.println("Created file: index=" + fileIndex + " name=" + f.getPath()); return doc; } @@ -168,19 +160,8 @@ for (int i = 0; i < collector.docs.size(); i++) { Document doc = searcher.doc(collector.docs.get(i)); - Query metaQuery = new QueryParser("fileIndex", analyzer).parse( - doc.get("fileIndex")); - SearchResultCollector fileCollector = new SearchResultCollector(); - metaSearcher.search(metaQuery, fileCollector); - if (fileCollector.docs.size() != 1) - { - JOptionPane.showMessageDialog(null, "Bad index - number of files with index " + doc.get("fileIndex") + " is not 1."); - return null; - } - Document fileDoc = metaSearcher.doc(fileCollector.docs.get(0)); - results.add(new FileLine(fileDoc.get("file"), - Integer.valueOf(doc.get("line")).intValue(), - doc.get("content"))); + results.add(new FileLine(doc.get("file"), + Integer.valueOf(doc.get("line")).intValue(), doc.get("content"))); } searcher.close(); return results; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |