Search in sources :

Example 66 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class QueriesPeopleApiTest method checkApiCall.

private void checkApiCall(String term, String orderBy, String fields, Paging paging, int expectedStatus, List<String> expectedPeople, int... userIds) throws Exception {
    createParamIdNotNull(Queries.PARAM_TERM, term);
    createParamIdNotNull(Queries.PARAM_ORDERBY, orderBy);
    createParamIdNotNull(Queries.PARAM_FIELDS, fields);
    dummySearchServiceQueryNodeRefs.clear();
    for (int i : userIds) {
        NodeRef nodeRef = testPersonNodeRefs.get(i);
        dummySearchServiceQueryNodeRefs.add(nodeRef);
    }
    response = getAll(URL_QUERIES_LSP, paging, params, expectedStatus);
    if (expectedStatus == 200) {
        String termWithEscapedAsterisks = term.replaceAll("\\*", "\\\\*");
        String expectedQuery = "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (\"*" + termWithEscapedAsterisks + "*\")";
        ArgumentCaptor<SearchParameters> searchParametersCaptor = ArgumentCaptor.forClass(SearchParameters.class);
        verify(mockSearchService, times(++callCountToMockSearchService)).query(searchParametersCaptor.capture());
        SearchParameters parameters = searchParametersCaptor.getValue();
        assertEquals("Query", expectedQuery, parameters.getQuery());
        people = Person.parsePeople(response.getJsonResponse()).getList();
        if (!expectedPeople.isEmpty()) {
            StringJoiner actual = new StringJoiner("\n");
            StringJoiner expected = new StringJoiner("\n");
            for (String people : expectedPeople) {
                expected.add(people);
            }
            for (Person person : people) {
                actual.add(person.toString());
            }
            String exp = expected.toString().replaceAll(TEST_TERM_PREFIX, "");
            String act = actual.toString().replaceAll(TEST_TERM_PREFIX, "");
            assertEquals(exp, act);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Person(org.alfresco.rest.api.tests.client.data.Person) StringJoiner(java.util.StringJoiner)

Example 67 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method findLinks.

public CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters) {
    checkEnabled();
    String queryString = "ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() + "\"";
    SearchParameters sp = new SearchParameters();
    // note: REST API query parameter (ie. where clause filter) - not to be confused with search query ;-)
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(FIND_SHARED_LINKS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String sharedByUserId = propertyWalker.getProperty(PARAM_SHAREDBY, WhereClauseParser.EQUALS, String.class);
        if (sharedByUserId != null) {
            if (People.DEFAULT_USER.equalsIgnoreCase(sharedByUserId)) {
                sharedByUserId = AuthenticationUtil.getFullyAuthenticatedUser();
            }
            QueryParameterDefinition qpd = new QueryParameterDefImpl(QuickShareModel.PROP_QSHARE_SHAREDBY, dictionaryService.getDataType(DataTypeDefinition.TEXT), true, sharedByUserId);
            sp.addQueryParameterDefinition(qpd);
            String qsharedBy = QuickShareModel.PROP_QSHARE_SHAREDBY.toPrefixString(namespaceService);
            queryString += " +@" + SearchLanguageConversion.escapeLuceneQuery(qsharedBy) + ":\"${" + qsharedBy + "}\"";
        }
    }
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(queryString);
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    sp.setSkipCount(pagingRequest.getSkipCount());
    sp.setMaxItems(pagingRequest.getMaxItems());
    sp.addSort("@" + ContentModel.PROP_MODIFIED, false);
    ResultSet results = searchService.query(sp);
    List<QuickShareLink> qsLinks = new ArrayList<>(results.length());
    List<String> includeParam = parameters.getInclude();
    for (ResultSetRow row : results) {
        NodeRef nodeRef = row.getNodeRef();
        qsLinks.add(getQuickShareInfo(nodeRef, false, includeParam));
    }
    results.close();
    return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), Long.valueOf(results.getNumberFound()).intValue());
}
Also used : QueryParameterDefImpl(org.alfresco.repo.search.QueryParameterDefImpl) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) PagingRequest(org.alfresco.query.PagingRequest) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) ResultSet(org.alfresco.service.cmr.search.ResultSet) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) QueryParameterDefinition(org.alfresco.service.cmr.search.QueryParameterDefinition)

Example 68 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapper method toSearchParameters.

/**
 * Turn the SearchQuery params serialized by Jackson into the Java SearchParameters object
 * @param params
 * @return SearchParameters
 */
