Search in sources :

Example 1 with ProjectHelper

use of org.opensolaris.opengrok.web.ProjectHelper 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

File (java.io.File)1 ArrayList (java.util.ArrayList)1 Project (org.opensolaris.opengrok.configuration.Project)1 ProjectHelper (org.opensolaris.opengrok.web.ProjectHelper)1