From: <sh...@us...> - 2009-05-19 11:01:40
|
Revision: 15308 http://jedit.svn.sourceforge.net/jedit/?rev=15308&view=rev Author: shlomy Date: 2009-05-19 11:01:33 +0000 (Tue, 19 May 2009) Log Message: ----------- A very simplistic version (but working...) of a Lucene plugin, that allows indexing a single directory, and presents the search results in a source link tree. Modified Paths: -------------- plugins/LucenePlugin/trunk/build.xml Added Paths: ----------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/actions.xml plugins/LucenePlugin/trunk/description.html plugins/LucenePlugin/trunk/dockables.xml plugins/LucenePlugin/trunk/index.html plugins/LucenePlugin/trunk/lucene-core-2.4.1.jar plugins/LucenePlugin/trunk/src/ plugins/LucenePlugin/trunk/src/lucene/ plugins/LucenePlugin/trunk/src/lucene/FileLine.java plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java plugins/LucenePlugin/trunk/src/lucene/OptionPane.java plugins/LucenePlugin/trunk/src/lucene/SearchResults.java Removed Paths: ------------- plugins/LucenePlugin/trunk/LICENSE.txt plugins/LucenePlugin/trunk/build.properties plugins/LucenePlugin/trunk/main/ plugins/LucenePlugin/trunk/test/ Deleted: plugins/LucenePlugin/trunk/LICENSE.txt =================================================================== --- plugins/LucenePlugin/trunk/LICENSE.txt 2009-05-18 21:30:48 UTC (rev 15307) +++ plugins/LucenePlugin/trunk/LICENSE.txt 2009-05-19 11:01:33 UTC (rev 15308) @@ -1,19 +0,0 @@ -Copyright (c) 2008 Eric Berry <el...@gm...> - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file Added: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props (rev 0) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,36 @@ +plugin.lucene.LucenePlugin.activate=startup + +# general plugin information +plugin.lucene.LucenePlugin.name=LucenePlugin +plugin.lucene.LucenePlugin.author=Shlomy Reinstein +plugin.lucene.LucenePlugin.version=0.1 +plugin.lucene.LucenePlugin.depend.0=jdk 1.5 +plugin.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 +plugin.lucene.LucenePlugin.depend.2=plugin marker.MarkerSetsPlugin 0.1 + +# Options +plugin.lucene.LucenePlugin.option-pane=LucenePlugin +options.LucenePlugin.code=new lucene.OptionPane(); +options.LucenePlugin.label=LucenePlugin +options.LucenePlugin.index_path.label=Lucene index directory: +options.LucenePlugin.exclude_dirs.label=Exclude directories that match: +options.LucenePlugin.include_files.label=Include only files that match: +options.LucenePlugin.exclude_files.label=... except files that match: + +options.LucenePlugin.include_files=.*\\.([ch]|cpp|java|inl|rc|ds[pw]|txt)$ +options.LucenePlugin.exclude_dirs=(debug|bin|build|icons|\\.svn) + +# action labels +lucene-index.label=Index directory tree... +lucene-find.label=Find text... + +# menu items +plugin.lucene.LucenePlugin.menu=lucene-index lucene-find + +# docs +plugin.lucene.LucenePlugin.docs=index.html +plugin.lucene.LucenePlugin.description=LucenePlugin provides an interface to the Lucene engine. + +# dockables +lucene-search.title=Lucene Search +lucene-search.label=Lucene Search Added: plugins/LucenePlugin/trunk/actions.xml =================================================================== --- plugins/LucenePlugin/trunk/actions.xml (rev 0) +++ plugins/LucenePlugin/trunk/actions.xml 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,18 @@ +<!DOCTYPE ACTIONS SYSTEM "actions.dtd"> +<!-- $Id: actions.xml 7606 2004-11-07 15:52:36Z orutherfurd $ --> + +<ACTIONS> + + <ACTION NAME="lucene-find" NO_REPEAT="TRUE"> + <CODE> + lucene.LucenePlugin.find(view); + </CODE> + </ACTION> + <ACTION NAME="lucene-index" NO_REPEAT="TRUE"> + <CODE> + lucene.LucenePlugin.index(view); + </CODE> + </ACTION> + +</ACTIONS> + Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2009-05-18 21:30:48 UTC (rev 15307) +++ plugins/LucenePlugin/trunk/build.xml 2009-05-19 11:01:33 UTC (rev 15308) @@ -1,55 +1,30 @@ -<?xml version="1.0"?> -<project name="LucenePlugin" default="build" basedir="."> - <property file="../build.properties" /> - <property file="build.properties" /> - <property name="src.dir" value="${basedir}/src/java" /> - <property name="conf.dir" value="${basedir}/src/conf" /> - <property name="lib.dir" value="${basedir}/lib" /> - <property name="compiler.target" value="1.5" /> - <property name="compiler.source" value="1.5" /> - - <!-- import the support build script --> - <import file="${build.support}/plugin-build.xml" /> - - <!-- Classpath is the plugins directory, application jars dir, project lib dir and project build dir --> - <path id="project.class.path"> - <!-- Other plugins jars --> - <fileset dir="${install.dir}"> - <include name="*.jar" /> - </fileset> - <!-- Your jars --> - <fileset dir="${lib.dir}"> - <include name="*.jar" /> - </fileset> - </path> - - <selector id="extraFiles"> - <and> - <or> - <filename name="**/LICENSE" /> - <filename name="**/README" /> - <filename name="**/swixml/*" /> - </or> - </and> - </selector> - - <target name="build.prepare"> - <!-- Before the build, copy all the configuration files to the classes directory. --> - <copy todir="${build.classes}" includeEmptyDirs="false"> - <fileset dir="${conf.dir}"> - <include name="**/*" /> - </fileset> - <fileset dir="${basedir}/src/swixml"> - <include name="**/*" /> - </fileset> - </copy> - </target> - <target name="build.post"> - <!-- After the build, copy all the libraries over to the dist directory. --> - <copy todir="${install.dir}" includeEmptyDirs="false"> - <fileset dir="${lib.dir}"> - <include name="**/*.jar" /> - </fileset> - </copy> - </target> -</project> +<?xml version="1.0"?> +<project name="LucenePlugin" default="build" basedir="."> +<!-- + This is a build.xml file for building the CtagsSideKick plugin. +--> + <!-- Read optional properties from various places --> + <!-- Latter ones override previous properties. --> + <property file="build.properties"/> + <property file="../build.properties"/> + <property name="javadoc.packagenames" value="browser.*,options.*" /> + <property name="user-doc.xml" location = "users-guide.xml"/> + <property name="plugin.dependencies" value="CommonControls" /> + <property name="dist.target" value="dist.complete" /> + <property name="compiler.source" value="1.5" /> + <property name="compiler.target" value="1.5" /> + + <import file="${build.support}/plugin-build.xml" /> + + <path id="project.class.path"> + <pathelement location="${jedit.install.dir}/jedit.jar" /> + <pathelement location="${install.dir}/MarkerSets.jar"/> + <pathelement location="${install.dir}/lucene-core-2.4.1.jar"/> + </path> + + <target name="build.prepare" > + <mkdir dir="${build.dir}" /> + <copy file="lucene-core-2.4.1.jar" todir="${install.dir}" /> + + </target> +</project> Added: plugins/LucenePlugin/trunk/description.html =================================================================== --- plugins/LucenePlugin/trunk/description.html (rev 0) +++ plugins/LucenePlugin/trunk/description.html 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,3 @@ +<html> +<p>LucenePlugin provides an interface to the Apache Lucene text search engine library.</p> +</html> Added: plugins/LucenePlugin/trunk/dockables.xml =================================================================== --- plugins/LucenePlugin/trunk/dockables.xml (rev 0) +++ plugins/LucenePlugin/trunk/dockables.xml 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,10 @@ +<?xml version="1.0"?> + +<!DOCTYPE DOsCKABLES SYSTEM "dockables.dtd"> + +<DOCKABLES> + <DOCKABLE NAME="lucene-search" MOVABLE="TRUE"> + new lucene.SearchResults(view); + </DOCKABLE> +</DOCKABLES> + Added: plugins/LucenePlugin/trunk/index.html =================================================================== --- plugins/LucenePlugin/trunk/index.html (rev 0) +++ plugins/LucenePlugin/trunk/index.html 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,9 @@ +<html> +<head> + <title>LucenePlugin</title> +</head> + +<body> +Lucene plugin provides an interface to the Lucene engine. +</body> +</html> Added: plugins/LucenePlugin/trunk/lucene-core-2.4.1.jar =================================================================== (Binary files differ) Property changes on: plugins/LucenePlugin/trunk/lucene-core-2.4.1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: plugins/LucenePlugin/trunk/src/lucene/FileLine.java =================================================================== --- plugins/LucenePlugin/trunk/src/lucene/FileLine.java (rev 0) +++ plugins/LucenePlugin/trunk/src/lucene/FileLine.java 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,13 @@ +package lucene; + +public class FileLine { + String file; + int line; + String content; + public FileLine(String f, int l, String c) + { + file = f; + line = l; + content = c; + } +} Added: plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java (rev 0) +++ plugins/LucenePlugin/trunk/src/lucene/LucenePlugin.java 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,190 @@ +package lucene; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Vector; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.JOptionPane; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriter.MaxFieldLength; +import org.apache.lucene.queryParser.ParseException; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.HitCollector; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Searcher; +import org.gjt.sp.jedit.EBPlugin; +import org.gjt.sp.jedit.View; +import org.gjt.sp.jedit.gui.DockableWindowManager; + +import lucene.OptionPane; + +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); + Matcher matcher = exc.matcher(path); + return (! matcher.matches()); + } + private static boolean validFile(String path) { + Pattern inc = Pattern.compile(OptionPane.includeFiles(),Pattern.CASE_INSENSITIVE); + Pattern exc = Pattern.compile(OptionPane.excludeFiles(),Pattern.CASE_INSENSITIVE); + Matcher incMatcher = inc.matcher(path); + Matcher excMatcher = exc.matcher(path); + return (incMatcher.matches() && (! excMatcher.matches())); + } + public static void find(View view) { + String text = JOptionPane.showInputDialog("Enter text to search:"); + if (text == null) + return; + DockableWindowManager dwm = view.getDockableWindowManager(); + dwm.showDockableWindow("lucene-search"); + SearchResults sr = (SearchResults) dwm.getDockableWindow( + "lucene-search"); + sr.search(text); + } + private static String contentDir() + { + return OptionPane.indexPath() + File.separator + "content"; + } + private static String metaDir() + { + return OptionPane.indexPath() + File.separator + "meta"; + } + public static void index(View view) { + String dir = JOptionPane.showInputDialog("Directory to index:"); + if (dir == null) + return; + try { + IndexWriter contentWriter = new IndexWriter(contentDir(), + analyzer, MaxFieldLength.UNLIMITED); + IndexWriter metaWriter = new IndexWriter(metaDir(), + analyzer, MaxFieldLength.UNLIMITED); + makeIndex(metaWriter, contentWriter, dir); + contentWriter.close(); + metaWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + private static void makeIndex(IndexWriter metaWriter, + IndexWriter contentWriter, String path) + { + File f = new File(path); + if (f.isDirectory()) { + if (! validDir(path)) + return; + String [] entries = f.list(); + for (String entry: entries) + makeIndex(metaWriter, contentWriter, + path + File.separatorChar + entry); + } else { + if (! validFile(path)) + return; + try { + metaWriter.addDocument(createFileDocument(f)); + BufferedReader input = new BufferedReader(new FileReader(f)); + try { + String line = null; + int index = 0; + while ((line = input.readLine()) != null) { + index++; + contentWriter.addDocument(createLineDocument(index, line)); + } + } + finally { + input.close(); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + private static Document createLineDocument(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); + 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; + } + + public void start() { + } + + private static class SearchResultCollector extends HitCollector + { + Vector<Integer> docs = new Vector<Integer>(); + + @Override + public void collect(int doc, float score) { + docs.add(doc); + } + } + public static Vector<FileLine> search(String queryString) + throws ParseException, IOException + { + Searcher searcher = new IndexSearcher(contentDir()); + Query query = new QueryParser("content", analyzer).parse(queryString); + SearchResultCollector collector = new SearchResultCollector(); + searcher.search(query, collector); + if (collector.docs.size() == 0) + { + JOptionPane.showMessageDialog(null, + "No matches were found for \"" + queryString + "\""); + return null; + } + Searcher metaSearcher = new IndexSearcher(metaDir()); + Vector<FileLine> results = new Vector<FileLine>(); + 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"))); + } + searcher.close(); + return results; + } +} + + Added: plugins/LucenePlugin/trunk/src/lucene/OptionPane.java =================================================================== --- plugins/LucenePlugin/trunk/src/lucene/OptionPane.java (rev 0) +++ plugins/LucenePlugin/trunk/src/lucene/OptionPane.java 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,65 @@ +package lucene; + +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; + +import org.gjt.sp.jedit.AbstractOptionPane; +import org.gjt.sp.jedit.jEdit; + +@SuppressWarnings("serial") +public class OptionPane extends AbstractOptionPane { + + public static final String PREFIX = "options.LucenePlugin."; + private static final String INDEX_PATH_OPTION = PREFIX + "index_path"; + private static final String INDEX_PATH_LABEL = INDEX_PATH_OPTION + ".label"; + private static final String EXCLUDE_DIRS_OPTION = PREFIX + "exclude_dirs"; + private static final String EXCLUDE_DIRS_LABEL = EXCLUDE_DIRS_OPTION + ".label"; + private static final String EXCLUDE_FILES_OPTION = PREFIX + "exclude_files"; + private static final String EXCLUDE_FILES_LABEL = EXCLUDE_FILES_OPTION + ".label"; + private static final String INCLUDE_FILES_OPTION = PREFIX + "include_files"; + private static final String INCLUDE_FILES_LABEL = INCLUDE_FILES_OPTION + ".label"; + + private JTextField indexPathTF; + private JTextField excludeDirsTF; + private JTextField includeFilesTF; + private JTextField excludeFilesTF; + + public OptionPane() { + super("LucenePlugin"); + setBorder(new EmptyBorder(5, 5, 5, 5)); + + indexPathTF = new JTextField(indexPath()); + addComponent(jEdit.getProperty(INDEX_PATH_LABEL), indexPathTF); + excludeDirsTF = new JTextField(excludeDirs()); + addComponent(jEdit.getProperty(EXCLUDE_DIRS_LABEL), excludeDirsTF); + includeFilesTF = new JTextField(includeFiles()); + addComponent(jEdit.getProperty(INCLUDE_FILES_LABEL), includeFilesTF); + excludeFilesTF = new JTextField(excludeFiles()); + addComponent(jEdit.getProperty(EXCLUDE_FILES_LABEL), excludeFilesTF); + } + public void save() + { + jEdit.setProperty(INDEX_PATH_OPTION, indexPathTF.getText()); + jEdit.setProperty(EXCLUDE_DIRS_OPTION, excludeDirsTF.getText()); + jEdit.setProperty(INCLUDE_FILES_OPTION, includeFilesTF.getText()); + jEdit.setProperty(EXCLUDE_FILES_OPTION, excludeFilesTF.getText()); + } + + static public String includeFiles() + { + return jEdit.getProperty(INCLUDE_FILES_OPTION); + } + static public String excludeFiles() + { + return jEdit.getProperty(EXCLUDE_FILES_OPTION); + } + static public String excludeDirs() + { + return jEdit.getProperty(EXCLUDE_DIRS_OPTION); + } + static public String indexPath() + { + return jEdit.getProperty(INDEX_PATH_OPTION); + } + +} Added: plugins/LucenePlugin/trunk/src/lucene/SearchResults.java =================================================================== --- plugins/LucenePlugin/trunk/src/lucene/SearchResults.java (rev 0) +++ plugins/LucenePlugin/trunk/src/lucene/SearchResults.java 2009-05-19 11:01:33 UTC (rev 15308) @@ -0,0 +1,59 @@ +package lucene; + +import java.awt.BorderLayout; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Vector; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +import marker.FileMarker; +import marker.tree.SourceLinkTree; +import marker.tree.SourceLinkTree.SourceLinkParentNode; + +import org.gjt.sp.jedit.View; + +@SuppressWarnings("serial") +public class SearchResults extends JPanel { + private JTextField symbolTF; + private SourceLinkTree tree; + + public SearchResults(final View view) + { + super(new BorderLayout()); + JPanel symbolPanel = new JPanel(new BorderLayout()); + add(symbolPanel, BorderLayout.NORTH); + symbolPanel.add(new JLabel("Search for:"), BorderLayout.WEST); + symbolTF = new JTextField(40); + symbolTF.addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) + search(symbolTF.getText()); + } + }); + symbolPanel.add(symbolTF, BorderLayout.CENTER); + tree = new SourceLinkTree(view); + add(new JScrollPane(tree), BorderLayout.CENTER); + } + public void search(String text) { + Vector<FileLine> lines; + try { + lines = LucenePlugin.search(text); + } catch (Exception e) { + e.printStackTrace(); + return; + } + tree.clear(); + if (lines == null) + return; + SourceLinkParentNode pn = tree.addSourceLinkParent(text); + for (int i = 0; i < lines.size(); i++) + { + FileLine line = lines.get(i); + pn.addSourceLink(new FileMarker(line.file, line.line - 1)); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2009-06-09 08:42:00
|
Revision: 15400 http://jedit.svn.sourceforge.net/jedit/?rev=15400&view=rev Author: kpouer Date: 2009-06-09 08:41:59 +0000 (Tue, 09 Jun 2009) Log Message: ----------- rewrote the plugin to create an easy to use api for lucene Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/actions.xml Added Paths: ----------- plugins/LucenePlugin/trunk/src/gatchan/ plugins/LucenePlugin/trunk/src/gatchan/jedit/ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-08 23:00:59 UTC (rev 15399) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-09 08:41:59 UTC (rev 15400) @@ -1,36 +1,8 @@ -plugin.lucene.LucenePlugin.activate=startup +plugin.gatchan.jedit.lucene.LucenePlugin.activate=defer -# general plugin information -plugin.lucene.LucenePlugin.name=LucenePlugin -plugin.lucene.LucenePlugin.author=Shlomy Reinstein -plugin.lucene.LucenePlugin.version=0.1 -plugin.lucene.LucenePlugin.depend.0=jdk 1.5 -plugin.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 -plugin.lucene.LucenePlugin.depend.2=plugin marker.MarkerSetsPlugin 0.1 - -# Options -plugin.lucene.LucenePlugin.option-pane=LucenePlugin -options.LucenePlugin.code=new lucene.OptionPane(); -options.LucenePlugin.label=LucenePlugin -options.LucenePlugin.index_path.label=Lucene index directory: -options.LucenePlugin.exclude_dirs.label=Exclude directories that match: -options.LucenePlugin.include_files.label=Include only files that match: -options.LucenePlugin.exclude_files.label=... except files that match: - -options.LucenePlugin.include_files=.*\\.([ch]|cpp|java|inl|rc|ds[pw]|txt)$ -options.LucenePlugin.exclude_dirs=(debug|bin|build|icons|\\.svn) - -# action labels -lucene-index.label=Index directory tree... -lucene-find.label=Find text... - -# menu items -plugin.lucene.LucenePlugin.menu=lucene-index lucene-find - -# docs -plugin.lucene.LucenePlugin.docs=index.html -plugin.lucene.LucenePlugin.description=LucenePlugin provides an interface to the Lucene engine. - -# dockables -lucene-search.title=Lucene Search -lucene-search.label=Lucene Search +plugin.gatchan.jedit.lucene.LucenePlugin.name=LucenePlugin +plugin.gatchan.jedit.lucene.LucenePlugin.author=Matthieu Casanova +plugin.gatchan.jedit.lucene.LucenePlugin.version=1.0 +plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 +plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 +plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar\ Modified: plugins/LucenePlugin/trunk/actions.xml =================================================================== --- plugins/LucenePlugin/trunk/actions.xml 2009-06-08 23:00:59 UTC (rev 15399) +++ plugins/LucenePlugin/trunk/actions.xml 2009-06-09 08:41:59 UTC (rev 15400) @@ -5,12 +5,16 @@ <ACTION NAME="lucene-find" NO_REPEAT="TRUE"> <CODE> - lucene.LucenePlugin.find(view); + gatchan.jedit.lucene.Index index = ((gatchan.jedit.lucene.LucenePlugin)jEdit.getPlugin("gatchan.jedit.lucene.LucenePlugin")).getIndex("jEdit"); + index.addFile("/home/kpouer/dev/jEdit"); + index.commit(); + </CODE> </ACTION> <ACTION NAME="lucene-index" NO_REPEAT="TRUE"> <CODE> - lucene.LucenePlugin.index(view); + gatchan.jedit.lucene.Index index = ((gatchan.jedit.lucene.LucenePlugin)jEdit.getPlugin("gatchan.jedit.lucene.LucenePlugin")).getIndex("jEdit"); + index.search("Matthieu"); </CODE> </ACTION> Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-09 08:41:59 UTC (rev 15400) @@ -0,0 +1,40 @@ +/* + * Index.java - The Index interface + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2009 Matthieu Casanova + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package gatchan.jedit.lucene; + +/** + * @author Matthieu Casanova + */ +public interface Index +{ + /** + * Release resources. + */ + void close(); + + void commit(); + + String getName(); + void addFile(String path); + void removeFile(String path); + + void search(String query); +} Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-09 08:41:59 UTC (rev 15400) @@ -0,0 +1,280 @@ +/* + * IndexImpl.java - The Index implementation + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2009 Matthieu Casanova + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package gatchan.jedit.lucene; + +import lucene.SourceCodeAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.Term; +import org.apache.lucene.queryParser.MultiFieldQueryParser; +import org.apache.lucene.queryParser.ParseException; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.*; +import org.apache.lucene.search.spans.SpanScorer; +import org.apache.lucene.search.highlight.Highlighter; +import org.apache.lucene.search.highlight.QueryScorer; +import org.gjt.sp.jedit.io.VFS; +import org.gjt.sp.jedit.io.VFSFile; +import org.gjt.sp.jedit.io.VFSManager; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.util.IOUtilities; +import org.gjt.sp.util.Log; + +import java.io.*; + +/** + * @author Matthieu Casanova + */ +public class IndexImpl implements Index +{ + private IndexWriter writer; + + private Searcher searcher; + + private String name; + private File path; + + + public IndexImpl(String name, File path) + { + this.name = name; + this.path = path; + } + + public void close() + { + closeWriter(); + if (searcher != null) + { + try + { + searcher.close(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to close searcher", e); + } + searcher = null; + } + } + + public String getName() + { + return name; + } + + public void addFile(String path) + { + openWriter(); + if (writer == null) + return; + Object session = null; + VFS vfs = VFSManager.getVFSForPath(path); + try + { + session = vfs.createVFSSession(path, jEdit.getActiveView()); + + VFSFile vfsFile = vfs._getFile(session, path, jEdit.getActiveView()); + addFile(vfsFile, session); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to add document " + path, e); + } + finally + { + try + { + vfs._endVFSSession(session, jEdit.getActiveView()); + } + catch (IOException e) + { + } + } + } + + private void addFile(VFSFile file, Object session) + { + if (file.getType() == VFSFile.DIRECTORY) + { + try + { + VFSFile[] vfsFiles = file.getVFS()._listFiles(session, file.getPath(), jEdit.getActiveView()); + for (VFSFile vfsFile : vfsFiles) + { + addFile(vfsFile, session); + } + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to lsit directory " + file.getPath(), e); + } + } + else if (file.getType() == VFSFile.FILE) + { + addDocument(file, session); + } + } + + public void removeFile(String path) + { + openWriter(); + if (writer == null) + return; + try + { + writer.deleteDocuments(new Term("path", path)); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to delete document " + path, e); + } + } + + public void search(String query) + { + openSearcher(); + if (searcher == null) + return; + SourceCodeAnalyzer analyzer = new SourceCodeAnalyzer(); + QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "content"}, analyzer); + try + { + Query _query = parser.parse(query); + TopDocs docs = searcher.search(_query, 100); + ScoreDoc[] scoreDocs = docs.scoreDocs; + Highlighter highlighter = new Highlighter(new QueryScorer(_query)); + for (ScoreDoc doc : scoreDocs) + { + Document document = searcher.doc(doc.doc); + Field field = document.getField("content"); +// analyzer.tokenStream("content", new StringReader()) + System.out.println(document.getField("path").stringValue()); + } + } + catch (ParseException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void commit() + { + if (writer != null) + { + try + { + writer.optimize(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Error while optimizing index", e); + } + closeWriter(); + } + if (searcher != null) + { + try + { + searcher.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + private void addDocument(VFSFile file, Object session) + { + Document doc = new Document(); + doc.add(new Field("path", file.getPath(), Field.Store.YES, Field.Index.ANALYZED)); + Reader reader = null; + try + { + reader = new BufferedReader(new InputStreamReader(file.getVFS()._createInputStream(session, file.getPath(), + false, + jEdit.getActiveView()))); + doc.add(new Field("content", reader)); + writer.updateDocument(new Term("path", file.getPath()), doc); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to read file " + path, e); + } + finally + { + IOUtilities.closeQuietly(reader); + } + } + + private void openWriter() + { + if (writer != null) + return; + try + { + path.mkdirs(); + writer = new IndexWriter(path, new SourceCodeAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to open IndexWriter", e); + } + } + + private void openSearcher() + { + if (searcher == null) + { + try + { + searcher = new IndexSearcher(path.getPath()); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + private void closeWriter() + { + if (writer != null) + { + try + { + writer.close(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to close IndexWriter", e); + } + writer = null; + } + } +} Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-09 08:41:59 UTC (rev 15400) @@ -0,0 +1,116 @@ +/* + * LucenePlugin.java - The Lucene plugin + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2009 Matthieu Casanova + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package gatchan.jedit.lucene; + +import org.gjt.sp.jedit.EBPlugin; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.io.VFS; +import org.gjt.sp.jedit.io.VFSManager; +import org.gjt.sp.util.Log; + +import java.util.Map; +import java.util.HashMap; +import java.io.File; +import java.io.IOException; + +/** + * @author Matthieu Casanova + */ +public class LucenePlugin extends EBPlugin +{ + private Map<String, Index> indexMap = new HashMap<String, Index>(); + + @Override + public void start() + { + super.start(); + } + + @Override + public void stop() + { + super.stop(); + } + + /** + * Return an index, or null. + * + * @param name the name of the index + * @return the index or null if there is no settings directory or the index cannot be + * created + */ + public Index getIndex(String name) + { + if (getIndexFile(name) == null) + return null; + + Index index = indexMap.get(name); + if (index == null) + { + index = new IndexImpl(name, getIndexFile(name)); + indexMap.put(name, index); + } + return index; + } + + public void removeIndex(String name) + { + Index index = indexMap.remove(name); + if (index != null) + index.close(); + File indexFile = getIndexFile(name); + if (indexFile == null) + return; + + VFS vfs = VFSManager.getVFSForPath(name); + Object session = vfs.createVFSSession(indexFile.getAbsolutePath(), jEdit.getActiveView()); + try + { + vfs._delete(session, indexFile.getAbsolutePath(), jEdit.getActiveView()); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, e); + } + finally + { + try + { + vfs._endVFSSession(session, jEdit.getActiveView()); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, e); + } + } + } + + private File getIndexFile(String name) + { + File home = getPluginHome(); + if (home == null) + return null; + return new File(home, name); + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2009-06-11 16:30:03
|
Revision: 15408 http://jedit.svn.sourceforge.net/jedit/?rev=15408&view=rev Author: kpouer Date: 2009-06-11 16:29:58 +0000 (Thu, 11 Jun 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/actions.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Added Paths: ----------- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-11 15:17:56 UTC (rev 15407) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-11 16:29:58 UTC (rev 15408) @@ -5,4 +5,4 @@ plugin.gatchan.jedit.lucene.LucenePlugin.version=1.0 plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 -plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar\ +plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar Modified: plugins/LucenePlugin/trunk/actions.xml =================================================================== --- plugins/LucenePlugin/trunk/actions.xml 2009-06-11 15:17:56 UTC (rev 15407) +++ plugins/LucenePlugin/trunk/actions.xml 2009-06-11 16:29:58 UTC (rev 15408) @@ -5,7 +5,7 @@ <ACTION NAME="lucene-find" NO_REPEAT="TRUE"> <CODE> - gatchan.jedit.lucene.Index index = ((gatchan.jedit.lucene.LucenePlugin)jEdit.getPlugin("gatchan.jedit.lucene.LucenePlugin")).getIndex("jEdit"); + gatchan.jedit.lucene.Index index = gatchan.jedit.lucene.LucenePlugin.instance.getIndex("jEdit"); index.addFile("/home/kpouer/dev/jEdit"); index.commit(); @@ -13,8 +13,8 @@ </ACTION> <ACTION NAME="lucene-index" NO_REPEAT="TRUE"> <CODE> - gatchan.jedit.lucene.Index index = ((gatchan.jedit.lucene.LucenePlugin)jEdit.getPlugin("gatchan.jedit.lucene.LucenePlugin")).getIndex("jEdit"); - index.search("Matthieu"); + gatchan.jedit.lucene.Index index = gatchan.jedit.lucene.LucenePlugin.instance.getIndex("jEdit"); + index.search("Matthieu", new gatchan.jedit.lucene.PrintResultProcessor()); </CODE> </ACTION> Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-06-11 16:29:58 UTC (rev 15408) @@ -0,0 +1,121 @@ +package gatchan.jedit.lucene; + +import org.gjt.sp.util.Log; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Searcher; + +import java.io.IOException; +import java.io.File; + +import lucene.SourceCodeAnalyzer; + +/** + * Created by IntelliJ IDEA. + * User: kpouer + * Date: 11 juin 2009 + * Time: 17:27:30 + * To change this template use File | Settings | File Templates. + */ +public class AbstractIndex +{ + protected IndexWriter writer; + protected Searcher searcher; + protected File path; + + public AbstractIndex(File path) + { + this.path = path; + } + + public void close() + { + closeWriter(); + if (searcher != null) + { + try + { + searcher.close(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to close searcher", e); + } + searcher = null; + } + } + + protected void openWriter() + { + if (writer != null) + return; + try + { + path.mkdirs(); + writer = new IndexWriter(path, new SourceCodeAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to open IndexWriter", e); + } + } + + protected void openSearcher() + { + if (searcher == null) + { + try + { + searcher = new IndexSearcher(path.getPath()); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + protected void closeWriter() + { + if (writer != null) + { + try + { + writer.close(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to close IndexWriter", e); + } + writer = null; + } + } + + public void commit() + { + if (writer != null) + { + try + { + writer.optimize(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Error while optimizing index", e); + } + closeWriter(); + } + if (searcher != null) + { + try + { + searcher.close(); + searcher = null; + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } +} Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2009-06-11 16:29:58 UTC (rev 15408) @@ -0,0 +1,140 @@ +/* + * CentralIndex.java - The Central Index + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2009 Matthieu Casanova + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +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.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; +import java.io.IOException; + +/** + * @author Matthieu Casanova + */ +public class CentralIndex extends AbstractIndex implements EBComponent +{ + private QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "indexName"},new StandardAnalyzer()); + + public CentralIndex(File indexFile) + { + super(indexFile); + } + + void addFile(String path, String indexName) + { + openWriter(); + openSearcher(); + + try + { + Query query = parser.parse("+path:"+path+" +indexName:"+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)); + writer.addDocument(document); + } + } + catch (ParseException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + 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); + writer.deleteDocuments(query); + } + catch (ParseException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void handleMessage(EBMessage message) + { + if (message instanceof BufferUpdate) + { + BufferUpdate bufferUpdate = (BufferUpdate) message; + if (bufferUpdate.getWhat() == BufferUpdate.SAVED) + { + fileUpdated(bufferUpdate.getBuffer()); + } + } + } + + private void fileUpdated(Buffer buffer) + { + try + { + Query query = parser.parse("path:" + buffer.getPath()); + openSearcher(); + TopDocs docs = searcher.search(query, 100); + ScoreDoc[] scoreDocs = docs.scoreDocs; + for (ScoreDoc doc : scoreDocs) + { + Document document = searcher.doc(doc.doc); + String indexName = document.getField("indexName").stringValue(); + Index index = LucenePlugin.instance.getIndex(indexName); + if (index != null) + { + index.addFile(document.getField("path").stringValue()); + } + } + } + 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-11 15:17:56 UTC (rev 15407) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-11 16:29:58 UTC (rev 15408) @@ -24,15 +24,13 @@ import lucene.SourceCodeAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.queryParser.MultiFieldQueryParser; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; -import org.apache.lucene.search.*; -import org.apache.lucene.search.spans.SpanScorer; -import org.apache.lucene.search.highlight.Highlighter; -import org.apache.lucene.search.highlight.QueryScorer; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; import org.gjt.sp.jedit.io.VFS; import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.io.VFSManager; @@ -45,39 +43,16 @@ /** * @author Matthieu Casanova */ -public class IndexImpl implements Index +public class IndexImpl extends AbstractIndex implements Index { - private IndexWriter writer; - - private Searcher searcher; - private String name; - private File path; - public IndexImpl(String name, File path) { + super(path); this.name = name; - this.path = path; } - public void close() - { - closeWriter(); - if (searcher != null) - { - try - { - searcher.close(); - } - catch (IOException e) - { - Log.log(Log.ERROR, this, "Unable to close searcher", e); - } - searcher = null; - } - } - public String getName() { return name; @@ -111,6 +86,7 @@ { } } + LucenePlugin.CENTRAL.commit(); } private void addFile(VFSFile file, Object session) @@ -144,6 +120,7 @@ try { writer.deleteDocuments(new Term("path", path)); + LucenePlugin.CENTRAL.removeFile(path, name); } catch (IOException e) { @@ -163,7 +140,6 @@ Query _query = parser.parse(query); TopDocs docs = searcher.search(_query, 100); ScoreDoc[] scoreDocs = docs.scoreDocs; - Highlighter highlighter = new Highlighter(new QueryScorer(_query)); for (ScoreDoc doc : scoreDocs) { Document document = searcher.doc(doc.doc); @@ -183,35 +159,9 @@ } } - public void commit() - { - if (writer != null) - { - try - { - writer.optimize(); - } - catch (IOException e) - { - Log.log(Log.ERROR, this, "Error while optimizing index", e); - } - closeWriter(); - } - if (searcher != null) - { - try - { - searcher.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - private void addDocument(VFSFile file, Object session) { + 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)); Reader reader = null; @@ -221,6 +171,7 @@ false, jEdit.getActiveView()))); doc.add(new Field("content", reader)); + LucenePlugin.CENTRAL.addFile(file.getPath(), name); writer.updateDocument(new Term("path", file.getPath()), doc); } catch (IOException e) @@ -233,49 +184,4 @@ } } - private void openWriter() - { - if (writer != null) - return; - try - { - path.mkdirs(); - writer = new IndexWriter(path, new SourceCodeAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); - } - catch (IOException e) - { - Log.log(Log.ERROR, this, "Unable to open IndexWriter", e); - } - } - - private void openSearcher() - { - if (searcher == null) - { - try - { - searcher = new IndexSearcher(path.getPath()); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - - private void closeWriter() - { - if (writer != null) - { - try - { - writer.close(); - } - catch (IOException e) - { - Log.log(Log.ERROR, this, "Unable to close IndexWriter", e); - } - writer = null; - } - } } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-11 15:17:56 UTC (rev 15407) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-11 16:29:58 UTC (rev 15408) @@ -21,34 +21,43 @@ package gatchan.jedit.lucene; -import org.gjt.sp.jedit.EBPlugin; -import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.EditBus; +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.jEdit; import org.gjt.sp.util.Log; -import java.util.Map; -import java.util.HashMap; import java.io.File; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; /** * @author Matthieu Casanova */ -public class LucenePlugin extends EBPlugin +public class LucenePlugin extends EditPlugin { + static CentralIndex CENTRAL; + private static final String CENTRAL_INDEX_NAME = "__CENTRAL__"; private Map<String, Index> indexMap = new HashMap<String, Index>(); + public static LucenePlugin instance; @Override public void start() { - super.start(); + instance = this; + CENTRAL = new CentralIndex(getIndexFile(CENTRAL_INDEX_NAME)); + EditBus.addToBus(CENTRAL); } @Override public void stop() { - super.stop(); + EditBus.removeFromBus(CENTRAL); + CENTRAL.close(); + CENTRAL = null; + instance = null; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Kp...@us...> - 2009-06-11 23:44:47
|
Revision: 15423 http://jedit.svn.sourceforge.net/jedit/?rev=15423&view=rev Author: Kpouer Date: 2009-06-11 23:44:45 +0000 (Thu, 11 Jun 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Added Paths: ----------- plugins/LucenePlugin/trunk/browser.actions.xml Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-11 23:11:29 UTC (rev 15422) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-11 23:44:45 UTC (rev 15423) @@ -6,3 +6,4 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar +plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene-add-to-index lucene-add-to-newindex \ No newline at end of file Copied: plugins/LucenePlugin/trunk/browser.actions.xml (from rev 15418, plugins/LucenePlugin/trunk/actions.xml) =================================================================== --- plugins/LucenePlugin/trunk/browser.actions.xml (rev 0) +++ plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-11 23:44:45 UTC (rev 15423) @@ -0,0 +1,24 @@ +<!DOCTYPE ACTIONS SYSTEM "actions.dtd"> +<ACTIONS> + <ACTION NAME="lucene-add-to-index" NO_REPEAT="TRUE"> + <CODE> + gatchan.jedit.lucene.LucenePlugin.instance.chooseIndex(); + + + + + </CODE> + </ACTION> + <ACTION NAME="lucene-add-to-newindex" NO_REPEAT="TRUE"> + <CODE> + String name = JOptionPane.showInputDialog(jEdit.getActiveView(), "Choose an index name", "Create an index", JOptionPane.QUESTION_MESSAGE); + gatchan.jedit.lucene.Index index = gatchan.jedit.lucene.LucenePlugin.instance.getIndex(name); + for (int i = 0;i < files.length; i++) + { + index.addFile(files[i].getPath()); + } + index.commit(); + </CODE> + </ACTION> +</ACTIONS> + Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-11 23:11:29 UTC (rev 15422) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-11 23:44:45 UTC (rev 15423) @@ -28,8 +28,10 @@ import org.gjt.sp.jedit.jEdit; import org.gjt.sp.util.Log; +import javax.swing.*; import java.io.File; import java.io.IOException; +import java.io.FileFilter; import java.util.HashMap; import java.util.Map; @@ -118,6 +120,22 @@ } } + public Index chooseIndex() + { + File home = getPluginHome(); + File[] indexes = home.listFiles(new FileFilter() + { + public boolean accept(File pathname) + { + return pathname.isDirectory(); + } + }); + + Object ret = JOptionPane.showInputDialog(jEdit.getActiveView(), "Choose an index", "Choose an index", JOptionPane.QUESTION_MESSAGE, null, indexes,null); + System.out.println(ret); + return null; + } + private File getIndexFile(String name) { File home = getPluginHome(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Kp...@us...> - 2009-06-12 11:00:08
|
Revision: 15427 http://jedit.svn.sourceforge.net/jedit/?rev=15427&view=rev Author: Kpouer Date: 2009-06-12 11:00:07 +0000 (Fri, 12 Jun 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/browser.actions.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-12 01:19:27 UTC (rev 15426) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-12 11:00:07 UTC (rev 15427) @@ -1,4 +1,4 @@ -plugin.gatchan.jedit.lucene.LucenePlugin.activate=defer +plugin.gatchan.jedit.lucene.LucenePlugin.activate=startup plugin.gatchan.jedit.lucene.LucenePlugin.name=LucenePlugin plugin.gatchan.jedit.lucene.LucenePlugin.author=Matthieu Casanova @@ -6,4 +6,9 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar -plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene-add-to-index lucene-add-to-newindex \ No newline at end of file +plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene.add-to-index lucene.add-to-newindex +plugin.gatchan.jedit.lucene.LucenePlugin.usePluginHome=true + + +lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> +lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> \ No newline at end of file Modified: plugins/LucenePlugin/trunk/browser.actions.xml =================================================================== --- plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-12 01:19:27 UTC (rev 15426) +++ plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-12 11:00:07 UTC (rev 15427) @@ -1,24 +1,18 @@ <!DOCTYPE ACTIONS SYSTEM "actions.dtd"> <ACTIONS> - <ACTION NAME="lucene-add-to-index" NO_REPEAT="TRUE"> + <ACTION NAME="lucene.add-to-index" NO_REPEAT="TRUE"> <CODE> - gatchan.jedit.lucene.LucenePlugin.instance.chooseIndex(); - - - - - </CODE> + String indexName = gatchan.jedit.lucene.LucenePlugin.instance.chooseIndex(); + if (indexName != null) + gatchan.jedit.lucene.LucenePlugin.instance.addToIndex(indexName, files); + </CODE> </ACTION> - <ACTION NAME="lucene-add-to-newindex" NO_REPEAT="TRUE"> + <ACTION NAME="lucene.add-to-newindex" NO_REPEAT="TRUE"> <CODE> - String name = JOptionPane.showInputDialog(jEdit.getActiveView(), "Choose an index name", "Create an index", JOptionPane.QUESTION_MESSAGE); - gatchan.jedit.lucene.Index index = gatchan.jedit.lucene.LucenePlugin.instance.getIndex(name); - for (int i = 0;i < files.length; i++) - { - index.addFile(files[i].getPath()); - } - index.commit(); - </CODE> + String indexName = Macros.input(view, "Choose an index name"); + if (indexName != null) + gatchan.jedit.lucene.LucenePlugin.instance.addToIndex(indexName, files); + </CODE> </ACTION> </ACTIONS> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-12 01:19:27 UTC (rev 15426) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-12 11:00:07 UTC (rev 15427) @@ -21,6 +21,7 @@ package gatchan.jedit.lucene; +import org.apache.lucene.index.IndexFileNameFilter; import org.gjt.sp.jedit.EditBus; import org.gjt.sp.jedit.EditPlugin; import org.gjt.sp.jedit.io.VFS; @@ -31,7 +32,6 @@ import javax.swing.*; import java.io.File; import java.io.IOException; -import java.io.FileFilter; import java.util.HashMap; import java.util.Map; @@ -45,6 +45,7 @@ private Map<String, Index> indexMap = new HashMap<String, Index>(); public static LucenePlugin instance; + @Override public void start() { @@ -67,7 +68,7 @@ * * @param name the name of the index * @return the index or null if there is no settings directory or the index cannot be - * created + * created */ public Index getIndex(String name) { @@ -85,6 +86,7 @@ /** * Delete an index. + * * @param name the name of the index. */ public void removeIndex(String name) @@ -120,20 +122,47 @@ } } - public Index chooseIndex() + public String chooseIndex() { File home = getPluginHome(); - File[] indexes = home.listFiles(new FileFilter() + File[] indexes = home.listFiles(new IndexFileNameFilter()); + if (indexes.length == 0) + return null; + String[] names = new String[indexes.length]; + for (int i = 0; i < names.length; i++) { - public boolean accept(File pathname) + names[i] = indexes[i].getName(); + } + String name = (String) JOptionPane.showInputDialog(jEdit.getActiveView(), "Choose an index", "Choose an index", + JOptionPane.QUESTION_MESSAGE, null, names, null); + return name; + } + + /** + * Add some files to the given index. + * + * @param indexName the index name + * @param files the file array to add + */ + public void addToIndex(final String indexName, final File[] files) + { + VFSManager.runInWorkThread(new Runnable() + { + public void run() { - return pathname.isDirectory(); + Index index = getIndex(indexName); + if (index == null) + { + Log.log(Log.ERROR, this, "Unable to get index " + indexName); + return; + } + for (File file : files) + { + index.addFile(file.getPath()); + } + index.commit(); } }); - - Object ret = JOptionPane.showInputDialog(jEdit.getActiveView(), "Choose an index", "Choose an index", JOptionPane.QUESTION_MESSAGE, null, indexes,null); - System.out.println(ret); - return null; } private File getIndexFile(String name) @@ -143,6 +172,4 @@ return null; return new File(home, name); } - - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Kp...@us...> - 2009-06-12 19:41:00
|
Revision: 15435 http://jedit.svn.sourceforge.net/jedit/?rev=15435&view=rev Author: Kpouer Date: 2009-06-12 19:40:31 +0000 (Fri, 12 Jun 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/dockables.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java Added Paths: ----------- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java Removed Paths: ------------- plugins/LucenePlugin/trunk/actions.xml Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-12 17:17:23 UTC (rev 15434) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-12 19:40:31 UTC (rev 15435) @@ -7,8 +7,11 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene.add-to-index lucene.add-to-newindex +plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search plugin.gatchan.jedit.lucene.LucenePlugin.usePluginHome=true lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> -lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> \ No newline at end of file +lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> +lucene-search.label=Search +lucene-search.title=Search with Lucene \ No newline at end of file Deleted: plugins/LucenePlugin/trunk/actions.xml =================================================================== --- plugins/LucenePlugin/trunk/actions.xml 2009-06-12 17:17:23 UTC (rev 15434) +++ plugins/LucenePlugin/trunk/actions.xml 2009-06-12 19:40:31 UTC (rev 15435) @@ -1,22 +0,0 @@ -<!DOCTYPE ACTIONS SYSTEM "actions.dtd"> -<!-- $Id: actions.xml 7606 2004-11-07 15:52:36Z orutherfurd $ --> - -<ACTIONS> - - <ACTION NAME="lucene-find" NO_REPEAT="TRUE"> - <CODE> - gatchan.jedit.lucene.Index index = gatchan.jedit.lucene.LucenePlugin.instance.getIndex("jEdit"); - index.addFile("/home/kpouer/dev/jEdit"); - index.commit(); - - </CODE> - </ACTION> - <ACTION NAME="lucene-index" NO_REPEAT="TRUE"> - <CODE> - gatchan.jedit.lucene.Index index = gatchan.jedit.lucene.LucenePlugin.instance.getIndex("jEdit"); - index.search("Matthieu", new gatchan.jedit.lucene.PrintResultProcessor()); - </CODE> - </ACTION> - -</ACTIONS> - Modified: plugins/LucenePlugin/trunk/dockables.xml =================================================================== --- plugins/LucenePlugin/trunk/dockables.xml 2009-06-12 17:17:23 UTC (rev 15434) +++ plugins/LucenePlugin/trunk/dockables.xml 2009-06-12 19:40:31 UTC (rev 15435) @@ -4,7 +4,7 @@ <DOCKABLES> <DOCKABLE NAME="lucene-search" MOVABLE="TRUE"> - new lucene.SearchResults(view); + new gatchan.jedit.lucene.SearchResults(); </DOCKABLE> </DOCKABLES> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java 2009-06-12 17:17:23 UTC (rev 15434) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java 2009-06-12 19:40:31 UTC (rev 15435) @@ -21,6 +21,7 @@ package gatchan.jedit.lucene; import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.Query; import org.apache.lucene.document.Document; /** Copied: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java (from rev 15418, plugins/LucenePlugin/trunk/src/lucene/SearchResults.java) =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-12 19:40:31 UTC (rev 15435) @@ -0,0 +1,105 @@ +package gatchan.jedit.lucene; + +import org.gjt.sp.jedit.jEdit; + +import javax.swing.*; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +public class SearchResults extends JPanel +{ + private JTextField searchField; + private JList list; + private JComboBox indexes; + private MyModel model; +// private JTextPane preview; + + public SearchResults() + { + super(new BorderLayout()); + String[] items = LucenePlugin.instance.getIndexes(); + if (items == null) + { + indexes = new JComboBox(); + } + else + { + + indexes = new JComboBox(items); + } + JPanel panel = new JPanel(new BorderLayout()); + add(panel, BorderLayout.NORTH); + panel.add(new JLabel("Search for:"), BorderLayout.WEST); + searchField = new JTextField(40); + searchField.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + search(searchField.getText()); + } + }); + + panel.add(searchField, BorderLayout.CENTER); + panel.add(indexes, BorderLayout.EAST); + model = new MyModel(); + list = new JList(model); + + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.getSelectionModel().addListSelectionListener(new ListSelectionListener() + { + public void valueChanged(ListSelectionEvent e) + { + String path = (String) list.getSelectedValue(); + jEdit.openFile(jEdit.getActiveView(), path); + } + }); +// HTMLDocument htmlDocument = new HTMLDocument(); +// preview = new JTextPane(htmlDocument); +// preview.setContentType("text/html"); + add(new JScrollPane(list), BorderLayout.CENTER); +// add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(list), preview), BorderLayout.CENTER); + } + + public void search(String text) + { + Index index = LucenePlugin.instance.getIndex((String) indexes.getSelectedItem()); + if (index == null) + return; + + final java.util.List<String> files = new ArrayList<String>(); + index.search(text, new ResultProcessor() + { + public boolean process(float score, Result result) + { + files.add(result.getPath()); + return true; + } + }); + model.setFiles(files); + } + + private static class MyModel extends AbstractListModel + { + private java.util.List<String> files = new ArrayList<String>(); + + public void setFiles(java.util.List<String> files) + { + this.files = files; + fireContentsChanged(this, 0, files.size()); + } + + public int getSize() + { + return files.size(); + } + + public Object getElementAt(int index) + { + return files.get(index); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-06-15 08:57:01
|
Revision: 15451 http://jedit.svn.sourceforge.net/jedit/?rev=15451&view=rev Author: shlomy Date: 2009-06-15 08:56:57 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Configurable index type - file-base or line-based, and configurable analyzer. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/browser.actions.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Result.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java Added Paths: ----------- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexFactory.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-15 08:56:57 UTC (rev 15451) @@ -6,12 +6,19 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar -plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene.add-to-index lucene.add-to-newindex +plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene.add-to-index lucene.add-to-newindex lucene.add-to-new-line-index plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search plugin.gatchan.jedit.lucene.LucenePlugin.usePluginHome=true lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> +lucene.add-to-new-line-index.label=<html>Add selected file(s) to a <b>new line index</b></html> lucene-search.label=Search -lucene-search.title=Search with Lucene \ No newline at end of file +lucene-search.title=Search with Lucene + +lucene.message.NewIndexDialogTitle=New Lucene Index +lucene.message.IndexName=Name: +lucene.message.IndexType=Type: +lucene.message.Analyzer=Analyzer: + Modified: plugins/LucenePlugin/trunk/browser.actions.xml =================================================================== --- plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-15 08:56:57 UTC (rev 15451) @@ -9,9 +9,10 @@ </ACTION> <ACTION NAME="lucene.add-to-newindex" NO_REPEAT="TRUE"> <CODE> - String indexName = Macros.input(view, "Choose an index name"); + import gatchan.jedit.lucene.LucenePlugin; + String indexName = LucenePlugin.instance.createNewIndex(); if (indexName != null) - gatchan.jedit.lucene.LucenePlugin.instance.addToIndex(indexName, files); + LucenePlugin.instance.addToIndex(indexName, files); </CODE> </ACTION> </ACTIONS> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -21,6 +21,7 @@ package gatchan.jedit.lucene; import org.gjt.sp.util.Log; +import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Searcher; @@ -38,12 +39,29 @@ protected IndexWriter writer; protected Searcher searcher; protected File path; + protected Analyzer analyzer; + protected String name; + public AbstractIndex() + { + } + public AbstractIndex(File path) { this.path = path; } + public void setData(String name, File path) + { + this.name = name; + this.path = path; + } + + public String getName() + { + return name; + } + public void close() { closeWriter(); @@ -68,7 +86,7 @@ try { path.mkdirs(); - writer = new IndexWriter(path, new SourceCodeAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); + writer = new IndexWriter(path, getAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); } catch (IOException e) { @@ -134,4 +152,16 @@ } } } + + public void setAnalyzer(Analyzer analyzer) + { + this.analyzer = analyzer; + } + + public Analyzer getAnalyzer() + { + if (analyzer == null) + analyzer = new SourceCodeAnalyzer(); + return analyzer; + } } Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -0,0 +1,36 @@ +package gatchan.jedit.lucene; + +import java.util.HashMap; + +import lucene.SourceCodeAnalyzer; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.KeywordAnalyzer; +import org.apache.lucene.analysis.SimpleAnalyzer; +import org.apache.lucene.analysis.StopAnalyzer; +import org.apache.lucene.analysis.WhitespaceAnalyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; + +public class AnalyzerFactory { + static final HashMap<String, Analyzer> analyzers = new HashMap<String, Analyzer>(); + + static { + analyzers.put("Standard", new StandardAnalyzer()); + analyzers.put("Simple", new SimpleAnalyzer()); + analyzers.put("Java identifier", new SourceCodeAnalyzer()); + analyzers.put("Whitespace", new WhitespaceAnalyzer()); + analyzers.put("Keyword", new KeywordAnalyzer()); + analyzers.put("Stop", new StopAnalyzer()); + } + + static String [] getAnalyzerNames() + { + String [] names = new String[analyzers.size()]; + analyzers.keySet().toArray(names); + return names; + } + static Analyzer getAnalyzer(String name) + { + return analyzers.get(name); + } +} Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -20,6 +20,10 @@ */ package gatchan.jedit.lucene; +import java.io.File; + +import org.apache.lucene.analysis.Analyzer; + /** * @author Matthieu Casanova */ @@ -36,6 +40,9 @@ void addFile(String path); void removeFile(String path); + void setData(String name, File path); + void setAnalyzer(Analyzer analyzer); + /** * Execute the given search query. * Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexFactory.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexFactory.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexFactory.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -0,0 +1,38 @@ +package gatchan.jedit.lucene; + +import java.util.HashMap; + + +public class IndexFactory +{ + private static HashMap<String, Class> indexes = new HashMap<String, Class>(); + + static { + register("File-based index", IndexImpl.class); + register("Line-based index", LineIndexImpl.class); + } + + public static void register(String name, Class cls) + { + indexes.put(name, cls); + } + public static String [] getIndexNames() + { + String [] names = new String[indexes.size()]; + indexes.keySet().toArray(names); + return names; + } + public static Index createIndex(String name) + { + Class c = indexes.get(name); + if (c == null) + return null; + Index index = null; + try { + index = (Index) c.newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + return index; + } +} Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -21,7 +21,11 @@ package gatchan.jedit.lucene; -import lucene.SourceCodeAnalyzer; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.Term; @@ -31,33 +35,18 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; +import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.io.VFS; import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.io.VFSManager; -import org.gjt.sp.jedit.jEdit; import org.gjt.sp.util.IOUtilities; import org.gjt.sp.util.Log; -import java.io.*; - /** * @author Matthieu Casanova */ public class IndexImpl extends AbstractIndex implements Index { - private String name; - - public IndexImpl(String name, File path) - { - super(path); - this.name = name; - } - - public String getName() - { - return name; - } - public void addFile(String path) { openWriter(); @@ -133,8 +122,8 @@ openSearcher(); if (searcher == null) return; - SourceCodeAnalyzer analyzer = new SourceCodeAnalyzer(); - QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "content"}, analyzer); + QueryParser parser = new MultiFieldQueryParser( + new String[]{"path", "content"}, getAnalyzer()); try { Query _query = parser.parse(query); @@ -161,7 +150,7 @@ } } - private void addDocument(VFSFile file, Object session) + protected void addDocument(VFSFile file, Object session) { Log.log(Log.DEBUG, this, "Index:"+name + " add " + file); Document doc = new Document(); @@ -186,5 +175,4 @@ IOUtilities.closeQuietly(reader); } } - } Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -0,0 +1,91 @@ +package gatchan.jedit.lucene; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import lucene.SourceCodeAnalyzer; + +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.Term; +import org.apache.lucene.queryParser.MultiFieldQueryParser; +import org.apache.lucene.queryParser.ParseException; +import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.io.VFSFile; +import org.gjt.sp.util.IOUtilities; +import org.gjt.sp.util.Log; + +public class LineIndexImpl extends IndexImpl +{ + protected void addDocument(VFSFile file, Object session) + { + Log.log(Log.DEBUG, this, "Index:"+getName() + " add " + file); + BufferedReader reader = null; + try + { + reader = new BufferedReader(new InputStreamReader( + file.getVFS()._createInputStream(session, file.getPath(), false, + jEdit.getActiveView()))); + String line = null; + int i = 0; + while ((line = reader.readLine()) != null) + { + Document doc = new Document(); + 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)); + i++; + doc.add(new Field("line", String.valueOf(i), Field.Store.YES, Field.Index.NOT_ANALYZED)); + doc.add(new Field("content", line, Field.Store.YES, Field.Index.ANALYZED)); + writer.updateDocument(new Term("_path", file.getPath()), doc); + } + LucenePlugin.CENTRAL.addFile(file.getPath(), getName()); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Unable to read file " + path, e); + } + finally + { + IOUtilities.closeQuietly(reader); + } + } + + @Override + public void search(String query, ResultProcessor processor) + { + openSearcher(); + if (searcher == null) + return; + SourceCodeAnalyzer analyzer = new SourceCodeAnalyzer(); + QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "content"}, analyzer); + try + { + Query _query = parser.parse(query); + TopDocs docs = searcher.search(_query, 100); + ScoreDoc[] scoreDocs = docs.scoreDocs; + LineResult result = new LineResult(); + for (ScoreDoc doc : scoreDocs) + { + Document document = searcher.doc(doc.doc); + result.setDocument(document); + if (!processor.process(doc.score, result)) + { + break; + } + } + } + catch (ParseException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } +} Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -0,0 +1,9 @@ +package gatchan.jedit.lucene; + +public class LineResult extends Result +{ + public int getLine() + { + return Integer.valueOf(getDocument().getField("line").stringValue()); + } +} Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -21,6 +21,7 @@ package gatchan.jedit.lucene; +import org.apache.lucene.analysis.Analyzer; import org.gjt.sp.jedit.EditBus; import org.gjt.sp.jedit.EditPlugin; import org.gjt.sp.jedit.io.VFS; @@ -73,25 +74,34 @@ * Return an index, or null. * * @param name the name of the index - * @return the index or null if there is no settings directory or the index cannot be - * created + * @return the index or null if there is no settings directory. */ public Index getIndex(String name) { if (getIndexFile(name) == null) return null; + return indexMap.get(name); + } - Index index = indexMap.get(name); + public Index createIndex(String name, String type, String analyzerName) + { + Index index = getIndex(name); + if (index != null) + return index; + + File path = getIndexFile(name); + index = IndexFactory.createIndex(type); if (index == null) + return null; + index.setData(name, path); + Analyzer analyzer = AnalyzerFactory.getAnalyzer(analyzerName); + if (analyzer != null) + index.setAnalyzer(analyzer); + indexMap.put(name, index); + if (!path.exists()) { - File path = getIndexFile(name); - index = new IndexImpl(name, path); - indexMap.put(name, index); - if (!path.exists()) - { - path.mkdirs(); - CENTRAL.createIndex(index); - } + path.mkdirs(); + CENTRAL.createIndex(index); } return index; } @@ -142,6 +152,23 @@ return name; } + /* + * Open the new index dialog. + * Returns the name of the new index, or null if cancelled. + */ + public String createNewIndex() + { + NewIndexDialog dlg = new NewIndexDialog(jEdit.getActiveView()); + dlg.setVisible(true); + if (! dlg.accepted()) + return null; + Index index = createIndex(dlg.getIndexName(), dlg.getIndexType(), + dlg.getIndexAnalyzer()); + if (index == null) + return null; + return index.getName(); + } + /** * Add some files to the given index. * Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -0,0 +1,130 @@ +package gatchan.jedit.lucene; + +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.KeyStroke; + +import org.gjt.sp.jedit.GUIUtilities; +import org.gjt.sp.jedit.jEdit; + +public class NewIndexDialog extends JDialog +{ + static public final String OPTION = "lucene.option."; + static public final String MESSAGE = "lucene.message."; + static private String GEOMETRY = OPTION + "NewLuceneIndexDialog"; + private JTextField name; + private JComboBox type; + private JComboBox analyzer; + private boolean accepted = false; + + private void saveGeometry() + { + GUIUtilities.saveGeometry(this, GEOMETRY); + } + + public NewIndexDialog(Frame frame) { + super(frame, jEdit.getProperty(MESSAGE + "NewIndexDialogTitle"), true); + addWindowListener(new java.awt.event.WindowAdapter() + { + public void windowClosing(java.awt.event.WindowEvent evt) + { + saveGeometry(); + } + }); + setLayout(new GridLayout(0, 1)); + // Name panel + JPanel p = new JPanel(); + add(p); + p.add(new JLabel(jEdit.getProperty(MESSAGE + "IndexName"))); + name = new JTextField(30); + p.add(name); + // Index type panel + p = new JPanel(); + add(p); + p.add(new JLabel(jEdit.getProperty(MESSAGE + "IndexType"))); + type = new JComboBox(IndexFactory.getIndexNames()); + p.add(type); + // Analyzer panel + p = new JPanel(); + add(p); + p.add(new JLabel(jEdit.getProperty(MESSAGE + "Analyzer"))); + analyzer = new JComboBox(AnalyzerFactory.getAnalyzerNames()); + p.add(analyzer); + // Button panel + JPanel buttons = new JPanel(); + add(buttons); + final JButton ok = new JButton("Ok"); + buttons.add(ok); + final JButton cancel = new JButton("Cancel"); + buttons.add(cancel); + ok.addActionListener( + new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + saveGeometry(); + save(); + setVisible(false); + } + } + ); + cancel.addActionListener( + new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + setVisible(false); + } + } + ); + + KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + ActionListener cancelListener = + new ActionListener() + { + public void actionPerformed(ActionEvent arg0) + { + cancel.doClick(); + } + }; + rootPane.registerKeyboardAction(cancelListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); + pack(); + GUIUtilities.loadGeometry(this, GEOMETRY); + } + + private void save() + { + accepted = true; + } + + public String getIndexName() + { + return name.getText(); + } + + public String getIndexAnalyzer() + { + return analyzer.getSelectedItem().toString(); + } + + public String getIndexType() + { + return type.getSelectedItem().toString(); + } + + public boolean accepted() + { + return accepted; + } +} Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Result.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Result.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Result.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -27,7 +27,7 @@ */ public class Result { - private Document document; + public Document document; public Result() { @@ -38,6 +38,11 @@ this.document = document; } + public Document getDocument() + { + return document; + } + public String getPath() { return document.getField("_path").stringValue(); Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -20,9 +20,6 @@ */ package gatchan.jedit.lucene; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Query; -import org.apache.lucene.document.Document; /** * @author Matthieu Casanova Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-15 08:12:07 UTC (rev 15450) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-15 08:56:57 UTC (rev 15451) @@ -74,7 +74,10 @@ { public boolean process(float score, Result result) { - files.add(result.getPath()); + String s = result.getPath(); + if (result instanceof LineResult) + s += ":" + ((LineResult)result).getLine(); + files.add(s); return true; } }); @@ -180,4 +183,4 @@ return selectedItem; } } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-06-15 13:14:35
|
Revision: 15453 http://jedit.svn.sourceforge.net/jedit/?rev=15453&view=rev Author: shlomy Date: 2009-06-15 12:35:57 +0000 (Mon, 15 Jun 2009) Log Message: ----------- Fixed LineIndexImpl to work correctly; improved the results for line based index. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-15 09:21:03 UTC (rev 15452) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-15 12:35:57 UTC (rev 15453) @@ -6,14 +6,14 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar -plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=lucene.add-to-index lucene.add-to-newindex lucene.add-to-new-line-index +plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=\ + lucene.add-to-index lucene.add-to-newindex plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search plugin.gatchan.jedit.lucene.LucenePlugin.usePluginHome=true lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> -lucene.add-to-new-line-index.label=<html>Add selected file(s) to a <b>new line index</b></html> lucene-search.label=Search lucene-search.title=Search with Lucene Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java 2009-06-15 09:21:03 UTC (rev 15452) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java 2009-06-15 12:35:57 UTC (rev 15453) @@ -4,8 +4,6 @@ import java.io.IOException; import java.io.InputStreamReader; -import lucene.SourceCodeAnalyzer; - import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.Term; @@ -28,6 +26,8 @@ BufferedReader reader = null; try { + writer.deleteDocuments(new Term("_path", file.getPath())); + LucenePlugin.CENTRAL.removeFile(file.getPath(), getName()); reader = new BufferedReader(new InputStreamReader( file.getVFS()._createInputStream(session, file.getPath(), false, jEdit.getActiveView()))); @@ -41,7 +41,7 @@ i++; doc.add(new Field("line", String.valueOf(i), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("content", line, Field.Store.YES, Field.Index.ANALYZED)); - writer.updateDocument(new Term("_path", file.getPath()), doc); + writer.addDocument(doc); } LucenePlugin.CENTRAL.addFile(file.getPath(), getName()); } @@ -61,8 +61,8 @@ openSearcher(); if (searcher == null) return; - SourceCodeAnalyzer analyzer = new SourceCodeAnalyzer(); - QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "content"}, analyzer); + QueryParser parser = new MultiFieldQueryParser( + new String[]{"path", "content"}, getAnalyzer()); try { Query _query = parser.parse(query); Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java 2009-06-15 09:21:03 UTC (rev 15452) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineResult.java 2009-06-15 12:35:57 UTC (rev 15453) @@ -6,4 +6,14 @@ { return Integer.valueOf(getDocument().getField("line").stringValue()); } + + public String getText() + { + return getDocument().getField("content").stringValue(); + } + + public String toString() + { + return super.toString() + ":" + getLine() + " - " + getText(); + } } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-15 09:21:03 UTC (rev 15452) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-15 12:35:57 UTC (rev 15453) @@ -1,8 +1,11 @@ package gatchan.jedit.lucene; +import marker.FileMarker; + import org.gjt.sp.jedit.EBComponent; import org.gjt.sp.jedit.EBMessage; import org.gjt.sp.jedit.EditBus; +import org.gjt.sp.jedit.View; import org.gjt.sp.jedit.jEdit; import org.gjt.sp.util.StandardUtilities; @@ -52,8 +55,17 @@ { public void valueChanged(ListSelectionEvent e) { - String path = (String) list.getSelectedValue(); - jEdit.openFile(jEdit.getActiveView(), path); + Object obj = list.getSelectedValue(); + View view = jEdit.getActiveView(); + if (obj instanceof String) + { + String path = (String) list.getSelectedValue(); + jEdit.openFile(view, path); + } + else if (obj instanceof FileMarker) + { + ((FileMarker) obj).jump(view); + } } }); // HTMLDocument htmlDocument = new HTMLDocument(); @@ -69,15 +81,23 @@ if (index == null) return; - final java.util.List<String> files = new ArrayList<String>(); + final java.util.List<Object> files = new ArrayList<Object>(); index.search(text, new ResultProcessor() { public boolean process(float score, Result result) { - String s = result.getPath(); if (result instanceof LineResult) - s += ":" + ((LineResult)result).getLine(); - files.add(s); + { + LineResult lr = (LineResult) result; + FileMarker marker = new FileMarker(lr.getPath(), + lr.getLine() - 1, lr.getText()); + files.add(marker); + } + else + { + String s = result.getPath(); + files.add(s); + } return true; } }); @@ -109,9 +129,9 @@ private static class MyModel extends AbstractListModel { - private java.util.List<String> files = new ArrayList<String>(); + private java.util.List<Object> files = new ArrayList<Object>(); - public void setFiles(java.util.List<String> files) + public void setFiles(java.util.List<Object> files) { this.files = files; fireContentsChanged(this, 0, files.size()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-06-19 02:15:50
|
Revision: 15482 http://jedit.svn.sourceforge.net/jedit/?rev=15482&view=rev Author: shlomy Date: 2009-06-19 00:39:45 +0000 (Fri, 19 Jun 2009) Log Message: ----------- Added line-based results using the Highlighter package. Added search options in the dockable: - Whether to show line-based results - The maximal number of results to show For the highlighter to work, a highlight-scorer must be created based on the query, so the result processor also receives the query with each result. LineIndexImpl can almost be considered deprecated, since an up-to-date line-based results can be retrieved using IndexImpl with the Highlighter. But, using the Highlighter for this requires a lot of memory, since the entire file must be in memory and an array of line start positions must be maintained for this, so LineIndexImpl can trade memory for performance and index size on disk. Modified Paths: -------------- plugins/LucenePlugin/trunk/build.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/PrintResultProcessor.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java Added Paths: ----------- plugins/LucenePlugin/trunk/lucene-highlighter-2.4.1.jar Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2009-06-18 22:31:12 UTC (rev 15481) +++ plugins/LucenePlugin/trunk/build.xml 2009-06-19 00:39:45 UTC (rev 15482) @@ -20,11 +20,13 @@ <pathelement location="${jedit.install.dir}/jedit.jar" /> <pathelement location="${install.dir}/MarkerSets.jar"/> <pathelement location="${install.dir}/lucene-core-2.4.1.jar"/> + <pathelement location="${install.dir}/lucene-highlighter-2.4.1.jar"/> </path> <target name="build.prepare" > <mkdir dir="${build.dir}" /> <copy file="lucene-core-2.4.1.jar" todir="${install.dir}" /> + <copy file="lucene-highlighter-2.4.1.jar" todir="${install.dir}" /> </target> </project> Added: plugins/LucenePlugin/trunk/lucene-highlighter-2.4.1.jar =================================================================== (Binary files differ) Property changes on: plugins/LucenePlugin/trunk/lucene-highlighter-2.4.1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-18 22:31:12 UTC (rev 15481) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-19 00:39:45 UTC (rev 15482) @@ -45,7 +45,8 @@ * Execute the given search query. * * @param query the query to execute + * @param max the maximal number of results to search for * @param processor the processor that will get the results */ - void search(String query, ResultProcessor processor); + void search(String query, int max, ResultProcessor processor); } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-18 22:31:12 UTC (rev 15481) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-19 00:39:45 UTC (rev 15482) @@ -128,8 +128,10 @@ } } - public void search(String query, ResultProcessor processor) + public void search(String query, int max, ResultProcessor processor) { + if (max < 1) + max = 1; Searcher searcher = getSearcher(); if (searcher == null) return; @@ -137,14 +139,14 @@ try { Query _query = parser.parse(query); - TopDocs docs = searcher.search(_query, 100); + TopDocs docs = searcher.search(_query, max); ScoreDoc[] scoreDocs = docs.scoreDocs; Result result = getResultInstance(); for (ScoreDoc doc : scoreDocs) { Document document = searcher.doc(doc.doc); result.setDocument(document); - if (!processor.process(doc.score, result)) + if (!processor.process(_query, doc.score, result)) { break; } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/PrintResultProcessor.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/PrintResultProcessor.java 2009-06-18 22:31:12 UTC (rev 15481) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/PrintResultProcessor.java 2009-06-19 00:39:45 UTC (rev 15482) @@ -20,6 +20,7 @@ */ package gatchan.jedit.lucene; +import org.apache.lucene.search.Query; import org.gjt.sp.util.Log; /** @@ -27,7 +28,7 @@ */ public class PrintResultProcessor implements ResultProcessor { - public boolean process(float score, Result result) + public boolean process(Query q, float score, Result result) { Log.log(Log.MESSAGE, this, result.getPath() + " score:" + score); return true; Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java 2009-06-18 22:31:12 UTC (rev 15481) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/ResultProcessor.java 2009-06-19 00:39:45 UTC (rev 15482) @@ -20,11 +20,13 @@ */ package gatchan.jedit.lucene; +import org.apache.lucene.search.Query; + /** * @author Matthieu Casanova */ public interface ResultProcessor { - boolean process(float score, Result result); + boolean process(Query query, float score, Result result); } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-18 22:31:12 UTC (rev 15481) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-06-19 00:39:45 UTC (rev 15482) @@ -1,7 +1,17 @@ package gatchan.jedit.lucene; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Collections; + import marker.FileMarker; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.highlight.Formatter; +import org.apache.lucene.search.highlight.Highlighter; +import org.apache.lucene.search.highlight.QueryScorer; +import org.apache.lucene.search.highlight.TokenGroup; import org.gjt.sp.jedit.EBComponent; import org.gjt.sp.jedit.EBMessage; import org.gjt.sp.jedit.EditBus; @@ -15,13 +25,14 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.ArrayList; @SuppressWarnings("serial") public class SearchResults extends JPanel implements EBComponent { private JTextField searchField; private JList list; + private JCheckBox lineResults; + private JSpinner maxResults; private JComboBox indexes; private MyModel model; private IndexComboBoxModel indexModel; @@ -30,6 +41,14 @@ public SearchResults() { super(new BorderLayout()); + + lineResults = new JCheckBox("Line-based results"); + + maxResults = new JSpinner(new SpinnerNumberModel(100, 1, 10000, 1)); + JPanel maxPanel = new JPanel(new BorderLayout()); + maxPanel.add(BorderLayout.WEST, new JLabel("Max results:")); + maxPanel.add(BorderLayout.EAST, maxResults); + String[] items = LucenePlugin.instance.getIndexes(); indexModel = new IndexComboBoxModel(items); indexes = new JComboBox(indexModel); @@ -45,9 +64,13 @@ search(searchField.getText()); } }); - + + JPanel optionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0)); + optionsPanel.add(lineResults); + optionsPanel.add(maxPanel); + optionsPanel.add(indexes); panel.add(searchField, BorderLayout.CENTER); - panel.add(indexes, BorderLayout.EAST); + panel.add(optionsPanel, BorderLayout.EAST); model = new MyModel(); list = new JList(model); @@ -76,35 +99,125 @@ // add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(list), preview), BorderLayout.CENTER); } - public void search(String text) + private class QueryResultProcessor implements ResultProcessor { - Index index = LucenePlugin.instance.getIndex((String) indexes.getSelectedItem()); - if (index == null) - return; - - final java.util.List<Object> files = new ArrayList<Object>(); - index.search(text, new ResultProcessor() + private Index index; + private java.util.List<Object> files; + private int max; + public QueryResultProcessor(Index index, + java.util.List<Object> files, int max) { - public boolean process(float score, Result result) + this.index = index; + this.files = files; + this.max = max; + } + public boolean process(Query query, float score, Result result) + { + if (result instanceof LineResult) { - if (result instanceof LineResult) + LineResult lr = (LineResult) result; + FileMarker marker = new FileMarker(lr.getPath(), + lr.getLine() - 1, lr.getText()); + files.add(marker); + } + else + { + String s = result.getPath(); + if (! lineResults.isSelected()) { - LineResult lr = (LineResult) result; - FileMarker marker = new FileMarker(lr.getPath(), - lr.getLine() - 1, lr.getText()); - files.add(marker); + files.add(s); } else { - String s = result.getPath(); - files.add(s); + ArrayList<FileMarker> markers = + findMatch(query, s, max - files.size()); + for (FileMarker marker: markers) + files.add(marker); } - return true; } - }); + return (files.size() < max); + } + private ArrayList<FileMarker> findMatch(Query query, String file, + int max) + { + SearchFormatter sf = new SearchFormatter(file, max); + QueryScorer scorer = new QueryScorer(query); + StringBuilder sb = new StringBuilder(); + ArrayList<Integer> lineStart = new ArrayList<Integer>(); + try { + BufferedReader br = new BufferedReader(new FileReader(file)); + String s; + String sep = "\n"; + while ((s = br.readLine()) != null) + { + if (sb.length() > 0) + sb.append(sep); + lineStart.add(sb.length()); + sb.append(s); + } + Highlighter h = new Highlighter(sf, scorer); + h.setMaxDocCharsToAnalyze(sb.length()); + h.getBestFragments(index.getAnalyzer(), sb.toString(), 0); + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + ArrayList<FileMarker> lines = new ArrayList<FileMarker>(); + FileMarker marker = null; + for (int i: sf.positions) + { + int start = i, stop = i + 1; + // Find beginning and end of line + while ((start >= 0) && (sb.charAt(start) != '\n')) + start--; + start++; + while ((stop < sb.length()) && (sb.charAt(stop) != '\n')) + stop++; + String lineText = sb.substring(start, stop); + int line = Collections.binarySearch(lineStart, i); + if (line < 0) + line = -line - 2; + marker = new FileMarker(file, line, lineText); + lines.add(marker); + } + return lines; + } + } + + public void search(String text) + { + Index index = LucenePlugin.instance.getIndex((String) indexes.getSelectedItem()); + if (index == null) + return; + + final java.util.List<Object> files = new ArrayList<Object>(); + int max = ((Integer)(maxResults.getValue())).intValue(); + index.search(text, max, new QueryResultProcessor(index, files, max)); model.setFiles(files); } + private class SearchFormatter implements Formatter + { + String file; + int max; + ArrayList<Integer> positions = new ArrayList<Integer>(0); + public SearchFormatter(String file, int max) + { + this.file = file; + this.max = max; + } + public String highlightTerm(String originalText, + TokenGroup tokenGroup) + { + if ((positions.size() < max) && + (tokenGroup.getTotalScore() > 0)) + { + positions.add(tokenGroup.getStartOffset()); + } + return originalText; + } + } + //{{{ addNotify() method public void addNotify() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Kp...@us...> - 2009-06-20 10:15:01
|
Revision: 15500 http://jedit.svn.sourceforge.net/jedit/?rev=15500&view=rev Author: Kpouer Date: 2009-06-20 10:14:55 +0000 (Sat, 20 Jun 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-20 10:11:39 UTC (rev 15499) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-20 10:14:55 UTC (rev 15500) @@ -1,7 +1,7 @@ plugin.gatchan.jedit.lucene.LucenePlugin.activate=startup plugin.gatchan.jedit.lucene.LucenePlugin.name=LucenePlugin -plugin.gatchan.jedit.lucene.LucenePlugin.author=Matthieu Casanova +plugin.gatchan.jedit.lucene.LucenePlugin.author=Matthieu Casanova, Shlomy Reinstein plugin.gatchan.jedit.lucene.LucenePlugin.version=1.0 plugin.gatchan.jedit.lucene.LucenePlugin.depend.0=jdk 1.5 plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-20 10:11:39 UTC (rev 15499) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-20 10:14:55 UTC (rev 15500) @@ -185,9 +185,7 @@ protected void addDocument(VFSFile file, Object session) { Log.log(Log.DEBUG, this, "Index:" + name + " add " + file); - Document doc = new Document(); - 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)); + Document doc = getEmptyDocument(file); Reader reader = null; try { @@ -208,6 +206,14 @@ } } + protected Document getEmptyDocument(VFSFile file) + { + Document doc = new Document(); + 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)); + return doc; + } + private static class MyVFSFilter implements VFSFileFilter { private static final String[] suffixes = new String[]{"~", "bak", "tgz", "gif", "class", "exe", "gif", "png", "jpg"}; Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java 2009-06-20 10:11:39 UTC (rev 15499) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LineIndexImpl.java 2009-06-20 10:14:55 UTC (rev 15500) @@ -1,3 +1,23 @@ +/* + * IndexImpl.java - The Index implementation + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2009 Shlomy Reinstein + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ package gatchan.jedit.lucene; import org.apache.lucene.document.Document; @@ -13,6 +33,10 @@ import java.io.IOException; import java.io.InputStreamReader; +/** + * A line based Index. + * @author Shlomy Reinstein + */ public class LineIndexImpl extends IndexImpl { public LineIndexImpl(String name, File path) @@ -31,13 +55,11 @@ reader = new BufferedReader(new InputStreamReader( file.getVFS()._createInputStream(session, file.getPath(), false, jEdit.getActiveView()))); - String line = null; + String line; int i = 0; while ((line = reader.readLine()) != null) { - Document doc = new Document(); - 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)); + Document doc = getEmptyDocument(file); i++; doc.add(new Field("line", String.valueOf(i), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("content", line, Field.Store.YES, Field.Index.ANALYZED)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-06-21 16:57:35
|
Revision: 15522 http://jedit.svn.sourceforge.net/jedit/?rev=15522&view=rev Author: shlomy Date: 2009-06-21 16:57:34 +0000 (Sun, 21 Jun 2009) Log Message: ----------- Added configurable file globs to include / exclude in the index. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java Added Paths: ----------- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/OptionPane.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-21 14:10:47 UTC (rev 15521) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-21 16:57:34 UTC (rev 15522) @@ -22,3 +22,11 @@ lucene.message.IndexType=Type: lucene.message.Analyzer=Analyzer: +# Options +plugin.gatchan.jedit.lucene.LucenePlugin.option-pane=Lucene +options.Lucene.label=Lucene +options.Lucene.code=new gatchan.jedit.lucene.OptionPane(); +lucene.options.IncludeGlobs=* +lucene.options.IncludeGlobs.label=Include only files matching: +lucene.options.ExcludeGlobs=*.*~ *.bak *.tgz *.gif *.class *.exe *.gif *.png *.jpg *.obj +lucene.options.ExcludeGlobs.label=... except files matching: Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-21 14:10:47 UTC (rev 15521) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-21 16:57:34 UTC (rev 15522) @@ -223,8 +223,6 @@ private static class MyVFSFilter implements VFSFileFilter { - private static final String[] suffixes = new String[]{"~", "bak", "tgz", "gif", "class", "exe", "gif", "png", "jpg"}; - public boolean accept(VFSFile file) { String name = file.getName(); @@ -241,12 +239,7 @@ public boolean accept(String url) { - for (String suffix : suffixes) - { - if (url.endsWith(suffix)) - return false; - } - return true; + return OptionPane.accept(url); } public String getDescription() Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/OptionPane.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/OptionPane.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/OptionPane.java 2009-06-21 16:57:34 UTC (rev 15522) @@ -0,0 +1,76 @@ +package gatchan.jedit.lucene; + +import java.util.regex.Pattern; + +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; + +import org.gjt.sp.jedit.AbstractOptionPane; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.util.StandardUtilities; + +@SuppressWarnings("serial") +public class OptionPane extends AbstractOptionPane { + + public static final String PREFIX = "lucene.options."; + private static final String INCLUDE_GLOBS_OPTION = PREFIX + "IncludeGlobs"; + private static final String INCLUDE_GLOBS_LABEL = INCLUDE_GLOBS_OPTION + ".label"; + private static final String EXCLUDE_GLOBS_OPTION = PREFIX + "ExcludeGlobs"; + private static final String EXCLUDE_GLOBS_LABEL = EXCLUDE_GLOBS_OPTION + ".label"; + private static Pattern include = null, exclude = null; + + private JTextField includeFilesTF; + private JTextField excludeFilesTF; + + public OptionPane() { + super("Lucene"); + setBorder(new EmptyBorder(5, 5, 5, 5)); + + includeFilesTF = new JTextField(includeGlobs()); + addComponent(jEdit.getProperty(INCLUDE_GLOBS_LABEL), includeFilesTF); + excludeFilesTF = new JTextField(excludeGlobs()); + addComponent(jEdit.getProperty(EXCLUDE_GLOBS_LABEL), excludeFilesTF); + } + public void save() + { + jEdit.setProperty(INCLUDE_GLOBS_OPTION, includeFilesTF.getText()); + jEdit.setProperty(EXCLUDE_GLOBS_OPTION, excludeFilesTF.getText()); + updateFilter(); + } + + static public String includeGlobs() + { + return jEdit.getProperty(INCLUDE_GLOBS_OPTION); + } + static public String excludeGlobs() + { + return jEdit.getProperty(EXCLUDE_GLOBS_OPTION); + } + static private Pattern globToPattern(String filter) + { + String [] parts = filter.split(" "); + StringBuilder sb = new StringBuilder(); + for (String part: parts) + { + if (sb.length() > 0) + sb.append("|"); + String regexp = StandardUtilities.globToRE(part); + sb.append(regexp); + } + return Pattern.compile(sb.toString()); + } + + static private void updateFilter() + { + include = globToPattern(includeGlobs()); + exclude = globToPattern(excludeGlobs()); + } + + static public boolean accept(String path) + { + if (include == null || exclude == null) + updateFilter(); + return (include.matcher(path).matches() && + !exclude.matcher(path).matches()); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-06-22 06:17:47
|
Revision: 15530 http://jedit.svn.sourceforge.net/jedit/?rev=15530&view=rev Author: shlomy Date: 2009-06-22 06:17:44 +0000 (Mon, 22 Jun 2009) Log Message: ----------- Added support for project indexing. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/browser.actions.xml plugins/LucenePlugin/trunk/build.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java Added Paths: ----------- plugins/LucenePlugin/trunk/services.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-22 06:17:44 UTC (rev 15530) @@ -22,6 +22,9 @@ lucene.message.IndexType=Type: lucene.message.Analyzer=Analyzer: +lucene.message.CreateProjectIndexError=Could not create an index for this project. +lucene.message.CreateProjectIndexError.title=Project index error + # Options plugin.gatchan.jedit.lucene.LucenePlugin.option-pane=Lucene options.Lucene.label=Lucene Modified: plugins/LucenePlugin/trunk/browser.actions.xml =================================================================== --- plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/browser.actions.xml 2009-06-22 06:17:44 UTC (rev 15530) @@ -4,7 +4,7 @@ <CODE> String indexName = gatchan.jedit.lucene.LucenePlugin.instance.chooseIndex(); if (indexName != null) - gatchan.jedit.lucene.LucenePlugin.instance.addToIndex(indexName, files); + gatchan.jedit.lucene.LucenePlugin.instance.addToIndex(indexName, files, false); </CODE> </ACTION> <ACTION NAME="lucene.add-to-newindex" NO_REPEAT="TRUE"> @@ -12,7 +12,7 @@ import gatchan.jedit.lucene.LucenePlugin; String indexName = LucenePlugin.instance.createNewIndex(); if (indexName != null) - LucenePlugin.instance.addToIndex(indexName, files); + LucenePlugin.instance.addToIndex(indexName, files, false); </CODE> </ACTION> </ACTIONS> Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/build.xml 2009-06-22 06:17:44 UTC (rev 15530) @@ -18,6 +18,7 @@ <path id="project.class.path"> <pathelement location="${jedit.install.dir}/jedit.jar" /> + <pathelement location="${install.dir}/ProjectViewer.jar"/> <pathelement location="${install.dir}/MarkerSets.jar"/> <pathelement location="${install.dir}/lucene-core-2.4.1.jar"/> <pathelement location="${install.dir}/lucene-highlighter-2.4.1.jar"/> Added: plugins/LucenePlugin/trunk/services.xml =================================================================== --- plugins/LucenePlugin/trunk/services.xml (rev 0) +++ plugins/LucenePlugin/trunk/services.xml 2009-06-22 06:17:44 UTC (rev 15530) @@ -0,0 +1,9 @@ +<?xml version="1.0"?> + +<!DOCTYPE SERVICES SYSTEM "services.dtd"> + +<SERVICES> + <SERVICE CLASS="projectviewer.action.Action" NAME="Create/update Lucene index for project"> + new gatchan.jedit.lucene.IndexProjectAction(); + </SERVICE> +</SERVICES> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-06-22 06:17:44 UTC (rev 15530) @@ -21,6 +21,7 @@ package gatchan.jedit.lucene; import org.apache.lucene.analysis.Analyzer; +import org.gjt.sp.jedit.io.VFSFile; /** * @author Matthieu Casanova @@ -37,6 +38,7 @@ String getName(); Analyzer getAnalyzer(); void addFile(String path); + void addFiles(VFSFile[] files); void removeFile(String path); void setAnalyzer(Analyzer analyzer); Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2009-06-22 06:17:44 UTC (rev 15530) @@ -35,6 +35,7 @@ import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.io.VFSFileFilter; import org.gjt.sp.jedit.io.VFSManager; +import org.gjt.sp.jedit.View; import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.MiscUtilities; import org.gjt.sp.util.IOUtilities; @@ -61,6 +62,29 @@ return name; } + public void addFiles(VFSFile[] files) + { + if (files.length == 0) + return; + openWriter(); + if (writer == null) + return; + String path = files[0].getPath(); + VFS vfs = VFSManager.getVFSForPath(path); + View view = jEdit.getActiveView(); + Object session = vfs.createVFSSession(path, view); + for (VFSFile file: files) + addDocument(file, session); + try + { + vfs._endVFSSession(session, view); + } + catch (IOException e) + { + } + LucenePlugin.CENTRAL.commit(); + } + public void addFile(String path) { openWriter(); Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java 2009-06-22 06:17:44 UTC (rev 15530) @@ -0,0 +1,63 @@ +package gatchan.jedit.lucene; + +import java.awt.event.ActionEvent; +import java.util.Collection; +import java.util.Vector; + +import javax.swing.JOptionPane; + +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.io.VFSFile; + +import projectviewer.action.Action; +import projectviewer.vpt.VPTFile; +import projectviewer.vpt.VPTNode; +import projectviewer.vpt.VPTProject; + +public class IndexProjectAction extends Action +{ + static public final String MESSAGE = "lucene.message."; + static public final String INDEX_ERROR = MESSAGE + "CreateProjectIndexError"; + static public final String INDEX_ERROR_TITLE = MESSAGE + "CreateProjectIndexError.title"; + + @Override + public String getText() + { + return "Create/update Lucene index for project"; + } + + public void actionPerformed(ActionEvent e) + { + if (viewer != null) { + VPTNode node = viewer.getSelectedNode(); + if (node == null) + node = viewer.getRoot(); + VPTProject project = VPTNode.findProjectFor(node); + if (project == null) + return; + Collection<VPTNode> nodes = project.getOpenableNodes(); + Vector<VFSFile> files = new Vector<VFSFile>(); + for (VPTNode n: nodes) + { + if (n.isFile()) + { + VPTFile vptFile = (VPTFile) n; + files.add(vptFile.getFile()); + } + } + VFSFile [] fileArray = new VFSFile[files.size()]; + files.toArray(fileArray); + String indexName = project.getName(); + Index index = LucenePlugin.instance.getIndexForProject(indexName); + if (index == null) + { + JOptionPane.showMessageDialog(null, jEdit.getProperty(INDEX_ERROR), + jEdit.getProperty(INDEX_ERROR_TITLE), JOptionPane.ERROR_MESSAGE, + null); + return; + } + LucenePlugin.instance.addToIndex(indexName, fileArray, true); + } + } + +} Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-22 06:17:44 UTC (rev 15530) @@ -148,6 +148,23 @@ return indexMap.get(name); } + public Index getIndexForProject(String name) + { + Index index = getIndex(name); + if (index == null) + { + NewIndexDialog dlg = new NewIndexDialog(jEdit.getActiveView(), name); + dlg.setVisible(true); + if (dlg.accepted()) + { + index = createIndex(dlg.getIndexName(), dlg.getIndexType(), + dlg.getIndexAnalyzer()); + } + + } + return index; + } + public Index createIndex(String name, String type, String analyzerName) { Index index = getIndex(name); @@ -239,8 +256,10 @@ * * @param indexName the index name * @param files the file array to add + * @param sharedSession whether the VFS session can be shared by all files */ - public void addToIndex(final String indexName, final VFSFile[] files) + public void addToIndex(final String indexName, final VFSFile[] files, + final boolean sharedSession) { VFSManager.runInWorkThread(new Runnable() { @@ -252,9 +271,14 @@ Log.log(Log.ERROR, this, "Unable to get index " + indexName); return; } - for (VFSFile file : files) + if (sharedSession) + index.addFiles(files); + else { - index.addFile(file.getPath()); + for (VFSFile file : files) + { + index.addFile(file.getPath()); + } } index.commit(); } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java 2009-06-21 21:26:12 UTC (rev 15529) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/NewIndexDialog.java 2009-06-22 06:17:44 UTC (rev 15530) @@ -32,8 +32,11 @@ { GUIUtilities.saveGeometry(this, GEOMETRY); } - + public NewIndexDialog(Frame frame) { + this(frame, null); + } + public NewIndexDialog(Frame frame, String initialName) { super(frame, jEdit.getProperty(MESSAGE + "NewIndexDialogTitle"), true); addWindowListener(new java.awt.event.WindowAdapter() { @@ -49,6 +52,11 @@ p.add(new JLabel(jEdit.getProperty(MESSAGE + "IndexName"))); name = new JTextField(30); p.add(name); + if (initialName != null) + { + name.setText(initialName); + name.setEditable(false); + } // Index type panel p = new JPanel(new FlowLayout(FlowLayout.LEADING)); add(p); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-06-24 21:04:06
|
Revision: 15561 http://jedit.svn.sourceforge.net/jedit/?rev=15561&view=rev Author: shlomy Date: 2009-06-24 21:03:57 +0000 (Wed, 24 Jun 2009) Log Message: ----------- Added a menu item for deleting an Index. Also, save the index list whenever something changes, do not wait until stop(), in case jEdit crashes. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Added Paths: ----------- plugins/LucenePlugin/trunk/actions.xml Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-24 16:57:58 UTC (rev 15560) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-06-24 21:03:57 UTC (rev 15561) @@ -10,7 +10,7 @@ plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar lucene-highlighter-2.4.1.jar plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=\ lucene.add-to-index lucene.add-to-newindex -plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search +plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search - lucene.remove-index plugin.gatchan.jedit.lucene.LucenePlugin.usePluginHome=true @@ -18,6 +18,7 @@ lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> lucene-search.label=Search lucene-search.title=Search with Lucene +lucene.remove-index.label=Delete an index lucene.message.NewIndexDialogTitle=New Lucene Index lucene.message.IndexName=Name: Added: plugins/LucenePlugin/trunk/actions.xml =================================================================== --- plugins/LucenePlugin/trunk/actions.xml (rev 0) +++ plugins/LucenePlugin/trunk/actions.xml 2009-06-24 21:03:57 UTC (rev 15561) @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<!DOCTYPE ACTIONS SYSTEM "actions.dtd"> +<ACTIONS> + <ACTION NAME="lucene.remove-index" NO_REPEAT="TRUE"> + <CODE> + String indexName = gatchan.jedit.lucene.LucenePlugin.instance.chooseIndex(); + if (indexName != null) + gatchan.jedit.lucene.LucenePlugin.instance.removeIndex(indexName); + </CODE> + </ACTION> +</ACTIONS> + Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2009-06-24 16:57:58 UTC (rev 15560) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2009-06-24 21:03:57 UTC (rev 15561) @@ -28,12 +28,15 @@ import org.gjt.sp.jedit.EBComponent; import org.gjt.sp.jedit.EBMessage; import org.gjt.sp.jedit.EditBus; +import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.io.VFSManager; import org.gjt.sp.jedit.msg.BufferUpdate; import java.io.File; import java.io.IOException; +import javax.swing.JOptionPane; + /** * This index will contains documents to link files to indexes. * Each document has the following fields : @@ -75,7 +78,15 @@ openWriter(); try { - writer.deleteDocuments(new Term("indexName", name)); + if (writer == null) + { + JOptionPane.showMessageDialog(jEdit.getActiveView(), + "Error: Can't complete removal of index " + name + ": Could not open meta-index."); + } + else + { + writer.deleteDocuments(new Term("indexName", name)); + } } catch (IOException e) { Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-24 16:57:58 UTC (rev 15560) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-06-24 21:03:57 UTC (rev 15561) @@ -132,7 +132,6 @@ { index.close(); } - saveIndexes(); } /** @@ -179,6 +178,7 @@ if (analyzer != null) index.setAnalyzer(analyzer); indexMap.put(name, index); + saveIndexes(); if (!path.exists()) { path.mkdirs(); @@ -196,6 +196,7 @@ { CENTRAL.removeIndex(name); Index index = indexMap.remove(name); + saveIndexes(); if (index != null) index.close(); File indexFile = getIndexFile(name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2009-08-05 08:42:32
|
Revision: 15862 http://jedit.svn.sourceforge.net/jedit/?rev=15862&view=rev Author: kpouer Date: 2009-08-05 08:42:26 +0000 (Wed, 05 Aug 2009) Log Message: ----------- unlock the index when it is locked (by a crash for example) Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-08-04 23:58:38 UTC (rev 15861) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-08-05 08:42:26 UTC (rev 15862) @@ -36,3 +36,9 @@ lucene.options.IncludeGlobs.label=Include only files matching: lucene.options.ExcludeGlobs=*.*~ *.bak *.bmp *.ico *.gif *.gif *.png *.jpg *.class *.exe *.obj *.jar *.zip *.7z *.rar *.tgz *.wav *.mp3 *.ogg lucene.options.ExcludeGlobs.label=... except files matching: + +lucene.index.locked.title=Index locked +lucene.index.locked.message=The index at path {0} is locked.\n\ + It can happens if another processus is currently using it\n\ + or there was a problem with the Lucene plugin (a bug or a crash).\n\ + Do you want to unlock the index ? \ No newline at end of file Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-08-04 23:58:38 UTC (rev 15861) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-08-05 08:42:26 UTC (rev 15862) @@ -26,10 +26,14 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Searcher; +import org.apache.lucene.store.FSDirectory; import org.gjt.sp.util.Log; +import org.gjt.sp.jedit.GUIUtilities; +import org.gjt.sp.jedit.jEdit; import gatchan.jedit.lucene.Index.ActivityListener; +import javax.swing.*; import java.io.File; import java.io.IOException; import java.util.Map; @@ -89,6 +93,17 @@ try { path.mkdirs(); + if (IndexWriter.isLocked(path.getAbsolutePath())) + { + Log.log(Log.WARNING, this, "The lucene index at " + path + " is locked"); + int ret = GUIUtilities.confirm(jEdit.getActiveView(), "lucene.index.locked", + new Object[]{path}, JOptionPane.YES_NO_OPTION, + JOptionPane.ERROR_MESSAGE); + if (ret == JOptionPane.YES_OPTION) + { + IndexWriter.unlock(FSDirectory.getDirectory(path)); + } + } writer = new IndexWriter(path, getAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); } catch (IOException e) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2009-08-23 10:16:17
|
Revision: 16035 http://jedit.svn.sourceforge.net/jedit/?rev=16035&view=rev Author: kpouer Date: 2009-08-23 10:16:11 +0000 (Sun, 23 Aug 2009) Log Message: ----------- Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props Added Paths: ----------- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-08-23 04:28:18 UTC (rev 16034) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-08-23 10:16:11 UTC (rev 16035) @@ -29,9 +29,12 @@ lucene.message.CreateProjectIndexError.title=Project index error # Options -plugin.gatchan.jedit.lucene.LucenePlugin.option-pane=Lucene +plugin.gatchan.jedit.lucene.LucenePlugin.option-group=Lucene IndexManagement options.Lucene.label=Lucene options.Lucene.code=new gatchan.jedit.lucene.OptionPane(); +options.IndexManagement.label=Index Management +options.IndexManagement.code=new gatchan.jedit.lucene.IndexManagement(); + lucene.options.IncludeGlobs=* lucene.options.IncludeGlobs.label=Include only files matching: lucene.options.ExcludeGlobs=*.*~ *.bak *.bmp *.ico *.gif *.gif *.png *.jpg *.class *.exe *.obj *.jar *.zip *.7z *.rar *.tgz *.wav *.mp3 *.ogg Added: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java (rev 0) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java 2009-08-23 10:16:11 UTC (rev 16035) @@ -0,0 +1,74 @@ +/* + * AbstractIndex.java + * :tabSize=8:indentSize=8:noTabs=false: + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2009 Matthieu Casanova + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package gatchan.jedit.lucene; + +import org.gjt.sp.jedit.AbstractOptionPane; + +import javax.swing.*; +import java.awt.*; + +/** + * @author Matthieu Casanova + */ +public class IndexManagement extends AbstractOptionPane +{ + public IndexManagement() + { + super("LuceneIndexManagement"); + setLayout(new BorderLayout()); + } + + @Override + protected void _init() + { + String[] items = LucenePlugin.instance.getIndexes(); + JList indexList = new JList(items); + JScrollPane leftScroll = new JScrollPane(indexList); + JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftScroll, new IndexOptionPanel0()); + + + add(split); + + } + + @Override + protected void _save() + { + } + + private static class IndexOptionPanel0 extends JPanel + { + private final JTextField indexName; + + private IndexOptionPanel0() + { + super(); + indexName = new JTextField(); + add(indexName); + + } + + public void setIndex(String name) + { + indexName.setText(name); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2009-08-23 11:39:31
|
Revision: 16039 http://jedit.svn.sourceforge.net/jedit/?rev=16039&view=rev Author: kpouer Date: 2009-08-23 11:39:25 +0000 (Sun, 23 Aug 2009) Log Message: ----------- started index management Modified Paths: -------------- plugins/LucenePlugin/trunk/build.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2009-08-23 11:07:19 UTC (rev 16038) +++ plugins/LucenePlugin/trunk/build.xml 2009-08-23 11:39:25 UTC (rev 16039) @@ -14,7 +14,7 @@ <property name="compiler.source" value="1.5" /> <property name="compiler.target" value="1.5" /> - <import file="${build.support}/plugin-build.xml" /> + <import file="../../build-support/plugin-build.xml" /> <path id="project.class.path"> <pathelement location="${jedit.install.dir}/jedit.jar" /> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-08-23 11:07:19 UTC (rev 16038) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2009-08-23 11:39:25 UTC (rev 16039) @@ -161,6 +161,26 @@ } } + /** + * Optimize the index. + * It is necessary to commit after that + */ + public void optimize() + { + openWriter(); + if (writer != null) + { + try + { + writer.optimize(); + } + catch (IOException e) + { + Log.log(Log.ERROR, this, "Error while optimizing index", e); + } + } + } + public void commit() { if (writer != null) @@ -171,7 +191,7 @@ } catch (IOException e) { - Log.log(Log.ERROR, this, "Error while optimizing index", e); + Log.log(Log.ERROR, this, "Error while commiting index", e); } } } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-08-23 11:07:19 UTC (rev 16038) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/Index.java 2009-08-23 11:39:25 UTC (rev 16039) @@ -33,6 +33,7 @@ */ void close(); + void optimize(); void commit(); String getName(); Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java 2009-08-23 11:07:19 UTC (rev 16038) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexManagement.java 2009-08-23 11:39:25 UTC (rev 16039) @@ -21,15 +21,22 @@ package gatchan.jedit.lucene; import org.gjt.sp.jedit.AbstractOptionPane; +import org.gjt.sp.util.Log; import javax.swing.*; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.ListSelectionEvent; import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; /** * @author Matthieu Casanova */ public class IndexManagement extends AbstractOptionPane { + private IndexOptionPanel indexOptionPanel; + public IndexManagement() { super("LuceneIndexManagement"); @@ -40,11 +47,23 @@ protected void _init() { String[] items = LucenePlugin.instance.getIndexes(); - JList indexList = new JList(items); + final JList indexList = new JList(items); JScrollPane leftScroll = new JScrollPane(indexList); - JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftScroll, new IndexOptionPanel0()); + indexOptionPanel = new IndexOptionPanel(); + JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScroll, indexOptionPanel); + indexList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + indexList.getSelectionModel().addListSelectionListener(new ListSelectionListener() + { + public void valueChanged(ListSelectionEvent e) + { + int row = e.getFirstIndex(); + if (row > -1) + { + indexOptionPanel.setIndex((String) indexList.getSelectedValue()); + } + } + }); - add(split); } @@ -54,21 +73,102 @@ { } - private static class IndexOptionPanel0 extends JPanel + private static class IndexOptionPanel extends JPanel { - private final JTextField indexName; + private final JTextField indexNameField; + private String indexName; - private IndexOptionPanel0() + private JButton optimize; + private JButton delete; + private JButton reindex; + + private IndexOptionPanel() { - super(); - indexName = new JTextField(); - add(indexName); + super(new SpringLayout()); + SpringLayout layout = (SpringLayout) getLayout(); + indexNameField = new JTextField(); + indexNameField.setEditable(false); + optimize = new JButton("Optimize"); + delete = new JButton("Delete"); + reindex = new JButton("Re-index"); + + + JLabel indexNameLabel = new JLabel("Index name:"); + + // label at 5 pixel of the left and top border + layout.putConstraint(SpringLayout.WEST, indexNameLabel, 5, SpringLayout.WEST, this); + layout.putConstraint(SpringLayout.NORTH, indexNameLabel, 5, SpringLayout.NORTH, this); + + + // indexNameField at 5 pixels from label and 5 pixels from east border + layout.putConstraint(SpringLayout.WEST, indexNameField, 5, SpringLayout.EAST, indexNameLabel); + layout.putConstraint(SpringLayout.NORTH, indexNameField, 5, SpringLayout.NORTH, this); + layout.putConstraint(SpringLayout.EAST, this, 5, SpringLayout.EAST, indexNameField); + + // optimize + layout.putConstraint(SpringLayout.WEST, optimize, 5, SpringLayout.WEST, this); + layout.putConstraint(SpringLayout.NORTH, optimize, 10, SpringLayout.SOUTH, indexNameLabel); + + // delete + layout.putConstraint(SpringLayout.WEST, delete, 5, SpringLayout.EAST, optimize); + layout.putConstraint(SpringLayout.NORTH, delete, 10, SpringLayout.SOUTH, indexNameLabel); + + // reindex + layout.putConstraint(SpringLayout.WEST, reindex, 5, SpringLayout.EAST, delete); + layout.putConstraint(SpringLayout.NORTH, reindex, 10, SpringLayout.SOUTH, indexNameLabel); + + + add(indexNameLabel); + add(indexNameField); + add(optimize); + add(delete); + add(reindex); + + + optimize.addActionListener(new MyActionListener()); + } public void setIndex(String name) { - indexName.setText(name); + this.indexName = name; + indexNameField.setText(name); } + + private class MyActionListener implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + if (e.getSource() == optimize) + { + Log.log(Log.NOTICE, this, "Optimize " + indexName + " asked"); + Index index = LucenePlugin.instance.getIndex(indexName); + index.optimize(); + index.commit(); + Log.log(Log.NOTICE, this, "Optimize " + indexName + " DONE"); + } + else if (e.getSource() == delete) + { + Log.log(Log.NOTICE, this, "Delete " + indexName + " asked not implemented"); + + } + else if (e.getSource() == reindex) + { + Log.log(Log.NOTICE, this, "Reindex " + indexName + " asked not implemented"); + + } + } + } } + + public static void main(String[] args) + { + JFrame f = new JFrame(); + IndexOptionPanel p = new IndexOptionPanel(); + p.setIndex("jEdit"); + f.getContentPane().add(p); + f.pack(); + f.setVisible(true); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2009-09-01 08:54:07
|
Revision: 16140 http://jedit.svn.sourceforge.net/jedit/?rev=16140&view=rev Author: kpouer Date: 2009-09-01 08:53:58 +0000 (Tue, 01 Sep 2009) Log Message: ----------- new lucene.close-all-indexes action to release a few memory Modified Paths: -------------- plugins/LucenePlugin/trunk/actions.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java Modified: plugins/LucenePlugin/trunk/actions.xml =================================================================== --- plugins/LucenePlugin/trunk/actions.xml 2009-09-01 08:52:59 UTC (rev 16139) +++ plugins/LucenePlugin/trunk/actions.xml 2009-09-01 08:53:58 UTC (rev 16140) @@ -8,5 +8,10 @@ gatchan.jedit.lucene.LucenePlugin.instance.removeIndex(indexName); </CODE> </ACTION> + <ACTION NAME="lucene.close-all-indexes" NO_REPEAT="TRUE"> + <CODE> + gatchan.jedit.lucene.LucenePlugin.instance.closeAllIndexes(); + </CODE> + </ACTION> </ACTIONS> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-09-01 08:52:59 UTC (rev 16139) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/LucenePlugin.java 2009-09-01 08:53:58 UTC (rev 16140) @@ -136,6 +136,17 @@ CENTRAL.close(); CENTRAL = null; instance = null; + closeAllIndexes(); + indexMap.clear(); + } + + /** + * Close all opened indexes. + * This release memory + */ + public void closeAllIndexes() + { + Log.log(Log.DEBUG, this, "closeAllIndexes"); Collection<Index> indexCollection = indexMap.values(); for (Index index : indexCollection) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-09-02 06:05:54
|
Revision: 16146 http://jedit.svn.sourceforge.net/jedit/?rev=16146&view=rev Author: shlomy Date: 2009-09-02 06:05:42 +0000 (Wed, 02 Sep 2009) Log Message: ----------- Do not show multiple search results for the same line. Modified Paths: -------------- plugins/LucenePlugin/trunk/build.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2009-09-01 21:27:27 UTC (rev 16145) +++ plugins/LucenePlugin/trunk/build.xml 2009-09-02 06:05:42 UTC (rev 16146) @@ -14,7 +14,7 @@ <property name="compiler.source" value="1.5" /> <property name="compiler.target" value="1.5" /> - <import file="../../build-support/plugin-build.xml" /> + <import file="../build-support/plugin-build.xml" /> <path id="project.class.path"> <pathelement location="${jedit.install.dir}/jedit.jar" /> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-09-01 21:27:27 UTC (rev 16145) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-09-02 06:05:42 UTC (rev 16146) @@ -163,10 +163,15 @@ { SourceLinkParentNode parent = tree.addSourceLinkParent( new SearchRootNode(text)); + FileMarker prev = null; for (Object o: files) { FileMarker marker = (FileMarker) o; - parent.addSourceLink(marker); + if (! marker.equals(prev)) + { + parent.addSourceLink(marker); + prev = marker; + } } ((CardLayout) mainPanel.getLayout()).show(mainPanel, "tree"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <el...@us...> - 2009-12-22 20:14:04
|
Revision: 16704 http://jedit.svn.sourceforge.net/jedit/?rev=16704&view=rev Author: elberry Date: 2009-12-22 20:13:54 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Setting up help documentation. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/build.xml Added Paths: ----------- plugins/LucenePlugin/trunk/docs/ plugins/LucenePlugin/trunk/docs/LucenePlugin.html Removed Paths: ------------- plugins/LucenePlugin/trunk/index.html Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2009-12-22 20:11:52 UTC (rev 16703) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2009-12-22 20:13:54 UTC (rev 16704) @@ -12,6 +12,7 @@ lucene.add-to-index lucene.add-to-newindex plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search - lucene.remove-index plugin.gatchan.jedit.lucene.LucenePlugin.usePluginHome=true +plugin.gatchan.jedit.lucene.LucenePlugin.docs=docs/LucenePlugin.html lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2009-12-22 20:11:52 UTC (rev 16703) +++ plugins/LucenePlugin/trunk/build.xml 2009-12-22 20:13:54 UTC (rev 16704) @@ -12,9 +12,18 @@ <property name="dist.target" value="dist.complete" /> <property name="compiler.source" value="1.5" /> <property name="compiler.target" value="1.5" /> - + <property name="jedit.plugins.dir" value="${install.dir}" /> + <import file="${build.support}/plugin-build.xml" /> + <selector id="packageFiles"> + <and> + <or> + <filename name="docs/LucenePlugin.html" /> + </or> + </and> + </selector> + <path id="project.class.path"> <pathelement location="${jedit.install.dir}/jedit.jar" /> <pathelement location="${jedit.plugins.dir}/ProjectViewer.jar"/> @@ -22,11 +31,11 @@ <pathelement location="${install.dir}/lucene-core-2.4.1.jar"/> <pathelement location="${install.dir}/lucene-highlighter-2.4.1.jar"/> </path> - - <target name="build.prepare" > - <mkdir dir="${build.dir}" /> + + <target name="build.prepare"> + <mkdir dir="${build.dir}" /> <copy file="lucene-core-2.4.1.jar" todir="${install.dir}" /> <copy file="lucene-highlighter-2.4.1.jar" todir="${install.dir}" /> - - </target> + + </target> </project> Copied: plugins/LucenePlugin/trunk/docs/LucenePlugin.html (from rev 16702, plugins/LucenePlugin/trunk/index.html) =================================================================== --- plugins/LucenePlugin/trunk/docs/LucenePlugin.html (rev 0) +++ plugins/LucenePlugin/trunk/docs/LucenePlugin.html 2009-12-22 20:13:54 UTC (rev 16704) @@ -0,0 +1,9 @@ +<html> +<head> + <title>LucenePlugin</title> +</head> + +<body> +Lucene plugin provides an interface to the Lucene engine. +</body> +</html> Deleted: plugins/LucenePlugin/trunk/index.html =================================================================== --- plugins/LucenePlugin/trunk/index.html 2009-12-22 20:11:52 UTC (rev 16703) +++ plugins/LucenePlugin/trunk/index.html 2009-12-22 20:13:54 UTC (rev 16704) @@ -1,9 +0,0 @@ -<html> -<head> - <title>LucenePlugin</title> -</head> - -<body> -Lucene plugin provides an interface to the Lucene engine. -</body> -</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2009-12-28 15:12:53
|
Revision: 16758 http://jedit.svn.sourceforge.net/jedit/?rev=16758&view=rev Author: shlomy Date: 2009-12-28 15:12:45 +0000 (Mon, 28 Dec 2009) Log Message: ----------- Added small clarifications to the documentation. Added a tooltip for the "clear" button in the search dockable. Modified Paths: -------------- plugins/LucenePlugin/trunk/docs/LucenePlugin.html plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java Modified: plugins/LucenePlugin/trunk/docs/LucenePlugin.html =================================================================== --- plugins/LucenePlugin/trunk/docs/LucenePlugin.html 2009-12-28 05:16:53 UTC (rev 16757) +++ plugins/LucenePlugin/trunk/docs/LucenePlugin.html 2009-12-28 15:12:45 UTC (rev 16758) @@ -12,14 +12,19 @@ <a href="#DeleteIndex"> Deleting an index </a><br> <a href="#Support"> Support </a><br> <p> -LucenePlugin provides an interface to the Lucene engine. +LucenePlugin allows you to perform quick and complex text searches using the +Lucene search engine. It can save you a lot of time when searching across +projects, directory trees or large files. It builds up an index for the text +in the files, and enables you to search this index efficiently. Information about Lucene is available on the <a href="http://lucene.apache.org/java/docs">Lucene website</a>. </p> <p> The plugin allows you to create a Lucene index, using one of the built-in analyzers, and then search the index. Once created, the index remains updated -when the files in it are changed. +when the files in it are changed inside jEdit (i.e. when their buffers are +saved). If the files in the index are changed externally (e.g. by updating them +from a version control system), you can ask the plugin to update the index. </p> <p> <a name="CreateIndex"> Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-12-28 05:16:53 UTC (rev 16757) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/SearchResults.java 2009-12-28 15:12:45 UTC (rev 16758) @@ -104,6 +104,8 @@ type.addActionListener(actionListener); clear = new RolloverButton(GUIUtilities.loadIcon( jEdit.getProperty("hypersearch-results.clear.icon"))); + clear.setToolTipText(jEdit.getProperty( + "hypersearch-results.clear.label")); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2010-01-04 14:10:28
|
Revision: 16834 http://jedit.svn.sourceforge.net/jedit/?rev=16834&view=rev Author: kpouer Date: 2010-01-04 14:10:22 +0000 (Mon, 04 Jan 2010) Log Message: ----------- updated for lucene 3.0.0 Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/build.xml plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/FileArrayProvider.java plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java Added Paths: ----------- plugins/LucenePlugin/trunk/lucene-core-3.0.0.jar plugins/LucenePlugin/trunk/lucene-highlighter-3.0.0.jar Removed Paths: ------------- plugins/LucenePlugin/trunk/lucene-core-2.4.1.jar plugins/LucenePlugin/trunk/lucene-highlighter-2.4.1.jar Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-04 14:10:22 UTC (rev 16834) @@ -7,7 +7,7 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.depend.2=plugin marker.MarkerSetsPlugin 0.2 plugin.gatchan.jedit.lucene.LucenePlugin.depend.3=optional plugin projectviewer.ProjectPlugin 2.9.0.0 -plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-2.4.1.jar lucene-highlighter-2.4.1.jar +plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-3.0.0.jar lucene-highlighter-3.0.0.jar plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=\ lucene.add-to-index lucene.add-to-newindex plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search - lucene.remove-index Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/build.xml 2010-01-04 14:10:22 UTC (rev 16834) @@ -28,14 +28,14 @@ <pathelement location="${jedit.install.dir}/jedit.jar" /> <pathelement location="${jedit.plugins.dir}/ProjectViewer.jar"/> <pathelement location="${jedit.plugins.dir}/MarkerSets.jar"/> - <pathelement location="${install.dir}/lucene-core-2.4.1.jar"/> - <pathelement location="${install.dir}/lucene-highlighter-2.4.1.jar"/> + <pathelement location="${install.dir}/lucene-core-3.0.0.jar"/> + <pathelement location="${install.dir}/lucene-highlighter-3.0.0.jar"/> </path> <target name="build.prepare"> <mkdir dir="${build.dir}" /> - <copy file="lucene-core-2.4.1.jar" todir="${install.dir}" /> - <copy file="lucene-highlighter-2.4.1.jar" todir="${install.dir}" /> + <copy file="lucene-core-3.0.0.jar" todir="${install.dir}" /> + <copy file="lucene-highlighter-3.0.0.jar" todir="${install.dir}" /> </target> </project> Deleted: plugins/LucenePlugin/trunk/lucene-core-2.4.1.jar =================================================================== (Binary files differ) Added: plugins/LucenePlugin/trunk/lucene-core-3.0.0.jar =================================================================== (Binary files differ) Property changes on: plugins/LucenePlugin/trunk/lucene-core-3.0.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: plugins/LucenePlugin/trunk/lucene-highlighter-2.4.1.jar =================================================================== (Binary files differ) Added: plugins/LucenePlugin/trunk/lucene-highlighter-3.0.0.jar =================================================================== (Binary files differ) Property changes on: plugins/LucenePlugin/trunk/lucene-highlighter-3.0.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AbstractIndex.java 2010-01-04 14:10:22 UTC (rev 16834) @@ -102,7 +102,8 @@ try { path.mkdirs(); - if (IndexWriter.isLocked(path.getAbsolutePath())) + FSDirectory directory = FSDirectory.open(path); + if (IndexWriter.isLocked(directory)) { Log.log(Log.WARNING, this, "The lucene index at " + path + " is locked"); int ret = GUIUtilities.confirm(jEdit.getActiveView(), "lucene.index.locked", @@ -110,10 +111,10 @@ JOptionPane.ERROR_MESSAGE); if (ret == JOptionPane.YES_OPTION) { - IndexWriter.unlock(FSDirectory.getDirectory(path)); + IndexWriter.unlock(directory); } } - writer = new IndexWriter(path, getAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); + writer = new IndexWriter(directory, getAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); } catch (IOException e) { @@ -133,7 +134,7 @@ { try { - reader = IndexReader.open(path.getPath()); + reader = IndexReader.open(FSDirectory.open(path)); readerMap.put(reader, 0); } catch (IOException e) Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/AnalyzerFactory.java 2010-01-04 14:10:22 UTC (rev 16834) @@ -10,6 +10,7 @@ import org.apache.lucene.analysis.StopAnalyzer; import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.util.Version; public class AnalyzerFactory { @@ -17,12 +18,12 @@ static { - analyzers.put("Standard", new StandardAnalyzer()); + analyzers.put("Standard", new StandardAnalyzer(Version.LUCENE_CURRENT)); analyzers.put("Simple", new SimpleAnalyzer()); analyzers.put("Java identifier", new SourceCodeAnalyzer()); analyzers.put("Whitespace", new WhitespaceAnalyzer()); analyzers.put("Keyword", new KeywordAnalyzer()); - analyzers.put("Stop", new StopAnalyzer()); + analyzers.put("Stop", new StopAnalyzer(Version.LUCENE_CURRENT)); } static String[] getAnalyzerNames() Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/CentralIndex.java 2010-01-04 14:10:22 UTC (rev 16834) @@ -25,6 +25,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.*; +import org.apache.lucene.store.FSDirectory; import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.EditBus; import org.gjt.sp.jedit.jEdit; @@ -59,20 +60,27 @@ { // test if the central index exists. If it doesnt exists, no need to start working // it is possible that it doesn't exists if the plugin is just installed an no index has been created yet - if (IndexReader.indexExists(path)) + try { - final BufferUpdate bufferUpdate = message; - if (bufferUpdate.getWhat() == BufferUpdate.SAVED) + if (IndexReader.indexExists(FSDirectory.open(path))) { - VFSManager.runInWorkThread(new Runnable() + final BufferUpdate bufferUpdate = message; + if (bufferUpdate.getWhat() == BufferUpdate.SAVED) { - public void run() + VFSManager.runInWorkThread(new Runnable() { - fileUpdated(bufferUpdate.getBuffer()); - } - }); + public void run() + { + fileUpdated(bufferUpdate.getBuffer()); + } + }); + } } } + catch (IOException e) + { + Log.log(Log.ERROR, this, e); + } } void createIndex(Index index) @@ -142,11 +150,16 @@ final List<String> documents = new ArrayList<String>(); try { - searcher.search(new TermQuery(new Term("indexName", indexName)), new HitCollector() + searcher.search(new TermQuery(new Term("indexName", indexName)), new Collector() { @Override - public void collect(int doc, float v) + public void setScorer(Scorer scorer) throws IOException { + } + + @Override + public void collect(int doc) throws IOException + { try { Document document = searcher.doc(doc); @@ -157,6 +170,17 @@ Log.log(Log.ERROR, this, e); } } + + @Override + public void setNextReader(IndexReader reader, int docBase) throws IOException + { + } + + @Override + public boolean acceptsDocsOutOfOrder() + { + return false; + } }); } catch (IOException e) Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/FileArrayProvider.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/FileArrayProvider.java 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/FileArrayProvider.java 2010-01-04 14:10:22 UTC (rev 16834) @@ -8,14 +8,17 @@ { private VFSFile[] fileArray; private int index = 0; + public FileArrayProvider(VFSFile[] files) { fileArray = files; } - public VFSFile next() { + + public VFSFile next() + { if (index >= fileArray.length) return null; - return fileArray[index]; + return fileArray[index++]; } } Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2010-01-04 13:01:08 UTC (rev 16833) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexImpl.java 2010-01-04 14:10:22 UTC (rev 16834) @@ -31,6 +31,7 @@ import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.TopDocs; +import org.apache.lucene.util.Version; import org.gjt.sp.jedit.io.VFS; import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.io.VFSFileFilter; @@ -239,15 +240,16 @@ Searcher searcher = getSearcher(); if (searcher == null) return; - QueryParser parser = new MultiFieldQueryParser(new String[]{"path", "content"}, getAnalyzer()); + QueryParser parser = new MultiFieldQueryParser(Version.LUCENE_CURRENT, new String[]{"path", "content"}, + getAnalyzer()); try { StringBuilder queryStr = new StringBuilder(); if (fileType.length() > 0) { if (query.length() > 0) - queryStr.append("(" + query + ") AND "); - queryStr.append("filetype:" + fileType); + queryStr.append('(').append(query).append(") AND "); + queryStr.append("filetype:").append(fileType); } else queryStr.append(query); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-01-05 07:42:14
|
Revision: 16840 http://jedit.svn.sourceforge.net/jedit/?rev=16840&view=rev Author: shlomy Date: 2010-01-05 07:42:00 +0000 (Tue, 05 Jan 2010) Log Message: ----------- The Highlighter contrib module now requires also the Memory contrib module (which was moved out of Highlighter-2.4.1). Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/build.xml Added Paths: ----------- plugins/LucenePlugin/trunk/lucene-memory-3.0.0.jar Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-04 23:04:09 UTC (rev 16839) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-05 07:42:00 UTC (rev 16840) @@ -7,7 +7,7 @@ plugin.gatchan.jedit.lucene.LucenePlugin.depend.1=jedit 04.03.17.00 plugin.gatchan.jedit.lucene.LucenePlugin.depend.2=plugin marker.MarkerSetsPlugin 0.2 plugin.gatchan.jedit.lucene.LucenePlugin.depend.3=optional plugin projectviewer.ProjectPlugin 2.9.0.0 -plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-3.0.0.jar lucene-highlighter-3.0.0.jar +plugin.gatchan.jedit.lucene.LucenePlugin.jars=lucene-core-3.0.0.jar lucene-highlighter-3.0.0.jar lucene-memory-3.0.0.jar plugin.gatchan.jedit.lucene.LucenePlugin.browser-menu=\ lucene.add-to-index lucene.add-to-newindex plugin.gatchan.jedit.lucene.LucenePlugin.menu=lucene-search - lucene.remove-index Modified: plugins/LucenePlugin/trunk/build.xml =================================================================== --- plugins/LucenePlugin/trunk/build.xml 2010-01-04 23:04:09 UTC (rev 16839) +++ plugins/LucenePlugin/trunk/build.xml 2010-01-05 07:42:00 UTC (rev 16840) @@ -30,12 +30,13 @@ <pathelement location="${jedit.plugins.dir}/MarkerSets.jar"/> <pathelement location="${install.dir}/lucene-core-3.0.0.jar"/> <pathelement location="${install.dir}/lucene-highlighter-3.0.0.jar"/> + <pathelement location="${install.dir}/lucene-memory-3.0.0.jar"/> </path> <target name="build.prepare"> <mkdir dir="${build.dir}" /> <copy file="lucene-core-3.0.0.jar" todir="${install.dir}" /> <copy file="lucene-highlighter-3.0.0.jar" todir="${install.dir}" /> - + <copy file="lucene-memory-3.0.0.jar" todir="${install.dir}" /> </target> </project> Added: plugins/LucenePlugin/trunk/lucene-memory-3.0.0.jar =================================================================== (Binary files differ) Property changes on: plugins/LucenePlugin/trunk/lucene-memory-3.0.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sh...@us...> - 2010-01-11 08:22:28
|
Revision: 16890 http://jedit.svn.sourceforge.net/jedit/?rev=16890&view=rev Author: shlomy Date: 2010-01-11 08:22:21 +0000 (Mon, 11 Jan 2010) Log Message: ----------- Add an appropriate message when a project cannot be locked for retrieving the file list to index. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-11 08:14:55 UTC (rev 16889) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-11 08:22:21 UTC (rev 16890) @@ -29,6 +29,7 @@ lucene.message.CreateProjectIndexError=Could not create an index for this project. lucene.message.CreateProjectIndexError.title=Project index error +lucene.message.LockProjectError=Project files cannot be retrieved now; try again later. # Options plugin.gatchan.jedit.lucene.LucenePlugin.option-group=Lucene IndexManagement Modified: plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java =================================================================== --- plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java 2010-01-11 08:14:55 UTC (rev 16889) +++ plugins/LucenePlugin/trunk/src/gatchan/jedit/lucene/IndexProjectAction.java 2010-01-11 08:22:21 UTC (rev 16890) @@ -6,6 +6,9 @@ import java.util.Collection; import java.util.Vector; +import javax.swing.JOptionPane; + +import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.io.VFSFile; import org.gjt.sp.jedit.io.VFSManager; @@ -19,6 +22,7 @@ static public final String MESSAGE = "lucene.message."; static public final String INDEX_ERROR = MESSAGE + "CreateProjectIndexError"; static public final String INDEX_ERROR_TITLE = MESSAGE + "CreateProjectIndexError.title"; + static public final String LOCK_PROJECT_ERROR = MESSAGE + "LockProjectError"; @Override public String getText() @@ -50,7 +54,7 @@ } } - private static class ProjectIndexer implements Runnable + private class ProjectIndexer implements Runnable { private VPTProject project; private Index index; @@ -87,7 +91,15 @@ return files.get(index++); } if (! project.tryLock()) + { + JOptionPane.showMessageDialog( + IndexProjectAction.this.viewer.getView(), + jEdit.getProperty(LOCK_PROJECT_ERROR), + jEdit.getProperty(INDEX_ERROR_TITLE), + JOptionPane.ERROR_MESSAGE, + null); return null; + } Collection<VPTNode> nodes = project.getOpenableNodes(); files = new Vector<VFSFile>(); for (VPTNode n : nodes) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ez...@us...> - 2010-01-14 17:39:12
|
Revision: 16927 http://jedit.svn.sourceforge.net/jedit/?rev=16927&view=rev Author: ezust Date: 2010-01-14 17:39:05 +0000 (Thu, 14 Jan 2010) Log Message: ----------- Label changes only. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/services.xml Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-14 16:50:18 UTC (rev 16926) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-14 17:39:05 UTC (rev 16927) @@ -18,7 +18,7 @@ lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> -lucene-search.label=Search +lucene-search.label=Lucene Search lucene-search.title=Search with Lucene lucene.remove-index.label=Delete an index Modified: plugins/LucenePlugin/trunk/services.xml =================================================================== --- plugins/LucenePlugin/trunk/services.xml 2010-01-14 16:50:18 UTC (rev 16926) +++ plugins/LucenePlugin/trunk/services.xml 2010-01-14 17:39:05 UTC (rev 16927) @@ -3,7 +3,7 @@ <!DOCTYPE SERVICES SYSTEM "services.dtd"> <SERVICES> - <SERVICE CLASS="projectviewer.action.Action" NAME="Create/update Lucene index for project"> + <SERVICE CLASS="projectviewer.action.Action" NAME="Index in Lucene"> new gatchan.jedit.lucene.IndexProjectAction(); </SERVICE> </SERVICES> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ez...@us...> - 2010-01-14 17:43:36
|
Revision: 16928 http://jedit.svn.sourceforge.net/jedit/?rev=16928&view=rev Author: ezust Date: 2010-01-14 17:43:30 +0000 (Thu, 14 Jan 2010) Log Message: ----------- Made docs consistent. Modified Paths: -------------- plugins/LucenePlugin/trunk/LucenePlugin.props plugins/LucenePlugin/trunk/docs/LucenePlugin.html Modified: plugins/LucenePlugin/trunk/LucenePlugin.props =================================================================== --- plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-14 17:39:05 UTC (rev 16927) +++ plugins/LucenePlugin/trunk/LucenePlugin.props 2010-01-14 17:43:30 UTC (rev 16928) @@ -16,8 +16,8 @@ plugin.gatchan.jedit.lucene.LucenePlugin.description=\ LucenePlugin plugin provides an interface to the Lucene search engine in jEdit. -lucene.add-to-index.label=<html>Add selected file(s) to an <b>existing index</b></html> -lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new index</b></html> +lucene.add-to-index.label=Index selected file(s) in Lucene +lucene.add-to-newindex.label=<html>Add selected file(s) to a <b>new Lucene index</b></html> lucene-search.label=Lucene Search lucene-search.title=Search with Lucene lucene.remove-index.label=Delete an index Modified: plugins/LucenePlugin/trunk/docs/LucenePlugin.html =================================================================== --- plugins/LucenePlugin/trunk/docs/LucenePlugin.html 2010-01-14 17:39:05 UTC (rev 16927) +++ plugins/LucenePlugin/trunk/docs/LucenePlugin.html 2010-01-14 17:43:30 UTC (rev 16928) @@ -24,7 +24,7 @@ analyzers, and then search the index. Once created, the index remains updated when the files in it are changed inside jEdit (i.e. when their buffers are saved). If the files in the index are changed externally (e.g. by updating them -from a version control system), you can ask the plugin to update the index. +from a version control system), you can ask the plugin to update the index. </p> <p> <a name="CreateIndex"> @@ -36,7 +36,7 @@ <ul> <li> To create an index for a project, right-click the project in the ProjectViewer -dockable window, and select "Create/update Lucene index for project". +dockable window, and select "Index in Lucene". <li> To create an index for a directory tree, right-click the root of the directory tree in the File System Browser dockable window, and select Plugins -> @@ -75,8 +75,8 @@ </a> <ol> <li> -Open the "Search with Lucene" dockable window using Plugins -> LucenePlugin -> -Search. +Open the "Search with Lucene" dockable window using <tt>Plugins -> LucenePlugin -> +Lucene Search </tt>. <li> Select the index to search in the combo-box on the right of the dockable. <li> @@ -116,7 +116,7 @@ <li> To report bugs, use the <a href="https://sourceforge.net/tracker/?group_id=588&atid=565475"> -Plugins Bugs tracker </a>. Specify the plugin name in the Summary field. +Plugins Bugs tracker </a>. Specify the plugin name in the Summary field. <li> To ask for new features, use the <a href="https://sourceforge.net/tracker/?group_id=588&atid=997936"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |