IndexDatabase.java revision 504
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
405N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
928N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.index;
376N/A
0N/Aimport java.io.BufferedInputStream;
1327N/Aimport java.io.File;
1327N/Aimport java.io.FileInputStream;
1327N/Aimport java.io.FileNotFoundException;
1327N/Aimport java.io.IOException;
1327N/Aimport java.io.InputStream;
1327N/Aimport java.util.ArrayList;
234N/Aimport java.util.Arrays;
0N/Aimport java.util.Comparator;
1318N/Aimport java.util.List;
1318N/Aimport java.util.concurrent.ExecutorService;
428N/Aimport java.util.logging.Level;
1327N/Aimport java.util.logging.Logger;
1327N/Aimport org.apache.lucene.document.DateTools;
0N/Aimport org.apache.lucene.document.Document;
350N/Aimport org.apache.lucene.index.IndexReader;
0N/Aimport org.apache.lucene.index.IndexWriter;
1318N/Aimport org.apache.lucene.index.Term;
0N/Aimport org.apache.lucene.index.TermEnum;
0N/Aimport org.apache.lucene.search.spell.LuceneDictionary;
816N/Aimport org.apache.lucene.search.spell.SpellChecker;
928N/Aimport org.apache.lucene.store.FSDirectory;
928N/Aimport org.opensolaris.opengrok.analysis.AnalyzerGuru;
928N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzer;
986N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
350N/Aimport org.opensolaris.opengrok.configuration.Project;
1185N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
0N/Aimport org.opensolaris.opengrok.history.HistoryGuru;
1385N/Aimport org.opensolaris.opengrok.web.Util;
234N/A
125N/A/**
615N/A * This class is used to create / update the index databases. Currently we use
0N/A * one index database per project.
0N/A *
0N/A * @author Trond Norbye
1195N/A */
0N/Apublic class IndexDatabase {
0N/A
0N/A private Project project;
0N/A private FSDirectory indexDirectory;
0N/A private FSDirectory spellDirectory;
816N/A private IndexWriter writer;
928N/A private TermEnum uidIter;
1318N/A private IgnoredNames ignoredNames;
0N/A private AnalyzerGuru analyzerGuru;
0N/A private File xrefDir;
1327N/A private boolean interrupted;
615N/A private List<IndexChangedListener> listeners;
615N/A private File dirtyFile;
615N/A private final Object lock = new Object();
947N/A private boolean dirty;
947N/A private boolean running;
947N/A private List<String> directories;
947N/A private static final Logger log = Logger.getLogger(IndexDatabase.class.getName());
1318N/A
947N/A /**
0N/A * Create a new instance of the Index Database. Use this constructor if
0N/A * you don't use any projects
0N/A *
0N/A * @throws java.io.IOException if an error occurs while creating directories
1190N/A */
0N/A public IndexDatabase() throws IOException {
0N/A initialize();
0N/A }
0N/A
1190N/A /**
0N/A * Create a new instance of an Index Database for a given project
0N/A * @param project the project to create the database for
0N/A * @throws java.io.IOException if an errror occurs while creating directories
0N/A */
1190N/A public IndexDatabase(Project project) throws IOException {
0N/A this.project = project;
0N/A initialize();
0N/A }
0N/A
1190N/A /**
0N/A * Update the index database for all of the projects. Print progress to
0N/A * standard out.
0N/A * @param executor An executor to run the job
0N/A * @throws IOException if an error occurs
234N/A */
0N/A public static void updateAll(ExecutorService executor) throws IOException {
0N/A updateAll(executor, null);
0N/A }
0N/A
986N/A /**
0N/A * Update the index database for all of the projects
0N/A * @param executor An executor to run the job
816N/A * @param listener where to signal the changes to the database
816N/A * @throws IOException if an error occurs
816N/A */
456N/A static void updateAll(ExecutorService executor, IndexChangedListener listener) throws IOException {
234N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
234N/A if (env.hasProjects()) {
1238N/A for (Project project : env.getProjects()) {
816N/A final IndexDatabase db = new IndexDatabase(project);
816N/A if (listener != null) {
816N/A db.addIndexChangedListener(listener);
816N/A }
1190N/A executor.submit(new Runnable() {
1185N/A
1185N/A public void run() {
1318N/A try {
1185N/A db.update();
816N/A } catch (Exception e) {
0N/A log.log(Level.WARNING,"Problem updating lucene index database: ",e);
0N/A }
0N/A }
0N/A });
816N/A }
234N/A } else {
236N/A final IndexDatabase db = new IndexDatabase();
985N/A if (listener != null) {
986N/A db.addIndexChangedListener(listener);
986N/A }
986N/A
986N/A executor.submit(new Runnable() {
985N/A
986N/A public void run() {
986N/A try {
986N/A db.update();
986N/A } catch (Exception e) {
986N/A log.log(Level.FINE,"Problem updating lucene index database: ",e);
986N/A }
986N/A }
985N/A });
985N/A }
236N/A }
538N/A
986N/A @SuppressWarnings("PMD.CollapsibleIfStatements")
986N/A private synchronized void initialize() throws IOException {
986N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
986N/A File indexDir = new File(env.getDataRootFile(), "index");
538N/A File spellDir = new File(env.getDataRootFile(), "spellIndex");
236N/A if (project != null) {
986N/A indexDir = new File(indexDir, project.getPath());
236N/A spellDir = new File(spellDir, project.getPath());
236N/A }
816N/A
816N/A if (!indexDir.exists() && !indexDir.mkdirs()) {
816N/A // to avoid race conditions, just recheck..
816N/A if (!indexDir.exists()) {
1190N/A throw new FileNotFoundException("Failed to create root directory [" + indexDir.getAbsolutePath() + "]");
816N/A }
816N/A }
816N/A
928N/A if (!spellDir.exists() && !spellDir.mkdirs()) {
1318N/A if (!spellDir.exists()) {
928N/A throw new FileNotFoundException("Failed to create root directory [" + spellDir.getAbsolutePath() + "]");
816N/A }
816N/A }
1318N/A
928N/A if (!env.isUsingLuceneLocking()) {
816N/A FSDirectory.setDisableLocks(true);
1190N/A }
816N/A indexDirectory = FSDirectory.getDirectory(indexDir);
816N/A spellDirectory = FSDirectory.getDirectory(spellDir);
816N/A ignoredNames = env.getIgnoredNames();
816N/A analyzerGuru = new AnalyzerGuru();
816N/A if (env.isGenerateHtml()) {
235N/A xrefDir = new File(env.getDataRootFile(), "xref");
235N/A }
816N/A listeners = new ArrayList<IndexChangedListener>();
816N/A dirtyFile = new File(indexDir, "dirty");
816N/A dirty = dirtyFile.exists();
816N/A directories = new ArrayList<String>();
816N/A }
816N/A
816N/A /**
1318N/A * By default the indexer will traverse all directories in the project.
1318N/A * If you add directories with this function update will just process
816N/A * the specified directories.
816N/A *
816N/A * @param dir The directory to scan
928N/A * @return <code>true</code> if the file is added, false oth
1318N/A */
816N/A @SuppressWarnings("PMD.UseStringBufferForStringAppends")
1318N/A public boolean addDirectory(String dir) {
816N/A String directory = dir;
1318N/A if (directory.startsWith("\\")) {
1318N/A directory = directory.replace('\\', '/');
1318N/A } else if (directory.charAt(0) != '/') {
1318N/A directory = "/" + directory;
928N/A }
816N/A File file = new File(RuntimeEnvironment.getInstance().getSourceRootFile(), directory);
816N/A if (file.exists()) {
1318N/A directories.add(directory);
928N/A return true;
816N/A } else {
816N/A return false;
816N/A }
816N/A }
816N/A
816N/A /**
816N/A * Update the content of this index database
816N/A * @throws IOException if an error occurs
816N/A */
816N/A public void update() throws IOException {
235N/A synchronized (lock) {
235N/A if (running) {
0N/A throw new IOException("Indexer already running!");
494N/A }
0N/A running = true;
0N/A interrupted = false;
0N/A }
816N/A try {
0N/A writer = new IndexWriter(indexDirectory, AnalyzerGuru.getAnalyzer());
830N/A writer.setMaxFieldLength(RuntimeEnvironment.getInstance().getIndexWordLimit());
0N/A
0N/A if (directories.isEmpty()) {
235N/A if (project == null) {
235N/A directories.add("");
816N/A } else {
986N/A directories.add(project.getPath());
986N/A }
986N/A }
986N/A
986N/A for (String dir : directories) {
986N/A File sourceRoot;
234N/A if ("".equals(dir)) {
1190N/A sourceRoot = RuntimeEnvironment.getInstance().getSourceRootFile();
234N/A } else {
234N/A sourceRoot = new File(RuntimeEnvironment.getInstance().getSourceRootFile(), dir);
234N/A }
830N/A
830N/A String startuid = Util.uid(dir, "");
1185N/A IndexReader reader = IndexReader.open(indexDirectory); // open existing index
234N/A try {
234N/A uidIter = reader.terms(new Term("u", startuid)); // init uid iterator
816N/A
0N/A indexDown(sourceRoot, dir);
0N/A
986N/A while (uidIter.term() != null && uidIter.term().field().equals("u") && uidIter.term().text().startsWith(startuid)) {
1327N/A removeFile();
1327N/A uidIter.next();
0N/A }
986N/A } finally {
816N/A reader.close();
0N/A }
816N/A }
0N/A } finally {
986N/A if (writer != null) {
4N/A try {
0N/A writer.close();
4N/A } catch (IOException e) {
986N/A }
0N/A }
1327N/A synchronized (lock) {
1327N/A running = false;
1327N/A }
0N/A }
1190N/A
0N/A if (!isInterrupted() && isDirty()) {
0N/A if (RuntimeEnvironment.getInstance().isOptimizeDatabase()) {
0N/A optimize();
4N/A }
0N/A createSpellingSuggestions();
4N/A }
0N/A }
1327N/A
1327N/A /**
1327N/A * Optimize all index databases
0N/A * @param executor An executor to run the job
0N/A * @throws IOException if an error occurs
1318N/A */
1318N/A static void optimizeAll(ExecutorService executor) throws IOException {
0N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
816N/A if (env.hasProjects()) {
816N/A for (Project project : env.getProjects()) {
816N/A final IndexDatabase db = new IndexDatabase(project);
816N/A if (db.isDirty()) {
816N/A executor.submit(new Runnable() {
816N/A
816N/A public void run() {
816N/A db.optimize();
816N/A }
816N/A });
816N/A }
816N/A }
816N/A } else {
1185N/A final IndexDatabase db = new IndexDatabase();
1185N/A if (db.isDirty()) {
1185N/A executor.submit(new Runnable() {
1185N/A
816N/A public void run() {
816N/A try {
816N/A db.update();
816N/A } catch (IOException e) {
1185N/A log.log(Level.FINE,"Problem updating lucene index database: ",e);
816N/A }
928N/A }
816N/A });
816N/A }
816N/A }
1327N/A }
1327N/A
816N/A /**
816N/A * Optimize the index database
816N/A */
816N/A public void optimize() {
816N/A synchronized (lock) {
816N/A if (running) {
1185N/A log.warning("Optimize terminated... Someone else is updating / optimizing it!");
816N/A return ;
1327N/A }
1327N/A running = true;
816N/A }
816N/A IndexWriter wrt = null;
816N/A try {
816N/A if (RuntimeEnvironment.getInstance().isVerbose()) {
234N/A log.info("Optimizing the index ... ");
816N/A }
816N/A wrt = new IndexWriter(indexDirectory, null, false);
816N/A wrt.optimize();
816N/A if (RuntimeEnvironment.getInstance().isVerbose()) {
0N/A log.info("done");
0N/A }
0N/A synchronized (lock) {
816N/A if (dirtyFile.exists() && !dirtyFile.delete()) {
0N/A log.fine("Failed to remove \"dirty-file\": " +
816N/A dirtyFile.getAbsolutePath());
1185N/A }
350N/A dirty = false;
1190N/A }
350N/A } catch (IOException e) {
928N/A log.severe("ERROR: optimizing index: " + e);
350N/A } finally {
816N/A if (wrt != null) {
1190N/A try {
0N/A wrt.close();
0N/A } catch (IOException e) {
1185N/A }
234N/A }
0N/A synchronized (lock) {
0N/A running = false;
1185N/A }
439N/A }
1385N/A }
1385N/A
380N/A /**
1190N/A * Generate a spelling suggestion for the definitions stored in defs
380N/A */
1195N/A public void createSpellingSuggestions() {
380N/A IndexReader indexReader = null;
816N/A SpellChecker checker = null;
816N/A
0N/A try {
0N/A if (RuntimeEnvironment.getInstance().isVerbose()) {
0N/A log.info("Generating spelling suggestion index ... ");
0N/A }
0N/A indexReader = IndexReader.open(indexDirectory);
0N/A checker = new SpellChecker(spellDirectory);
0N/A checker.indexDictionary(new LuceneDictionary(indexReader, "defs"));
0N/A if (RuntimeEnvironment.getInstance().isVerbose()) {
0N/A log.info("done");
0N/A }
0N/A } catch (IOException e) {
0N/A log.severe("ERROR: Generating spelling: " + e);
1327N/A } finally {
1327N/A if (indexReader != null) {
0N/A try {
0N/A indexReader.close();
0N/A } catch (IOException e) {
1327N/A }
1327N/A }
0N/A if (spellDirectory != null) {
0N/A spellDirectory.close();
0N/A }
0N/A }
234N/A }
0N/A
0N/A private boolean isDirty() {
0N/A synchronized (lock) {
0N/A return dirty;
0N/A }
1327N/A }
1327N/A
350N/A private void setDirty() {
1327N/A synchronized (lock) {
1327N/A try {
615N/A if (!dirty && !dirtyFile.createNewFile()) {
1327N/A if (!dirtyFile.exists()) {
1327N/A log.log(Level.FINE, "Failed to create \"dirty-file\": ", dirtyFile.getAbsolutePath());
0N/A }
0N/A dirty = true;
1190N/A }
0N/A } catch (IOException e) {
1190N/A log.log(Level.FINE,"When creating dirty file: ",e);
0N/A }
0N/A }
0N/A }
0N/A /**
0N/A * Remove a stale file (uidIter.term().text()) from the index database
0N/A * (and the xref file)
0N/A * @throws java.io.IOException if an error occurs
0N/A */
1190N/A private void removeFile() throws IOException {
0N/A String path = Util.uid2url(uidIter.term().text());
0N/A
0N/A for (IndexChangedListener listener : listeners) {
0N/A listener.fileRemoved(path);
0N/A }
0N/A writer.deleteDocuments(uidIter.term());
0N/A
0N/A File xrefFile = new File(xrefDir, path);
1190N/A File parent = xrefFile.getParentFile();
0N/A
0N/A if (!xrefFile.delete()) {
0N/A log.info("Failed to remove obsolete xref-file: " +
0N/A xrefFile.getAbsolutePath());
0N/A }
0N/A
0N/A if (!parent.delete()) {
0N/A // Ignore. The directory is most likely not empty, but to check
1190N/A // would just increase the disk IO even more..
0N/A }
0N/A
0N/A setDirty();
0N/A }
0N/A
0N/A /**
0N/A * Add a file to the Lucene index (and generate a xref file)
0N/A * @param file The file to add
1190N/A * @param path The path to the file (from source root)
0N/A * @throws java.io.IOException if an error occurs
0N/A */
0N/A private void addFile(File file, String path) throws IOException {
0N/A InputStream in;
0N/A try {
0N/A in = new BufferedInputStream(new FileInputStream(file));
0N/A } catch (IOException ex) {
0N/A log.warning("Warning: " + ex.getMessage());
1190N/A return;
0N/A }
0N/A FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, path);
0N/A
0N/A for (IndexChangedListener listener : listeners) {
0N/A listener.fileAdded(path, fa.getClass().getSimpleName());
0N/A }
0N/A
0N/A Document d = analyzerGuru.getDocument(file, in, path, fa);
1190N/A if (d == null) {
0N/A log.warning("Warning: did not add " + path);
0N/A } else {
0N/A writer.addDocument(d, fa);
0N/A Genre g = fa.getFactory().getGenre();
0N/A if (xrefDir != null && (g == Genre.PLAIN || g == Genre.XREFABLE)) {
0N/A File xrefFile = new File(xrefDir, path);
0N/A if (!xrefFile.getParentFile().mkdirs()) {
0N/A // The failure was most likely because the file already
1190N/A // existed. But to check for the file first and only
0N/A // add it if it doesn't exists would only increase the
0N/A // file IO...
0N/A }
0N/A fa.writeXref(xrefDir, path);
0N/A }
0N/A setDirty();
0N/A }
0N/A
1190N/A try { in.close(); } catch (Exception e) {}
0N/A }
0N/A
0N/A /**
0N/A * Check if I should accept this file into the index database
0N/A * @param file the file to check
0N/A * @return true if the file should be included, false otherwise
0N/A */
0N/A private boolean accept(File file) {
1190N/A if (ignoredNames.ignore(file)) {
0N/A return false;
0N/A }
0N/A
0N/A if (!file.canRead()) {
0N/A log.warning("Warning: could not read " + file.getAbsolutePath());
0N/A return false;
0N/A }
0N/A
0N/A try {
if (!file.getAbsolutePath().equals(file.getCanonicalPath())) {
if (file.getParentFile().equals(file.getCanonicalFile().getParentFile())) {
// Lets support symlinks within the same directory, this
// should probably be extended to within the same repository
return true;
} else {
log.warning("Warning: ignored non-local symlink " + file.getAbsolutePath() +
" -> " + file.getCanonicalPath());
return false;
}
}
} catch (IOException exp) {
log.warning("Warning: Failed to resolve name: " + file.getAbsolutePath());
log.log(Level.FINE,"Stack Trace: ",exp);
}
if (file.isDirectory()) {
// always accept directories so that their files can be examined
return true;
}
if (HistoryGuru.getInstance().hasHistory(file)) {
// versioned files should always be accepted
return true;
}
// this is an unversioned file, check if it should be indexed
return !RuntimeEnvironment.getInstance().isIndexVersionedFilesOnly();
}
/**
* Generate indexes recursively
* @param dir the root indexDirectory to generate indexes for
* @param path the path
*/
private void indexDown(File dir, String parent) throws IOException {
if (isInterrupted()) {
return;
}
if (!accept(dir)) {
return;
}
File[] files = dir.listFiles();
if (files == null) {
log.severe("Failed to get file listing for: " + dir.getAbsolutePath());
return;
}
Arrays.sort(files, new Comparator<File>() {
public int compare(File p1, File p2) {
return p1.getName().compareTo(p2.getName());
}
});
for (File file : files) {
if (accept(file)) {
String path = parent + '/' + file.getName();
if (file.isDirectory()) {
indexDown(file, path);
} else {
if (uidIter == null) {
addFile(file, path);
} else {
String uid = Util.uid(path, DateTools.timeToString(file.lastModified(), DateTools.Resolution.MILLISECOND)); // construct uid for doc
while (uidIter.term() != null && uidIter.term().field().equals("u") &&
uidIter.term().text().compareTo(uid) < 0) {
removeFile();
uidIter.next();
}
if (uidIter.term() != null && uidIter.term().field().equals("u") &&
uidIter.term().text().compareTo(uid) == 0) {
uidIter.next(); // keep matching docs
} else {
addFile(file, path);
}
}
}
}
}
}
/**
* Interrupt the index generation (and the index generation will stop as
* soon as possible)
*/
public void interrupt() {
synchronized (lock) {
interrupted = true;
}
}
private boolean isInterrupted() {
synchronized (lock) {
return interrupted;
}
}
/**
* Register an object to receive events when modifications is done to the
* index database.
*
* @param listener the object to receive the events
*/
public void addIndexChangedListener(IndexChangedListener listener) {
listeners.add(listener);
}
/**
* Remove an object from the lists of objects to receive events when
* modifications is done to the index database
*
* @param listener the object to remove
*/
public void removeIndexChangedListener(IndexChangedListener listener) {
listeners.remove(listener);
}
/**
* List all files in all of the index databases
* @throws IOException if an error occurs
*/
public static void listAllFiles() throws IOException {
listAllFiles(null);
}
/**
* List all files in some of the index databases
* @param subFiles Subdirectories for the various projects to list the files
* for (or null or an empty list to dump all projects)
* @throws IOException if an error occurs
*/
public static void listAllFiles(List<String> subFiles) throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.hasProjects()) {
if (subFiles == null || subFiles.isEmpty()) {
for (Project project : env.getProjects()) {
IndexDatabase db = new IndexDatabase(project);
db.listFiles();
}
} else {
for (String path : subFiles) {
Project project = Project.getProject(path);
if (project == null) {
log.warning("Warning: Could not find a project for \"" + path + "\"");
} else {
IndexDatabase db = new IndexDatabase(project);
db.listFiles();
}
}
}
} else {
IndexDatabase db = new IndexDatabase();
db.listFiles();
}
}
/**
* List all of the files in this index database
*
* @throws IOException If an IO error occurs while reading from the database
*/
public void listFiles() throws IOException {
IndexReader ireader = null;
TermEnum iter = null;
try {
ireader = IndexReader.open(indexDirectory); // open existing index
iter = ireader.terms(new Term("u", "")); // init uid iterator
while (iter.term() != null) {
log.info(Util.uid2url(iter.term().text()));
iter.next();
}
} finally {
if (iter != null) {
try {
iter.close();
} catch (IOException e) {
}
}
if (ireader != null) {
try {
ireader.close();
} catch (IOException e) {
}
}
}
}
static void listFrequentTokens() throws IOException {
listFrequentTokens(null);
}
static void listFrequentTokens(List<String> subFiles) throws IOException {
final int limit = 4;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.hasProjects()) {
if (subFiles == null || subFiles.isEmpty()) {
for (Project project : env.getProjects()) {
IndexDatabase db = new IndexDatabase(project);
db.listTokens(4);
}
} else {
for (String path : subFiles) {
Project project = Project.getProject(path);
if (project == null) {
log.warning("Warning: Could not find a project for \"" + path + "\"");
} else {
IndexDatabase db = new IndexDatabase(project);
db.listTokens(4);
}
}
}
} else {
IndexDatabase db = new IndexDatabase();
db.listTokens(limit);
}
}
public void listTokens(int freq) throws IOException {
IndexReader ireader = null;
TermEnum iter = null;
try {
ireader = IndexReader.open(indexDirectory);
iter = ireader.terms(new Term("defs", ""));
while (iter.term() != null) {
if (iter.term().field().startsWith("f")) {
if (iter.docFreq() > 16 && iter.term().text().length() > freq) {
log.warning(iter.term().text());
}
iter.next();
} else {
break;
}
}
} finally {
if (iter != null) {
try {
iter.close();
} catch (IOException e) {
}
}
if (ireader != null) {
try {
ireader.close();
} catch (IOException e) {
}
}
}
}
/**
* Get an indexReader for the Index database where a given file
* @param path the file to get the database for
* @return The index database where the file should be located or null if
* it cannot be located.
*/
public static IndexReader getIndexReader(String path) {
IndexReader ret = null;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
File indexDir = new File(env.getDataRootFile(), "index");
if (env.hasProjects()) {
Project p = Project.getProject(path);
if (p == null) {
return null;
} else {
indexDir = new File(indexDir, p.getPath());
}
}
if (indexDir.exists() && IndexReader.indexExists(indexDir)) {
try {
ret = IndexReader.open(indexDir);
} catch (Exception ex) {
log.severe("Failed to open index: " + indexDir.getAbsolutePath());
log.log(Level.FINE,"Stack Trace: ",ex);
}
}
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final IndexDatabase other = (IndexDatabase) obj;
if (this.project != other.project && (this.project == null || !this.project.equals(other.project))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 41 * hash + (this.project == null ? 0 : this.project.hashCode());
return hash;
}
}