Java Code Examples for org.alfresco.service.cmr.search.SearchParameters#addLocale()
The following examples show how to use
org.alfresco.service.cmr.search.SearchParameters#addLocale() .
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: HiddenAspect.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private ResultSet searchForName(StoreRef storeRef, String name) { SearchParameters sp = new SearchParameters(); sp.addStore(storeRef); sp.setLanguage("lucene"); sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_NAME.toString()) + ":\"" + name + "\""); sp.addLocale(new Locale("en")); return searchService.query(sp); }
Example 2
Source File: QueryOptions.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
/** * @return SearchParameters */ public SearchParameters getAsSearchParmeters() { SearchParameters searchParameters = new SearchParameters(); searchParameters.setDefaultFieldName(this.getDefaultFieldName()); searchParameters.setDefaultFTSFieldConnective(this.getDefaultFTSFieldConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND); searchParameters.setDefaultFTSOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND); searchParameters.setDefaultOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND); searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); if(this.getMaxItems() > 0) { searchParameters.setLimit(this.getMaxItems()); searchParameters.setLimitBy(LimitBy.FINAL_SIZE); searchParameters.setMaxItems(this.getMaxItems()); } searchParameters.setMaxPermissionChecks(this.getMaxPermissionChecks()); searchParameters.setMaxPermissionCheckTimeMillis(this.getMaxPermissionCheckTimeMillis()); searchParameters.setMlAnalaysisMode(this.getMlAnalaysisMode()); //searchParameters.setNamespace() TODO: Fix //searchParameters.setPermissionEvaluation() searchParameters.setQuery(this.getQuery()); searchParameters.setSkipCount(this.getSkipCount()); //searchParameters.addAllAttribute() for(Locale locale : this.getLocales()) { searchParameters.addLocale(locale); } for(QueryParameterDefinition queryParameterDefinition: this.getQueryParameterDefinitions()) { searchParameters.addQueryParameterDefinition(queryParameterDefinition); } //searchParameters.addQueryTemplate(name, template) //searchParameters.addSort() for(StoreRef storeRef : this.getStores()) { searchParameters.addStore(storeRef); } //searchParameters.addTextAttribute() searchParameters.setQueryConsistency(this.getQueryConsistency()); searchParameters.setSinceTxId(getSinceTxId()); for(String name : getQueryTemplates().keySet()) { String template = getQueryTemplates().get(name); searchParameters.addQueryTemplate(name, template); } return searchParameters; }
Example 3
Source File: CMISQueryOptions.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
/** * @return SearchParameters */ public SearchParameters getAsSearchParmeters() { SearchParameters searchParameters = new SearchParameters(); searchParameters.setDefaultFieldName(this.getDefaultFieldName()); searchParameters.setDefaultFTSFieldConnective(this.getDefaultFTSFieldConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND); searchParameters.setDefaultFTSOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND); searchParameters.setDefaultOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND); searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO); if(this.getMaxItems() > 0) { searchParameters.setLimit(this.getMaxItems()); searchParameters.setLimitBy(LimitBy.FINAL_SIZE); searchParameters.setMaxItems(this.getMaxItems()); } searchParameters.setMaxPermissionChecks(this.getMaxPermissionChecks()); searchParameters.setMaxPermissionCheckTimeMillis(this.getMaxPermissionCheckTimeMillis()); searchParameters.setMlAnalaysisMode(this.getMlAnalaysisMode()); //searchParameters.setNamespace() TODO: Fix //searchParameters.setPermissionEvaluation() searchParameters.setQuery(this.getQuery()); searchParameters.setSkipCount(this.getSkipCount()); //searchParameters.addAllAttribute() for(Locale locale : this.getLocales()) { searchParameters.addLocale(locale); } for(QueryParameterDefinition queryParameterDefinition: this.getQueryParameterDefinitions()) { searchParameters.addQueryParameterDefinition(queryParameterDefinition); } //searchParameters.addQueryTemplate(name, template) //searchParameters.addSort() for(StoreRef storeRef : this.getStores()) { searchParameters.addStore(storeRef); } //searchParameters.addTextAttribute() searchParameters.setBulkFetchEnabled(isBulkFetchEnabled()); searchParameters.setQueryConsistency(this.getQueryConsistency()); searchParameters.setSinceTxId(getSinceTxId()); for(String name : getQueryTemplates().keySet()) { String template = getQueryTemplates().get(name); searchParameters.addQueryTemplate(name, template); } return searchParameters; }
Example 4
Source File: AbstractAlfrescoSolrIT.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
protected void assertAQuery( String queryString, int count, Locale locale, String[] textAttributes, String[] allAttributes, String... name) { RefCounted<SolrIndexSearcher>refCounted = null; try (SolrServletRequest solrQueryRequest = new SolrServletRequest(getCore(), null)) { refCounted = getCore().getSearcher(); SolrIndexSearcher solrIndexSearcher = refCounted.get(); SearchParameters searchParameters = new SearchParameters(); searchParameters.setQuery(queryString); if (locale != null) { searchParameters.addLocale(locale); } if (textAttributes != null) { for (String textAttribute : textAttributes) { searchParameters.addTextAttribute(textAttribute); } } if (allAttributes != null) { for (String allAttribute : allAttributes) { searchParameters.addAllAttribute(allAttribute); } } Query query = dataModel.getLuceneQueryParser(searchParameters, solrQueryRequest, FTSQueryParser.RerankPhase.SINGLE_PASS).parse(queryString); LOG.debug("####### Query ######:"+query); TopDocs docs = solrIndexSearcher.search(query, count * 2 + 10); assertEquals(fixQueryString(queryString, name), count, docs.totalHits); } catch(Exception exception) { exception.printStackTrace(); throw new RuntimeException(exception); } finally { ofNullable(refCounted).ifPresent(RefCounted::decref); } }
Example 5
Source File: KeywordSearch.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Execute the search */ private SearchResult search(String searchTerms, int startPage, int itemsPerPage, Locale locale, WebScriptRequest req) { SearchResult searchResult = null; ResultSet results = null; try { // construct search statement String[] terms = searchTerms.split(" "); searchTerms = searchTerms.replaceAll("\"", """); // Escape special characters in the terms, so that they can't confuse the parser for (int i=0; i<terms.length; i++) { terms[i] = SearchLanguageConversion.escapeLuceneQuery(terms[i]); } Map<String, Object> statementModel = new HashMap<String, Object>(7, 1.0f); statementModel.put("args", createArgs(req)); statementModel.put("terms", terms); Writer queryWriter = new StringWriter(1024); renderFormatTemplate(QUERY_FORMAT, statementModel, queryWriter); String query = queryWriter.toString(); // execute query if (logger.isDebugEnabled()) { logger.debug("Search parameters: searchTerms=" + searchTerms + ", startPage=" + startPage + ", itemsPerPage=" + itemsPerPage + ", search locale=" + locale.toString()); logger.debug("Issuing lucene search: " + query); } SearchParameters parameters = new SearchParameters(); parameters.addStore(SEARCH_STORE); parameters.setLanguage(SearchService.LANGUAGE_LUCENE); parameters.setQuery(query); if (locale != null) { parameters.addLocale(locale); } results = searchService.query(parameters); int totalResults = results.length(); if (logger.isDebugEnabled()) logger.debug("Results: " + totalResults + " rows (limited: " + results.getResultSetMetaData().getLimitedBy() + ")"); // are we out-of-range int totalPages = (totalResults / itemsPerPage); totalPages += (totalResults % itemsPerPage != 0) ? 1 : 0; if (totalPages != 0 && (startPage < 1 || startPage > totalPages)) { throw new WebScriptException("Start page " + startPage + " is outside boundary of " + totalPages + " pages"); } // construct search result searchResult = new SearchResult(); searchResult.setSearchTerms(searchTerms); searchResult.setLocale(locale); searchResult.setItemsPerPage(itemsPerPage); searchResult.setStartPage(startPage); searchResult.setTotalResults(totalResults); if (totalResults == 0) { searchResult.setTotalPages(0); searchResult.setStartIndex(0); searchResult.setTotalPageItems(0); } else { searchResult.setTotalPages(totalPages); searchResult.setStartIndex(((startPage -1) * itemsPerPage) + 1); searchResult.setTotalPageItems(Math.min(itemsPerPage, totalResults - searchResult.getStartIndex() + 1)); } SearchTemplateNode[] nodes = new SearchTemplateNode[searchResult.getTotalPageItems()]; for (int i = 0; i < searchResult.getTotalPageItems(); i++) { NodeRef node = results.getNodeRef(i + searchResult.getStartIndex() - 1); // Make the search resilient to invalid nodes if (!nodeService.exists(node)) { continue; } float score = results.getScore(i + searchResult.getStartIndex() - 1); nodes[i] = new SearchTemplateNode(node, score); } searchResult.setResults(nodes); return searchResult; } finally { if (results != null) { results.close(); } } }