Search in sources :

Example 1 with TimeCodeSearcher

use of com.searchcode.app.service.TimeCodeSearcher in project searchcode-server by boyter.

the class TimeSearchRouteService method getTimeSearch.

public SearchResult getTimeSearch(Request request, Response response) {
    Data data = Singleton.getData();
    SearchcodeLib scl = Singleton.getSearchcodeLib(data);
    TimeCodeSearcher cs = new TimeCodeSearcher();
    CodeMatcher cm = new CodeMatcher(data);
    response.header("Content-Encoding", "gzip");
    if (request.queryParams().contains("q") == false || Values.EMPTYSTRING.equals(request.queryParams("q").trim())) {
        return null;
    }
    String query = request.queryParams("q").trim();
    int page = this.getPage(request);
    String[] repos;
    String[] langs;
    String[] owners;
    String[] year;
    String[] yearmonth;
    String[] yearmonthday;
    String[] revisions;
    String[] deleted;
    String reposFilter = Values.EMPTYSTRING;
    String langsFilter = Values.EMPTYSTRING;
    String ownersFilter = Values.EMPTYSTRING;
    String yearFilter = Values.EMPTYSTRING;
    String yearMonthFilter = Values.EMPTYSTRING;
    String yearMonthDayFilter = Values.EMPTYSTRING;
    String revisionsFilter = Values.EMPTYSTRING;
    String deletedFilter = Values.EMPTYSTRING;
    if (request.queryParams().contains("repo")) {
        repos = request.queryParamsValues("repo");
        reposFilter = getRepos(repos, reposFilter);
    }
    if (request.queryParams().contains("lan")) {
        langs = request.queryParamsValues("lan");
        langsFilter = getLanguages(langs, langsFilter);
    }
    if (request.queryParams().contains("own")) {
        owners = request.queryParamsValues("own");
        ownersFilter = getOwners(owners, ownersFilter);
    }
    if (request.queryParams().contains("year")) {
        year = request.queryParamsValues("year");
        yearFilter = this.getYears(year, yearFilter);
    }
    if (request.queryParams().contains("ym")) {
        yearmonth = request.queryParamsValues("ym");
        yearMonthFilter = this.getYearMonths(yearmonth, yearMonthFilter);
    }
    if (request.queryParams().contains("ymd")) {
        yearmonthday = request.queryParamsValues("ymd");
        yearMonthDayFilter = this.getYearMonthDays(yearmonthday, yearMonthDayFilter);
    }
    if (request.queryParams().contains("rev")) {
        revisions = request.queryParamsValues("rev");
        revisionsFilter = this.getRevisions(revisions, revisionsFilter);
    }
    if (request.queryParams().contains("del")) {
        deleted = request.queryParamsValues("del");
        deletedFilter = this.getDeleted(deleted, deletedFilter);
    }
    // split the query escape it and and it together
    String cleanQueryString = scl.formatQueryString(query);
    SearchResult searchResult = cs.search(cleanQueryString + reposFilter + langsFilter + ownersFilter + yearFilter + yearMonthFilter + yearMonthDayFilter + revisionsFilter + deletedFilter, page);
    searchResult.setCodeResultList(cm.formatResults(searchResult.getCodeResultList(), query, true));
    searchResult.setQuery(query);
    this.getAltQueries(scl, query, searchResult);
    // Null out code as it isn't required and there is no point in bloating our ajax requests
    for (CodeResult codeSearchResult : searchResult.getCodeResultList()) {
        codeSearchResult.setCode(null);
    }
    return searchResult;
}
Also used : SearchcodeLib(com.searchcode.app.util.SearchcodeLib) CodeResult(com.searchcode.app.dto.CodeResult) CodeMatcher(com.searchcode.app.service.CodeMatcher) Data(com.searchcode.app.dao.Data) TimeCodeSearcher(com.searchcode.app.service.TimeCodeSearcher) SearchResult(com.searchcode.app.dto.SearchResult)

Aggregations

Data (com.searchcode.app.dao.Data)1 CodeResult (com.searchcode.app.dto.CodeResult)1 SearchResult (com.searchcode.app.dto.SearchResult)1 CodeMatcher (com.searchcode.app.service.CodeMatcher)1 TimeCodeSearcher (com.searchcode.app.service.TimeCodeSearcher)1 SearchcodeLib (com.searchcode.app.util.SearchcodeLib)1