public SearchParameters toSearchParameters(Params params, SearchQuery searchQuery, SearchRequestContext searchRequestContext) {
    ParameterCheck.mandatory("query", searchQuery.getQuery());
    SearchParameters sp = new SearchParameters();
    setDefaults(sp);
    fromLocalization(sp, searchQuery.getLocalization());
    fromQuery(sp, searchQuery.getQuery());
    fromPaging(sp, params.getPaging());
    fromSort(sp, searchQuery.getSort());
    fromTemplate(sp, searchQuery.getTemplates());
    validateInclude(searchQuery.getInclude());
    fromDefault(sp, searchQuery.getDefaults());
    fromFilterQuery(sp, searchQuery.getFilterQueries());
    fromFacetQuery(sp, searchQuery.getFacetQueries());
    fromPivot(sp, searchQuery.getStats(), searchQuery.getFacetFields(), searchQuery.getFacetRanges(), searchQuery.getPivots(), searchRequestContext);
    fromStats(sp, searchQuery.getStats());
    fromFacetFields(sp, searchQuery.getFacetFields());
    fromSpellCheck(sp, searchQuery.getSpellcheck());
    fromHighlight(sp, searchQuery.getHighlight());
    fromFacetIntervals(sp, searchQuery.getFacetIntervals());
    fromRange(sp, searchQuery.getFacetRanges());
    fromScope(sp, searchQuery.getScope(), searchRequestContext);
    fromLimits(sp, searchQuery.getLimits());
    return sp;
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters)

Example 69 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchSQLApiWebscript method buildSearchParameters.

public SearchParameters buildSearchParameters(SearchSQLQuery searchQuery) {
    SearchParameters sparams = new SearchParameters();
    sparams.setLanguage(SearchService.LANGUAGE_SOLR_SQL);
    sparams.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    if (StringUtils.isEmpty(searchQuery.getStmt())) {
        throw new AlfrescoRuntimeException("Required stmt parameter is missing.");
    }
    if (searchQuery.getFormat().equalsIgnoreCase("solr")) {
        sparams.addExtraParameter("format", "solr");
    }
    if (!StringUtils.isEmpty(searchQuery.getTimezone())) {
        sparams.setTimezone(searchQuery.getTimezone());
    }
    sparams.setQuery(searchQuery.getStmt());
    searchQuery.getLocales().forEach(action -> {
        Locale locale = new Locale(action);
        sparams.addLocale(locale);
    });
    searchQuery.getFilterQueries().forEach(sparams::addFilterQuery);
    sparams.setIncludeMetadata(searchQuery.isIncludeMetadata());
    return sparams;
}
Also used : Locale(java.util.Locale) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 70 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchSQLApiWebscript method execute.

@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse res) throws IOException {
    try {
        // Turn JSON into a Java object representation
        SearchSQLQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchSQLQuery.class);
        SearchParameters sparams = buildSearchParameters(searchQuery);
        ResultSet results = searchService.query(sparams);
        FilteringResultSet frs = (FilteringResultSet) results;
        SolrSQLJSONResultSet ssjr = (SolrSQLJSONResultSet) frs.getUnFilteredResultSet();
        // When solr format is requested pass the solr output directly.
        if (searchQuery.getFormat().equalsIgnoreCase("solr")) {
            res.getWriter().write(ssjr.getSolrResponse());
        } else {
            CollectionWithPagingInfo<TupleList> nodes = resultMapper.toCollectionWithPagingInfo(ssjr.getDocs(), searchQuery);
            renderJsonResponse(res, nodes, assistant.getJsonHelper());
        }
        setResponse(res, DEFAULT_SUCCESS);
    } catch (Exception exception) {
        if (exception instanceof LuceneQueryParserException) {
            renderException(exception, res, assistant);
        } else {
            renderException(new WebScriptException(400, exception.getMessage()), res, assistant);
        }
    }
}
Also used : FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) TupleList(org.alfresco.rest.api.search.model.TupleList) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SolrSQLJSONResultSet(org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) ResultSet(org.alfresco.service.cmr.search.ResultSet) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) SolrSQLJSONResultSet(org.alfresco.repo.search.impl.solr.SolrSQLJSONResultSet) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Aggregations

SearchParameters (org.alfresco.service.cmr.search.SearchParameters)120 ResultSet (org.alfresco.service.cmr.search.ResultSet)51 Test (org.junit.Test)41 NodeRef (org.alfresco.service.cmr.repository.NodeRef)33 ArrayList (java.util.ArrayList)25 StoreRef (org.alfresco.service.cmr.repository.StoreRef)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)13 List (java.util.List)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 JSONObject (org.json.JSONObject)12 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 FieldHighlightParameters (org.alfresco.service.cmr.search.FieldHighlightParameters)11 Set (java.util.Set)10 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)10 RangeParameters (org.alfresco.service.cmr.search.RangeParameters)10 JSONArray (org.json.JSONArray)10 JSONTokener (org.json.JSONTokener)10 Locale (java.util.Locale)9