Search in sources :

Example 46 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class AuthorizationFrameworkTest method createUnallowedProject.

private Project createUnallowedProject() {
    Project p = new Project();
    p.setName("not_allowed" + "_" + "project" + Math.random());
    return p;
}
Also used : Project(org.opensolaris.opengrok.configuration.Project)

Example 47 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class ProjectHelperTestBase method createRepository.

protected static Project createRepository(int index, int number, int cnt, boolean grouped, boolean allowed, List<RepositoryInfo> rps, List<Project> prjs, Map<Project, List<RepositoryInfo>> map) {
    Project p = createProject(index, number, grouped, allowed, true, rps, prjs, map);
    for (int i = 0; i < cnt; i++) {
        RepositoryInfo info = new RepoRepository();
        info.setParent(p.getName() + "_" + i);
        info.setDirectoryName(p.getPath());
        rps.add(info);
        List<RepositoryInfo> infos = map.get(p);
        if (infos == null) {
            infos = new ArrayList<>();
        }
        infos.add(info);
        map.put(p, infos);
    }
    return p;
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) RepoRepository(org.opensolaris.opengrok.history.RepoRepository)

Example 48 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class ProjectHelperTestBase method createProject.

protected static Project createProject(int index, int number, boolean grouped, boolean allowed, boolean repository, List<RepositoryInfo> rps, List<Project> prjs, Map<Project, List<RepositoryInfo>> map) {
    Project p = new Project();
    p.setName((allowed ? "allowed_" : "") + (grouped ? "grouped_" : "ungrouped_") + (repository ? "repository" : "project") + "_" + index + "_" + number);
    prjs.add(p);
    return p;
}
Also used : Project(org.opensolaris.opengrok.configuration.Project)

Example 49 with Project

use of org.opensolaris.opengrok.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);
    collector = TopScoreDocCollector.create(hitsPerPage * cachePages);
    searcher.search(query, collector);
    totalHits = collector.getTotalHits();
    if (!paging && totalHits > 0) {
        collector = TopScoreDocCollector.create(totalHits);
        searcher.search(query, collector);
    }
    hits = collector.topDocs().scoreDocs;
    for (ScoreDoc hit : hits) {
        int docId = hit.doc;
        Document d = searcher.doc(docId);
        docs.add(d);
    }
}
Also used : SuperIndexSearcher(org.opensolaris.opengrok.configuration.SuperIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) Project(org.opensolaris.opengrok.configuration.Project) TreeSet(java.util.TreeSet) MultiReader(org.apache.lucene.index.MultiReader) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 50 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class SearchEngine method search.

/**
 * Execute a search aware of current request, limited to specific project names.
 *
 * This filters out all projects which are not allowed for the current request.
 *
 * Before calling this function,
 * you must set the appropriate search criteria with the set-functions. Note
 * that this search will return the first cachePages of hitsPerPage, for
 * more you need to call more.
 *
 * Call to search() must be eventually followed by call to destroy()
 * so that IndexSearcher objects are properly freed.
 *
 * @return The number of hits
 * @see ProjectHelper#getAllProjects()
 */
public int search(HttpServletRequest req, String... projectNames) {
    ProjectHelper pHelper = PageConfig.get(req).getProjectHelper();
    Set<Project> projects = pHelper.getAllProjects();
    List<Project> filteredProjects = new ArrayList<Project>();
    for (Project project : projects) {
        for (String name : projectNames) {
            if (project.getName().equalsIgnoreCase(name)) {
                filteredProjects.add(project);
            }
        }
    }
    return search(filteredProjects, new File(RuntimeEnvironment.getInstance().getDataRootFile(), IndexDatabase.INDEX_DIR));
}
Also used : ProjectHelper(org.opensolaris.opengrok.web.ProjectHelper) Project(org.opensolaris.opengrok.configuration.Project) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

Project (org.opensolaris.opengrok.configuration.Project)79 Test (org.junit.Test)40 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)31 File (java.io.File)20 ArrayList (java.util.ArrayList)20 Group (org.opensolaris.opengrok.configuration.Group)17 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)14 IOException (java.io.IOException)12 TreeSet (java.util.TreeSet)12 HistoryException (org.opensolaris.opengrok.history.HistoryException)8 List (java.util.List)6 ParseException (java.text.ParseException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Repository (org.opensolaris.opengrok.history.Repository)5 TestRepository (org.opensolaris.opengrok.util.TestRepository)5 ConnectException (java.net.ConnectException)4