IndexDatabase.java revision 297
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* This class is used to create / update the index databases. Currently we use
* one index database per project.
*
* @author Trond Norbye
*/
public class IndexDatabase {
private FSDirectory indexDirectory;
private FSDirectory spellDirectory;
private IndexWriter writer;
private IndexReader reader;
private IgnoredNames ignoredNames;
private AnalyzerGuru analyzerGuru;
private boolean interrupted;
private boolean dirty;
/**
* Create a new instance of the Index Database. Use this constructor if
* you don't use any projects
*
* @throws java.io.IOException if an error occurs while creating directories
*/
public IndexDatabase() throws IOException {
initialize();
}
/**
* Create a new instance of an Index Database for a given project
* @param project the project to create the database for
* @throws java.io.IOException if an errror occurs while creating directories
*/
initialize();
}
/**
* Update the index database for all of the projects. Print progress to
* standard out.
* @param executor An executor to run the job
* @throws java.lang.Exception if an error occurs
*/
}
/**
* Update the index database for all of the projects
* @param executor An executor to run the job
* @param listener where to signal the changes to the database
* @throws java.lang.Exception if an error occurs
*/
if (env.hasProjects()) {
}
public void run() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
} else {
}
public void run() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
private void initialize() throws IOException {
}
// to avoid race conditions, just recheck..
throw new FileNotFoundException("Failed to create root directory [" + indexDir.getAbsolutePath() + "]");
}
throw new FileNotFoundException("Failed to create root directory [" + spellDir.getAbsolutePath() + "]");
}
}
if (!env.isUsingLuceneLocking()) {
FSDirectory.setDisableLocks(true);
}
analyzerGuru = new AnalyzerGuru();
if (env.isGenerateHtml()) {
}
}
/**
* By default the indexer will traverse all directories in the project.
* If you add directories with this function update will just process
* the specified directories.
*
* @param dir The directory to scan
* @return <code>true</code> if the file is added, false oth
*/
}
return false;
} else {
return true;
}
}
/**
* Update the content of this index database
* @throws java.lang.Exception if an error occurs
*/
interrupted = false;
try {
} else {
}
}
} else {
}
while (uidIter.term() != null && uidIter.term().field().equals("u") && uidIter.term().text().startsWith(startuid)) {
removeFile();
}
}
} finally {
try {
} catch (IOException e) {
}
}
try {
} catch (IOException e) {
}
}
}
if (!interrupted && dirty) {
optimize();
}
}
}
/**
* Optimize all index databases
* @param executor An executor to run the job
* @throws java.lang.Exception if an error occurs
*/
if (env.hasProjects()) {
public void run() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
} else {
public void run() {
try {
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
}
/**
* Optimize the index database
*/
public void optimize() {
try {
}
}
dirty = false;
} catch (IOException e) {
} finally {
try {
} catch (IOException e) {
}
}
}
}
/**
* Generate a spelling suggestion for the definitions stored in defs
*/
public void createSpellingSuggestions() {
try {
}
}
} catch (IOException e) {
} finally {
if (indexReader != null) {
try {
indexReader.close();
} catch (IOException e) {
}
}
if (spellDirectory != null) {
}
}
}
private void setDirty() {
try {
if (!dirty) {
dirty = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Remove a stale file (uidIter.term().text()) from the index database
* (and the xref file)
* @throws java.io.IOException if an error occurs
*/
private void removeFile() throws IOException {
}
setDirty();
}
/**
* Add a file to the Lucene index (and generate a xref file)
* @param file The file to add
* @param path The path to the file (from source root)
* @throws java.io.IOException if an error occurs
*/
try {
} catch (IOException ex) {
return;
}
}
if (d != null) {
}
setDirty();
} else {
}
}
/**
* Check if I should accept this file into the index database
* @param file the file to check
* @return true if the file should be included, false otherwise
*/
return false;
}
return false;
}
try {
return false;
}
} catch (IOException exp) {
}
return true;
}
/**
* Generate indexes recursively
* @param dir the root indexDirectory to generate indexes for
* @param path the path
*/
if (interrupted) {
return;
}
return;
}
return;
}
}
});
if (file.isDirectory()) {
} else {
String uid = Util.uid(path, DateTools.timeToString(file.lastModified(), DateTools.Resolution.MILLISECOND)); // construct uid for doc
removeFile();
}
} else {
}
} else {
}
}
}
}
}
/**
* Interrupt the index generation (and the index generation will stop as
* soon as possible)
*/
public void interrupt() {
interrupted = true;
}
/**
* Register an object to receive events when modifications is done to the
* index database.
*
* @param listener the object to receive the events
*/
}
/**
* 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
*/
}
/**
* List all files in all of the index databases
* @throws java.lang.Exception if an error occurs
*/
public static void listAllFiles() throws Exception {
}
/**
* 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 java.lang.Exception if an error occurs
*/
if (!env.hasProjects()) {
} else {
}
} else {
} else {
}
}
}
}
}
/**
* List all of the files in this index database
*
* @throws java.lang.Exception if an error occurs
*/
try {
}
} finally {
try {
} catch (Exception e) {
}
}
try {
} catch (Exception e) {
}
}
}
}
static void listFrequentTokens() throws Exception {
}
final int limit = 4;
if (!env.hasProjects()) {
} else {
}
} else {
} else {
}
}
}
}
}
try {
}
} else {
break;
}
}
} finally {
try {
} catch (Exception e) {
}
}
try {
} catch (Exception 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.
*/
if (env.hasProjects()) {
if (p != null) {
} else {
return null;
}
}
try {
}
}
return ret;
}
return false;
}
return false;
}
if (this.project != other.project && (this.project == null || !this.project.equals(other.project))) {
return false;
}
return true;
}
public int hashCode() {
int hash = 7;
return hash;
}
}