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);
}
}
}
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());
}
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;
}
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;
}
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);
}
}
}
Aggregations