Search in sources :

Example 46 with Project

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);
}
Also used : SuperIndexSearcher(org.opengrok.indexer.configuration.SuperIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) Project(org.opengrok.indexer.configuration.Project) TreeSet(java.util.TreeSet) MultiReader(org.apache.lucene.index.MultiReader)

Example 47 with Project

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;
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 48 with Project

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;
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 49 with Project

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;
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) IndexReader(org.apache.lucene.index.IndexReader) FSDirectory(org.apache.lucene.store.FSDirectory) File(java.io.File) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 50 with Project

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());
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment)

Aggregations

Project (org.opengrok.indexer.configuration.Project)88 Test (org.junit.jupiter.api.Test)42 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)27 File (java.io.File)22 Group (org.opengrok.indexer.configuration.Group)20 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)17 ArrayList (java.util.ArrayList)16 TreeSet (java.util.TreeSet)11 IOException (java.io.IOException)10 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)10 List (java.util.List)8 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)7 Path (jakarta.ws.rs.Path)7 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)7 Path (java.nio.file.Path)6 Map (java.util.Map)6 Paths (java.nio.file.Paths)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5