use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class SearchEngine method searchMultiDatabase.
/**
* Perform search on multiple indexes in parallel.
* @param paging whether to use paging (if yes, first X pages will load
* faster)
* @param root list of projects to search
* @throws IOException
*/
private void searchMultiDatabase(List<Project> root, boolean paging) throws IOException {
SortedSet<String> projects = new TreeSet<>();
for (Project p : root) {
projects.add(p.getName());
}
// We use MultiReader even for single project. This should
// not matter given that MultiReader is just a cheap wrapper
// around set of IndexReader objects.
MultiReader searchables = RuntimeEnvironment.getInstance().getMultiReader(projects, searcherList);
searcher = new IndexSearcher(searchables);
searchIndex(searcher, paging);
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class IndexDatabase method updateAll.
/**
* Update the index database for all of the projects.
*
* @param listener where to signal the changes to the database
* @throws IOException if an error occurs
*/
static CountDownLatch updateAll(IndexChangedListener listener) throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
List<IndexDatabase> dbs = new ArrayList<>();
if (env.hasProjects()) {
for (Project project : env.getProjectList()) {
dbs.add(new IndexDatabase(project));
}
} else {
dbs.add(new IndexDatabase());
}
IndexerParallelizer parallelizer = RuntimeEnvironment.getInstance().getIndexerParallelizer();
CountDownLatch latch = new CountDownLatch(dbs.size());
for (IndexDatabase d : dbs) {
final IndexDatabase db = d;
if (listener != null) {
db.addIndexChangedListener(listener);
}
parallelizer.getFixedExecutor().submit(() -> {
try {
db.update();
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, String.format("Problem updating index database in directory %s: ", db.indexDirectory.getDirectory()), e);
} finally {
latch.countDown();
}
});
}
return latch;
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class IndexDatabase method optimizeAll.
/**
* Optimize all index databases.
*
* @throws IOException if an error occurs
*/
static CountDownLatch optimizeAll() throws IOException {
List<IndexDatabase> dbs = new ArrayList<>();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
IndexerParallelizer parallelizer = env.getIndexerParallelizer();
if (env.hasProjects()) {
for (Project project : env.getProjectList()) {
dbs.add(new IndexDatabase(project));
}
} else {
dbs.add(new IndexDatabase());
}
CountDownLatch latch = new CountDownLatch(dbs.size());
for (IndexDatabase d : dbs) {
final IndexDatabase db = d;
if (db.isDirty()) {
parallelizer.getFixedExecutor().submit(() -> {
try {
db.update();
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
} finally {
latch.countDown();
}
});
}
}
return latch;
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class IndexDatabase method getIndexReader.
/**
* 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.
*/
@SuppressWarnings("java:S2095")
public static IndexReader getIndexReader(String path) {
IndexReader ret = null;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
File indexDir = new File(env.getDataRootFile(), INDEX_DIR);
if (env.hasProjects()) {
Project p = Project.getProject(path);
if (p == null) {
return null;
}
indexDir = new File(indexDir, p.getPath());
}
try {
FSDirectory fdir = FSDirectory.open(indexDir.toPath(), NoLockFactory.INSTANCE);
if (indexDir.exists() && DirectoryReader.indexExists(fdir)) {
ret = DirectoryReader.open(fdir);
}
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Failed to open index: {0}", indexDir.getAbsolutePath());
LOGGER.log(Level.FINE, "Stack Trace: ", ex);
}
return ret;
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class RepositoryInfo method fillFromProject.
/**
* Fill configurable properties from associated project (if any) or Configuration.
*/
public void fillFromProject() {
Project proj = Project.getProject(getDirectoryNameRelative());
if (proj != null) {
setHistoryEnabled(proj.isHistoryEnabled());
setHandleRenamedFiles(proj.isHandleRenamedFiles());
setMergeCommitsEnabled(proj.isMergeCommitsEnabled());
} else {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
setHistoryEnabled(env.isHistoryEnabled());
setHandleRenamedFiles(env.isHandleHistoryOfRenamedFiles());
setMergeCommitsEnabled(env.isMergeCommitsEnabled());
}
}
Aggregations