org.alfresco.service.cmr.search.SearchParameters Java Examples
The following examples show how to use
org.alfresco.service.cmr.search.SearchParameters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchMapper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * SearchParameters from the Query object * @param sp SearchParameters * @param q Query */ public void fromQuery(SearchParameters sp, Query q) { ParameterCheck.mandatoryString("query", q.getQuery()); String lang = q.getLanguage()==null?AFTS:q.getLanguage(); switch (lang.toLowerCase()) { case AFTS: sp.setLanguage(LANGUAGE_FTS_ALFRESCO); break; case LUCENE: sp.setLanguage(LANGUAGE_LUCENE); break; case CMIS: sp.setLanguage(LANGUAGE_CMIS_ALFRESCO); break; default: throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": language allowed values: afts,lucene,cmis" }); } sp.setQuery(q.getQuery()); sp.setSearchTerm(q.getUserQuery()); }
Example #2
Source File: SearchSQLApiWebscriptTests.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testSearchQueryParamsFormatNull() throws Exception { String query = "select SITE from alfresco"; SearchSQLQuery searchQuery = new SearchSQLQuery(query, "", emptyList(), 1000, false, "", emptyList()); SearchParameters sparams = webscript.buildSearchParameters(searchQuery); assertNotNull(sparams); assertEquals(query, sparams.getQuery()); assertEquals(false, sparams.isIncludeMetadata()); assertEquals(Collections.EMPTY_LIST, sparams.getLocales()); assertEquals(null, sparams.getExtraParameters().get("format")); assertEquals(null, sparams.getTimezone()); searchQuery = new SearchSQLQuery(query, null, emptyList(), 1000, true, "", emptyList()); sparams = webscript.buildSearchParameters(searchQuery); assertNotNull(sparams); assertEquals(query, sparams.getQuery()); assertEquals(true, sparams.isIncludeMetadata()); assertEquals(Collections.EMPTY_LIST, sparams.getLocales()); assertEquals(null, sparams.getExtraParameters().get("format")); assertEquals(null, sparams.getTimezone()); }
Example #3
Source File: ResultMapperTests.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException { NodeService nodeService = mock(NodeService.class); when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() { @Override public NodeRef answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); //If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef if (archivedNodes.contains(args[0])) return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate()); if (versionNodes.contains(args[0])) return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()+args[0]); return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); } }); SearchParameters sp = new SearchParameters(); sp.setBulkFetchEnabled(false); JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE)); ResultSet results = new SolrJSONResultSet(json,sp,nodeService, null, LimitBy.FINAL_SIZE, 10); return results; }
Example #4
Source File: SearchMapper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** ** SearchParameters from List<FacetQuery> * @param sp * @param facetQueries */ public void fromFacetQuery(SearchParameters sp, List<FacetQuery> facetQueries) { if (facetQueries != null && !facetQueries.isEmpty()) { for (FacetQuery fq:facetQueries) { ParameterCheck.mandatoryString("facetQuery query", fq.getQuery()); String query = fq.getQuery(); String label = fq.getLabel()!=null?fq.getLabel():query; if (query.startsWith("{!afts")) { throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Facet queries should not start with !afts" }); } query = "{!afts key='"+label+"'}"+query; sp.addFacetQuery(query); } } }
Example #5
Source File: SearchMapper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * SearchParameters from SpellCheck object * @param sp SearchParameters * @param defaults SpellCheck */ public void fromSpellCheck(SearchParameters sp, Spelling spelling) { if (spelling != null) { if (spelling.getQuery() != null && !spelling.getQuery().isEmpty()) { sp.setSearchTerm(spelling.getQuery()); } else { if (sp.getSearchTerm() == null || sp.getSearchTerm().isEmpty()) { //We don't have a valid search term to use with the spelling throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": userQuery or spelling.query required." }); } } sp.setSpellCheck(true); } }
Example #6
Source File: SolrQueryHTTPClientTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testBuildTimezone() throws UnsupportedEncodingException { SearchParameters params = new SearchParameters(); params.setTimezone(""); StringBuilder urlBuilder = new StringBuilder(); client.buildUrlParameters(params, false, encoder, urlBuilder); String url = urlBuilder.toString(); assertFalse(url.contains("&TZ")); params.setTimezone("bob"); urlBuilder = new StringBuilder(); client.buildUrlParameters(params, false, encoder, urlBuilder); url = urlBuilder.toString(); //Timezone formats are not validated here so its just passing a string. assertTrue(url.contains("&TZ=bob"));; }
Example #7
Source File: Search.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Execute the query * * Removes any duplicates that may be present (ID search can cause duplicates - * it is better to remove them here) * * @param store StoreRef to search against - null for default configured store * @param search Lucene search to execute * @param sort Columns to sort by * @param language Search language to use e.g. SearchService.LANGUAGE_LUCENE * @param maxResults Maximum results to return if > 0 * @param skipResults Results to skip in the result set * * @return Array of Node objects */ protected Object[] query(String store, String search, SortColumn[] sort, String language, int maxResults, int skipResults) { SearchParameters sp = new SearchParameters(); sp.addStore(store != null ? new StoreRef(store) : this.storeRef); sp.setLanguage(language != null ? language : SearchService.LANGUAGE_LUCENE); sp.setQuery(search); if (maxResults > 0) { sp.setLimit(maxResults); sp.setLimitBy(LimitBy.FINAL_SIZE); } if (skipResults > 0) { sp.setSkipCount(skipResults); } if (sort != null) { for (SortColumn sd : sort) { sp.addSort(sd.column, sd.asc); } } return query(sp, true); }
Example #8
Source File: Lucene4QueryBuilderContextSolrImpl.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
/** * Context for building lucene queries * * @param dictionaryService * @param namespacePrefixResolver * @param tenantService * @param searchParameters * @param defaultSearchMLAnalysisMode * @param req * @param model */ public Lucene4QueryBuilderContextSolrImpl(DictionaryService dictionaryService, NamespacePrefixResolver namespacePrefixResolver, TenantService tenantService, SearchParameters searchParameters, MLAnalysisMode defaultSearchMLAnalysisMode, SolrQueryRequest req, AlfrescoSolrDataModel model, FTSQueryParser.RerankPhase rerankPhase) { lqp = new Solr4QueryParser(req, Version.LATEST, searchParameters.getDefaultFieldName(), req.getSchema().getQueryAnalyzer(), rerankPhase); // lqp.setDefaultOperator(AbstractLuceneQueryParser.OR_OPERATOR); lqp.setDictionaryService(dictionaryService); lqp.setNamespacePrefixResolver(namespacePrefixResolver); lqp.setTenantService(tenantService); lqp.setSearchParameters(searchParameters); // lqp.setDefaultSearchMLAnalysisMode(defaultSearchMLAnalysisMode); // lqp.setIndexReader(indexReader); // lqp.setAllowLeadingWildcard(true); // this.namespacePrefixResolver = namespacePrefixResolver; Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties(); int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000")); lqp.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit); lqpa = new Lucene4QueryParserAdaptor(lqp); }
Example #9
Source File: IgnoreConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected SearchParameters applyDecorations(ActualEnvironment environment, SearchParameters searchParameters, VirtualQuery query) { if ((ignoreAspectQNames != null && !ignoreAspectQNames.isEmpty()) || (ignoreTypeNames != null && !ignoreTypeNames.isEmpty())) { if (SearchService.LANGUAGE_FTS_ALFRESCO.equals(searchParameters.getLanguage())) { SearchParameters searchParametersCopy = searchParameters.copy(); return applyFTSDecorations(searchParametersCopy, environment.getNamespacePrefixResolver()); } else { throw new VirtualizationException("Unsupported constrating language " + searchParameters.getLanguage()); } } else { return searchParameters; } }
Example #10
Source File: SearchMapper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * SearchParameters from the Limits object * @param sp SearchParameters * @param paging Paging */ public void fromLimits(SearchParameters sp, Limits limits) { if (limits != null) { if (limits.getPermissionEvaluationCount() != null) { sp.setLimit(-1); sp.setLimitBy(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS); sp.setMaxPermissionChecks(limits.getPermissionEvaluationCount()); } if (limits.getPermissionEvaluationTime() != null) { sp.setLimit(-1); sp.setLimitBy(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS); sp.setMaxPermissionCheckTimeMillis(limits.getPermissionEvaluationTime()); } } }
Example #11
Source File: IgnoreConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private SearchParameters applyFTSDecorations(SearchParameters searchParameters, NamespacePrefixResolver nspResolver) { SearchParameters constrainedParameters = searchParameters.copy(); String theQuery = constrainedParameters.getQuery(); theQuery = "(" + theQuery + ")"; if (ignoreAspectQNames != null) { for (QName ignoredAspect : ignoreAspectQNames) { theQuery = theQuery + " and " + "!ASPECT:'" + ignoredAspect.toPrefixString(nspResolver) + "'"; } } if (ignoreTypeNames != null) { for (QName ignoredType : ignoreTypeNames) { theQuery = theQuery + " and " + "!TYPE:'" + ignoredType.toPrefixString(nspResolver) + "'"; } } constrainedParameters.setQuery(theQuery); return constrainedParameters; }
Example #12
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
public Solr4QueryParser getLuceneQueryParser(SearchParameters searchParameters, SolrQueryRequest req, FTSQueryParser.RerankPhase rerankPhase) { Analyzer analyzer = req.getSchema().getQueryAnalyzer(); Solr4QueryParser parser = new Solr4QueryParser(req, Version.LATEST, searchParameters.getDefaultFieldName(), analyzer, rerankPhase); parser.setNamespacePrefixResolver(namespaceDAO); parser.setDictionaryService(getDictionaryService(CMISStrictDictionaryService.DEFAULT)); parser.setTenantService(tenantService); parser.setSearchParameters(searchParameters); parser.setAllowLeadingWildcard(true); Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties(); int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000")); parser.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit); return parser; }
Example #13
Source File: AlfrescoLuceneQParserPlugin.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Query parse() throws SyntaxError { Pair<SearchParameters, Boolean> searchParametersAndFilter = getSearchParameters(); SearchParameters searchParameters = searchParametersAndFilter.getFirst(); Boolean isFilter = searchParametersAndFilter.getSecond(); Solr4QueryParser qp = AlfrescoSolrDataModel.getInstance().getLuceneQueryParser(searchParameters, req, FTSQueryParser.RerankPhase.SINGLE_PASS_WITH_AUTO_PHRASE); Query query; try { // escape / not in a string and not already escaped String escapedQ = escape(searchParameters.getQuery()); query = qp.parse(escapedQ); } catch (ParseException pe) { throw new SyntaxError(pe); } ContextAwareQuery contextAwareQuery = new ContextAwareQuery(query, Boolean.TRUE.equals(isFilter) ? null : searchParameters); if(log.isDebugEnabled()) { log.debug("Lucene QP query as lucene:\t "+contextAwareQuery); } return contextAwareQuery; }
Example #14
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
public Query getCMISQuery(CMISQueryMode mode, Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, org.alfresco.repo.search.impl.querymodel.Query queryModelQuery, CmisVersion cmisVersion, String alternativeDictionary) throws ParseException { SearchParameters searchParameters = searchParametersAndFilter.getFirst(); Boolean isFilter = searchParametersAndFilter.getSecond(); CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary); Set<String> selectorGroup = queryModelQuery.getSource().getSelectorGroups(functionContext).get(0); LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, alternativeDictionary, FTSQueryParser.RerankPhase.SINGLE_PASS); @SuppressWarnings("unchecked") LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery; org.apache.lucene.search.Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext); return new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters); }
Example #15
Source File: SearchMapperTests.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void facetFormatV2() { Query query = new Query("afts", "a*", ""); SearchQuery sq = new SearchQuery(query, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,null, null,FacetFormat.V2); SearchRequestContext searchRequestContext = SearchRequestContext.from(sq); SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, sq, searchRequestContext); assertNotNull(searchParameters); //Test defaults assertEquals("There should be only 1 default store", 1,searchParameters.getStores().size()); assertEquals("workspaces store is the default", StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0)); assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy()); assertEquals(100, searchParameters.getLimit()); }
Example #16
Source File: SolrQueryHTTPClientTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testBuildRangeDate() throws UnsupportedEncodingException { TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); SearchParameters params = new SearchParameters(); params.setSearchTerm("A*"); List<RangeParameters> ranges = new ArrayList<RangeParameters>(); ranges.add(new RangeParameters("created", "2015", "2016", "+1MONTH", true, Collections.emptyList(), Collections.emptyList(), null, null)); params.setRanges(ranges); StringBuilder urlBuilder = new StringBuilder(); client.buildRangeParameters(params, encoder, urlBuilder); String url = urlBuilder.toString(); assertNotNull(url); assertTrue(url.contains("&facet=true")); assertTrue(url.contains("&facet.range=created")); assertTrue(url.contains("&f.created.facet.range.start=2015-01-01T00%3A00%3A00.000Z")); assertTrue(url.contains("&f.created.facet.range.end=2016-12-31T23%3A59%3A59.999Z")); assertTrue(url.contains("&f.created.facet.range.gap=%2B1MONTH")); TimeZone.setDefault(defaultTimeZone); }
Example #17
Source File: PagingRequestConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected SearchParameters applyDecorations(ActualEnvironment environment, SearchParameters searchParameters, VirtualQuery query) { SearchParameters searchParametersCopy = searchParameters.copy(); if (pagingRequest != null) { searchParametersCopy.setSkipCount(pagingRequest.getSkipCount()); searchParametersCopy.setMaxItems(pagingRequest.getMaxItems()); } return searchParametersCopy; }
Example #18
Source File: NamePatternPropertyValueConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected SearchParameters applyFTS(SearchParameters searchParameters) { String filePattern; StringBuffer luceneReserved = new StringBuffer(); for(int i=0;i<value.toString().length();i++){ if(SearchLanguageConversion.DEF_LUCENE.isReserved(value.toString().charAt(i))){ luceneReserved.append(value.toString().charAt(i)); } } String luceneReservedStr=luceneReserved.toString(); String pattern =org.alfresco.util.ISO9075.encode(value.toString()); for (int i = 0; i < luceneReservedStr.length(); i++) { pattern = pattern.replace(org.alfresco.util.ISO9075.encode(luceneReservedStr.substring(i,i + 1)), luceneReservedStr.substring(i,i + 1)); } filePattern=SearchLanguageConversion.escapeForLucene(pattern); SearchParameters constrainedParameters = searchParameters.copy(); String theQuery = constrainedParameters.getQuery(); StringBuilder sb = new StringBuilder(); sb.append("(" + theQuery + ")"); sb.append(" and ("); sb.append("TEXT:(").append(filePattern).append(") "); sb.append("or ("); sb.append(" =").append(property.toPrefixString(this.nspResolver)); sb.append(":").append(filePattern); sb.append(" ) "); sb.append(")"); theQuery = sb.toString(); constrainedParameters.setQuery(theQuery); return constrainedParameters; }
Example #19
Source File: ResultMapperTests.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testRangeExclusiec() throws Exception { ResultSet results = mockResultset(Collections.emptyList(),Collections.emptyList()); String updatedJSON = helper.JSON.replace("lower", "upper"); SearchQuery searchQuery = helper.extractFromJson(updatedJSON); SearchRequestContext searchRequest = SearchRequestContext.from(searchQuery); SearchParameters searchParams = searchMapper.toSearchParameters(EMPTY_PARAMS, searchQuery, searchRequest); SearchContext searchContext = mapper.toSearchContext((SolrJSONResultSet) results, searchRequest, searchQuery, 0); //Numeric facet range List<GenericFacetResponse> rangeFacets = searchContext.getFacets().stream() .filter(f -> f.getType().equals(FACET_TYPE.range)).collect(Collectors.toList()); assertEquals(2, rangeFacets.size()); assertEquals(4, rangeFacets.get(0).getBuckets().size()); assertEquals(3, rangeFacets.get(1).getBuckets().size()); assertEquals("content.size",rangeFacets.get(1).getLabel()); assertEquals("(0 - 100]",rangeFacets.get(1).getBuckets().get(0).getLabel()); Object[] metrics = rangeFacets.get(1).getBuckets().get(0).getMetrics().toArray(); assertEquals("4",((SimpleMetric) metrics[0]).getValue().get("count")); assertEquals("content.size:<\"0\" TO \"100\"]", rangeFacets.get(1).getBuckets().get(0).getFilterQuery()); assertEquals(null,rangeFacets.get(1).getBuckets().get(0).getBucketInfo().get("count")); Map<String, String> facetInfo = rangeFacets.get(1).getBuckets().get(0).getBucketInfo(); assertEquals("0",facetInfo.get("start")); assertEquals("100",facetInfo.get("end")); assertEquals("false",facetInfo.get("startInclusive")); assertEquals("true",facetInfo.get("endInclusive")); }
Example #20
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
public org.alfresco.repo.search.impl.querymodel.Query parseCMISQueryToAlfrescoAbstractQuery(CMISQueryMode mode, SearchParameters searchParameters, SolrQueryRequest req, String alternativeDictionary, CmisVersion cmisVersion) { // convert search parameters to cmis query options // TODO: how to handle store ref CMISQueryOptions options = new CMISQueryOptions(searchParameters.getQuery(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS); options.setDefaultFieldName(searchParameters.getDefaultFieldName()); // TODO: options.setDefaultFTSConnective() // TODO: options.setDefaultFTSFieldConnective() options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction()); options.setLocales(searchParameters.getLocales()); options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode()); options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions()); for(String name : searchParameters.getQueryTemplates().keySet()) { String template = searchParameters.getQueryTemplates().get(name); options.addQueryTemplate(name, template); } // parse cmis syntax CapabilityJoin joinSupport = (mode == CMISQueryMode.CMS_STRICT) ? CapabilityJoin.NONE : CapabilityJoin.INNERANDOUTER; CmisFunctionEvaluationContext functionContext = getCMISFunctionEvaluationContext(mode, cmisVersion, alternativeDictionary); CMISDictionaryService cmisDictionary = getCMISDictionary(alternativeDictionary, cmisVersion); CMISQueryParser parser = new CMISQueryParser(options, cmisDictionary, joinSupport); org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = parser.parse(new LuceneQueryModelFactory<Query, Sort, SyntaxError>(), functionContext); if (queryModelQuery.getSource() != null) { List<Set<String>> selectorGroups = queryModelQuery.getSource().getSelectorGroups(functionContext); if (selectorGroups.size() == 0) { throw new UnsupportedOperationException("No selectors"); } } return queryModelQuery; }
Example #21
Source File: VirtualQueryImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); query = new VirtualQueryImpl(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString(), SearchService.LANGUAGE_FTS_ALFRESCO, QUERY_TEST_STRING_QUERY); mockitoActualEnvironment = Mockito.mock(ActualEnvironment.class); Mockito.when(mockitoActualEnvironment.query(Mockito.any(SearchParameters.class))) .thenReturn(new EmptyResultSet()); mockitoPrefixResolver = Mockito.mock(NamespacePrefixResolver.class); Mockito.when(mockitoPrefixResolver.getNamespaceURI(TST_PREFIX)).thenReturn(TEST_URI); Mockito.when(mockitoPrefixResolver.getPrefixes(TEST_URI)).thenReturn(Arrays.asList(TST_PREFIX)); Mockito.when(mockitoActualEnvironment.getNamespacePrefixResolver()).thenReturn(mockitoPrefixResolver); testQName1 = QName.createQName(TST_PREFIX, TEST_LOCAL_NAME_1, mockitoPrefixResolver); testQName2 = QName.createQName(TST_PREFIX, TEST_LOCAL_NAME_2, mockitoPrefixResolver); NodeRef n1 = new NodeRef("workspace://SpacesStore/17c8f11d-0936-4295-88a0-12b85764c76f"); NodeRef n2 = new NodeRef("workspace://SpacesStore/27c8f11d-0936-4295-88a0-12b85764c76f"); nodeOneReference = ((VirtualProtocol) Protocols.VIRTUAL.protocol).newReference(n1, "/1", n2); }
Example #22
Source File: FilesFoldersConstraint.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected SearchParameters applyDecorations(ActualEnvironment environment, SearchParameters searchParameters, VirtualQuery query) { String queryString = searchParameters.getQuery(); String language = searchParameters.getLanguage(); String filteredQuery = filter(language, queryString, files, folders); SearchParameters searchParametersCopy = searchParameters.copy(); searchParametersCopy.setQuery(filteredQuery); return searchParametersCopy; }
Example #23
Source File: QueryOptions.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public static QueryOptions create(SearchParameters searchParameters) { QueryOptions options = new QueryOptions(searchParameters.getQuery(), null); options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction()); options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND); options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND); options.setSkipCount(searchParameters.getSkipCount()); options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks()); options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis()); options.setDefaultFieldName(searchParameters.getDefaultFieldName()); if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE) { options.setMaxItems(searchParameters.getLimit()); } else { options.setMaxItems(searchParameters.getMaxItems()); } options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode()); options.setLocales(searchParameters.getLocales()); options.setStores(searchParameters.getStores()); options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions()); ///options.setQuery(query); Done on construction. options.setUseInMemorySort(searchParameters.getUseInMemorySort()); options.setMaxRawResultSetSizeForInMemorySort(searchParameters.getMaxRawResultSetSizeForInMemorySort()); options.setBulkFetchEnabled(searchParameters.isBulkFetchEnabled()); options.setExcludeTenantFilter(searchParameters.getExcludeTenantFilter()); options.setQueryConsistency(searchParameters.getQueryConsistency()); options.setSinceTxId(searchParameters.getSinceTxId()); for(String name : searchParameters.getQueryTemplates().keySet()) { String template = searchParameters.getQueryTemplates().get(name); options.addQueryTemplate(name, template); } return options; }
Example #24
Source File: SearchMapper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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; }
Example #25
Source File: ACLEntryAfterInvocationProvider.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get the max size from the search parameters. * The max size is the maximum number of elements to be returned, It is computed considering various * parameters in the searchParameters : maxSize, limitBy and skipCount. * * @param searchParameters * @return */ private Integer getMaxSize(SearchParameters searchParameters) { Integer maxSize = null; if (searchParameters.getMaxItems() >= 0) { maxSize = searchParameters.getMaxItems() + searchParameters.getSkipCount(); } else if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE) { maxSize = searchParameters.getLimit() + searchParameters.getSkipCount(); } return maxSize; }
Example #26
Source File: SolrQueryHTTPClientTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testBuildMulitRange() throws UnsupportedEncodingException { SearchParameters params = new SearchParameters(); params.setSearchTerm("A*"); List<RangeParameters> ranges = new ArrayList<RangeParameters>(); List<String>includes = new ArrayList<String>(); includes.add("upper"); includes.add("outer"); List<String>includes2 = new ArrayList<String>(); includes2.add("lower"); List<String> other = new ArrayList<String>(); other.add("before"); ranges.add(new RangeParameters("content.size", "0", "1000000", "10000", true, other, includes, null, null)); ranges.add(new RangeParameters("created", "2015-09-29T10:45:15.729Z", "2016-09-29T10:45:15.729Z", "+100DAY", true, other, includes2, null, null)); params.setRanges(ranges); StringBuilder urlBuilder = new StringBuilder(); client.buildRangeParameters(params, encoder, urlBuilder); String url = urlBuilder.toString(); assertNotNull(url); assertTrue(url.contains("&facet=true")); assertTrue(url.contains("&facet.range=content.size")); assertTrue(url.contains("&f.content.size.facet.range.start=0")); assertTrue(url.contains("&f.content.size.facet.range.end=1000000")); assertTrue(url.contains("&f.content.size.facet.range.gap=10000")); assertTrue(url.contains("&f.content.size.facet.range.include=upper")); assertTrue(url.contains("&f.content.size.facet.range.include=outer")); assertTrue(url.contains("&f.content.size.facet.range.hardend=true")); assertTrue(url.contains("&facet.range=created")); assertTrue(url.contains("&f.created.facet.range.start=2015-09-29T10%3A45%3A15.729Z")); assertTrue(url.contains("&f.created.facet.range.end=2016-09-29T10%3A45%3A15.729Z")); assertTrue(url.contains("&f.created.facet.range.gap=%2B100DAY")); assertTrue(url.contains("&f.created.facet.range.other=before")); assertTrue(url.contains("&f.created.facet.range.include=lower")); assertTrue(url.contains("&f.created.facet.range.hardend=true")); }
Example #27
Source File: DbAftsQueryLanguage.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ResultSet executeQuery(SearchParameters searchParameters) { if(metadataIndexCheck1.getPatchApplied()) { return super.executeQuery(searchParameters); } else { throw new QueryModelException("The patch to add the indexes to support in-transactional metadata queries has not been applied"); } }
Example #28
Source File: SearchMapper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * SearchParameters from Default object * @param sp SearchParameters * @param defaults Default */ public void fromDefault(SearchParameters sp, Default defaults) { if (defaults != null) { List<String> txtAttribs = defaults.getTextAttributes(); if (txtAttribs!= null && !txtAttribs.isEmpty()) { for (String attrib:txtAttribs) { sp.addTextAttribute(attrib); } } if (defaults.getDefaultFTSOperator() != null) { sp.setDefaultFTSOperator(Operator.valueOf(defaults.getDefaultFTSOperator().toUpperCase())); } if (defaults.getDefaultFTSFieldOperator() != null) { sp.setDefaultFTSFieldConnective(Operator.valueOf(defaults.getDefaultFTSFieldOperator().toUpperCase())); } sp.setNamespace(defaults.getNamespace()); sp.setDefaultFieldName(defaults.getDefaultFieldName()); } }
Example #29
Source File: DBResultSet.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public DBResultSet(SearchParameters searchParameters, List<Long> dbids, NodeDAO nodeDao, NodeService nodeService, TenantService tenantService, int maximumResultsFromUnlimitedQuery) { this.nodeDao = nodeDao; this.dbids = dbids; this.nodeService = nodeService; this.tenantService = tenantService; this.prefetch = new BitSet(dbids.size()); nodeRefs= new NodeRef[(dbids.size())]; final LimitBy limitBy; int maxResults = -1; if (searchParameters.getMaxItems() >= 0) { maxResults = searchParameters.getMaxItems(); limitBy = LimitBy.FINAL_SIZE; } else if(searchParameters.getLimitBy() == LimitBy.FINAL_SIZE && searchParameters.getLimit() >= 0) { maxResults = searchParameters.getLimit(); limitBy = LimitBy.FINAL_SIZE; } else { maxResults = searchParameters.getMaxPermissionChecks(); if (maxResults < 0) { maxResults = maximumResultsFromUnlimitedQuery; } limitBy = LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS; } this.resultSetMetaData = new SimpleResultSetMetaData( maxResults > 0 && dbids.size() < maxResults ? LimitBy.UNLIMITED : limitBy, PermissionEvaluationMode.EAGER, searchParameters); }
Example #30
Source File: DBQueryTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void queryWithCount(String ql, String query, int count, QName property, Boolean ascending) { SearchParameters sp = new SearchParameters(); sp.setLanguage(ql); sp.setQueryConsistency(QueryConsistency.TRANSACTIONAL); sp.setQuery(query); sp.addStore(rootNodeRef.getStoreRef()); ResultSet results = serviceRegistry.getSearchService().query(sp); HashSet<NodeRef> found = new HashSet<NodeRef>(); Comparable last = null; for(ResultSetRow row :results) { assertFalse(found.contains( row.getNodeRef())); found.add(row.getNodeRef()); if(property != null) { Comparable current = (Comparable)nodeService.getProperty(row.getNodeRef(), property); if(last != null) { if((ascending == null) || (ascending)) { assert(last.compareTo(current) >= 0); } else { assert(last.compareTo(current) <= 0); } } last = current; } } assertEquals(count, results.length()); results.getResultSetMetaData(); results.close(); }