Java Code Examples for org.alfresco.service.cmr.search.SearchParameters#setDefaultOperator()
The following examples show how to use
org.alfresco.service.cmr.search.SearchParameters#setDefaultOperator() .
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: PersonServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private List<NodeRef> getPeopleFtsList(String pattern, PagingRequest pagingRequest) throws Throwable { // Think this code is based on org.alfresco.repo.jscript.People.getPeopleImplSearch(String, StringTokenizer, int, int) List<NodeRef> people = null; SearchParameters params = new SearchParameters(); params.addQueryTemplate("_PERSON", "|%firstName OR |%lastName OR |%userName"); params.setDefaultFieldName("_PERSON"); StringBuilder query = new StringBuilder(256); query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND ("); StringTokenizer t = new StringTokenizer(pattern, " "); if (t.countTokens() == 1) { // fts-alfresco property search i.e. location:"maidenhead" query.append('"').append(pattern).append("*\""); } else { // multiple terms supplied - look for first and second name etc. // assume first term is first name, any more are second i.e. // "Fraun van de Wiels" // also allow fts-alfresco property search to reduce results params.setDefaultOperator(SearchParameters.Operator.AND); StringBuilder multiPartNames = new StringBuilder(pattern.length()); int numOfTokens = t.countTokens(); int counter = 1; String term = null; // MNT-8539, in order to support firstname and lastname search while (t.hasMoreTokens()) { term = t.nextToken(); // ALF-11311, in order to support multi-part // firstNames/lastNames, we need to use the whole tokenized term for both // firstName and lastName if (term.endsWith("*")) { term = term.substring(0, term.lastIndexOf("*")); } multiPartNames.append("\""); multiPartNames.append(term); multiPartNames.append("*\""); if (numOfTokens > counter) { multiPartNames.append(' '); } counter++; } // ALF-11311, in order to support multi-part firstNames/lastNames, // we need to use the whole tokenized term for both firstName and lastName. // e.g. "john junior lewis martinez", where "john junior" is the first // name and "lewis martinez" is the last name. if (multiPartNames.length() > 0) { query.append("firstName:"); query.append(multiPartNames); query.append(" OR lastName:"); query.append(multiPartNames); } } query.append(")"); // define the search parameters params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); params.addStore(this.storeRef); params.setQuery(query.toString()); if (pagingRequest.getMaxItems() > 0) { params.setLimitBy(LimitBy.FINAL_SIZE); params.setLimit(pagingRequest.getMaxItems()); } ResultSet results = null; try { results = searchService.query(params); people = results.getNodeRefs(); } catch (Throwable err) { if (logger.isDebugEnabled()) { logger.debug("Failed to execute people search: " + query.toString(), err); } throw err; } finally { if (results != null) { results.close(); } } return people; }
Example 2
Source File: SolrSearchService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean contains(NodeRef nodeRef, QName propertyQName, String googleLikePattern, Operator defaultOperator) throws InvalidNodeRefException { ResultSet resultSet = null; try { // build Lucene search string specific to the node StringBuilder sb = new StringBuilder(); sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(TEXT:(").append(googleLikePattern.toLowerCase()).append(") "); if (propertyQName != null) { sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(propertyQName.getNamespaceURI(), ISO9075.encode(propertyQName.getLocalName())).toString())); sb.append(":(").append(googleLikePattern.toLowerCase()).append(")"); } else { for (QName key : nodeService.getProperties(nodeRef).keySet()) { sb.append(" OR @").append(SearchLanguageConversion.escapeLuceneQuery(QName.createQName(key.getNamespaceURI(), ISO9075.encode(key.getLocalName())).toString())); sb.append(":(").append(googleLikePattern.toLowerCase()).append(")"); } } sb.append(")"); SearchParameters sp = new SearchParameters(); sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setQuery(sb.toString()); sp.setDefaultOperator(defaultOperator); sp.addStore(nodeRef.getStoreRef()); resultSet = this.query(sp); boolean answer = resultSet.length() > 0; return answer; } finally { if (resultSet != null) { resultSet.close(); } } }
Example 3
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 4
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; }