当前位置: 首页>>代码示例>>Java>>正文


Java ClientUtils类代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.util.ClientUtils的典型用法代码示例。如果您正苦于以下问题:Java ClientUtils类的具体用法?Java ClientUtils怎么用?Java ClientUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClientUtils类属于org.apache.solr.client.solrj.util包,在下文中一共展示了ClientUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchExistingOrCreateNewSolrDoc

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
private SolrInputDocument fetchExistingOrCreateNewSolrDoc(String id) throws SolrServerException, IOException {
  Map<String, String> p = new HashMap<String, String>();
  p.put("q", PHRASE + ":\"" + ClientUtils.escapeQueryChars(id) + "\"");
  
  SolrParams params = new MapSolrParams(p);
  
  QueryResponse res = solrAC.query(params);
  
  if (res.getResults().size() == 0) {
    return new SolrInputDocument();
  } else if (res.getResults().size() == 1) {
    SolrDocument doc = res.getResults().get(0);
    SolrInputDocument tmp = new SolrInputDocument();
    
    for (String fieldName : doc.getFieldNames()) {
      tmp.addField(fieldName, doc.getFieldValue(fieldName));
    }
    return tmp;
  } else {
    throw new IllegalStateException("Query with params : " + p + " returned more than 1 hit!");
  }
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:23,代码来源:AutocompleteUpdateRequestProcessor.java

示例2: query

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
/**
 * 
 * @param identifier
 * @param metadataPrefix
 * @param rows
 * @return
 * @throws SolrServerException
 */
private SolrDocumentList query(final String identifier, String metadataPrefix, int rows) throws SolrServerException {
    String useIdentifier = ClientUtils.escapeQueryChars(identifier);

    StringBuilder sb = new StringBuilder();
    sb.append('(').append(SolrConstants.PI).append(':').append(useIdentifier).append(" OR ").append(SolrConstants.URN).append(':').append(
            useIdentifier).append(" OR ").append(SolrConstants.IMAGEURN).append(':').append(useIdentifier).append(')');
    sb.append(getAllSuffixes());
    logger.debug(sb.toString());
    SolrQuery solrQuery = new SolrQuery(sb.toString());
    solrQuery.setRows(rows);
    QueryResponse resp = server.query(solrQuery);

    //        if (resp.getResults().isEmpty() && Metadata.epicur.name().equals(metadataPrefix)) {
    //            solrQuery = new SolrQuery(new StringBuilder(SolrConstants.IMAGEURN_OAI).append(":").append(identifier).toString());
    //            solrQuery.setRows(rows);
    //            resp = server.query(solrQuery);
    //        }

    return resp.getResults();
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:29,代码来源:SolrSearchIndex.java

示例3: getUrnPrefixBlacklistSuffix

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
/**
 * 
 * @return
 * @should build query suffix correctly
 */
static String getUrnPrefixBlacklistSuffix(List<String> urnPrefixBlacklist) {
    StringBuilder sbQuerySuffix = new StringBuilder();
    if (urnPrefixBlacklist != null && !urnPrefixBlacklist.isEmpty()) {
        int count = 0;
        for (String urnPrefix : urnPrefixBlacklist) {
            if (StringUtils.isNotBlank(urnPrefix)) {
                urnPrefix = ClientUtils.escapeQueryChars(urnPrefix);
                urnPrefix += '*';
                sbQuerySuffix.append(" -").append("URN_UNTOKENIZED:").append(urnPrefix).append(" -").append("IMAGEURN_UNTOKENIZED:").append(
                        urnPrefix).append(" -").append("IMAGEURN_OAI_UNTOKENIZED:").append(urnPrefix);
                count++;
            } else {
                logger.warn("Empty element found in <additionalDocstructTypes>.");
            }
        }
        // Avoid returning an invalid subquery if all configured values are blank
        if (count == 0) {
            return "";
        }
    }

    return sbQuerySuffix.toString();
}
 
开发者ID:intranda,项目名称:goobi-viewer-connector,代码行数:29,代码来源:XMLGeneration.java

示例4: escapeTermPlain

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
/**
     * Escapes all special solr/query characters in the given query term
     * <em>not</em> enclosed in quotes (single term).
     * At current time, this includes at least: 
     * <code>+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /</code> and whitespace.
     * NOTE: The result should NOT be enclosed in quotes; use {@link SolrUtil#escapeTermForQuote} for that.
     * FIXME?: whitespace escaping appears to not always be honored by solr parser?...
     * @see SolrUtil#escapeTermForQuote
     */
    public static String escapeTermPlain(String term) {
        return ClientUtils.escapeQueryChars(term);
        // Reference implementation:
//        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i < s.length(); i++) {
//          char c = s.charAt(i);
//          // These characters are part of the query syntax and must be escaped
//          if (c == '\\' || c == '+' || c == '-' || c == '!'  || c == '(' || c == ')' || c == ':'
//            || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
//            || c == '*' || c == '?' || c == '|' || c == '&'  || c == ';' || c == '/'
//            || Character.isWhitespace(c)) {
//            sb.append('\\');
//          }
//          sb.append(c);
//        }
//        return sb.toString();
    }
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:27,代码来源:SolrExprUtil.java

示例5: getSolrDocument

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
public SolrDocument getSolrDocument(String docId) {
    if (docId == null) {
        throw new NullPointerException("Cannot get SOLR document for null docId");
    }
    SolrDocument result = null;
    SolrQuery query = new SolrQuery();
    query.setQuery("id:" + ClientUtils.escapeQueryChars(docId));
    query.setFields("*");
    SolrDocumentList docs = fireQuery(query).getResults();
    if (docs.getNumFound() > 1) {
        logger.error("Error: found multiple documents for id (will return first one): " + docId + " \nDocuments found: " + docs);
        result = docs.get(0);
    } else if (docs.getNumFound() == 1) {
        result = docs.get(0);
    }
    return result;
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:18,代码来源:SolrDaoImpl.java

示例6: createFacetOrQuery

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
/**
 * Creates an OR filter query for a single facet for a number of values
 *
 * @param facetName facet that should be matched
 * @param values allowed values
 * @return
 */
private String createFacetOrQuery(String facetName, Collection<String> values) {
    // escape value and wrap in quotes to make literal query
    // prefix field name with tag statement (see <http://wiki.apache.org/solr/SimpleFacetParameters#Multi-Select_Faceting_and_LocalParams>)
    final StringBuilder queryBuilder = new StringBuilder(String.format("{!tag=%1$s}%1$s", facetName)).append(":(");
    // loop over values
    final Iterator<String> iterator = values.iterator();
    while (iterator.hasNext()) {
        final String value = iterator.next();

        queryBuilder.append(ClientUtils.escapeQueryChars(value));

        // add 'OR' connector except for last token
        if (iterator.hasNext()) {
            queryBuilder.append(" OR ");
        }
    }
    queryBuilder.append(")");
    return queryBuilder.toString();
}
 
开发者ID:acdh-oeaw,项目名称:vlo-curation,代码行数:27,代码来源:AbstractSolrQueryFactory.java

示例7: suggest

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
@Override
protected void suggest(PatientSearch search, FrameTask task) throws FrameException {
	SolrQuery query = new SolrQuery("stop_code_name: \"" + ClientUtils.escapeQueryChars(search.getOriginalQueryStr()) + "\"");
	query.addFilterQuery("domain:encounter");
	query.set(GroupParams.GROUP, true);
	query.set(GroupParams.GROUP_FIELD, "stop_code_name");
	
	QueryResponse resp = execSolrQuery(query, task);
	GroupResponse group = resp.getGroupResponse();
	if (group != null && group.getValues().get(0) != null) {
		GroupCommand cmd = group.getValues().get(0);
		for (Group grp : cmd.getValues()) {
			String val = grp.getGroupValue();
			SuggestItem item = new SuggestItem(val, val, "Stop Code");
			item.setCategory("Encounters/Visits");
			task.addAction(item);
		}
	}
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:20,代码来源:GoldSearchFrame.java

示例8: exec

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
@Override
public void exec(PatientSearch search, FrameTask task) throws FrameException {
	// create + exec SOLR query
	SolrQuery query = search.initQuery();
	query.setParam("q.op", "OR");

	query.setQuery("+all:\"" + ClientUtils.escapeQueryChars(search.getQueryStr()) + '"');
	
	// search for the specific domains we don't have frames for
	String domains = "obs procedure "; // encounter stuff
	domains += "mh "; // other patient stuff
	domains += "roadtrip auxiliary "; // CPE specific stuff
	domains += "pov skin diagnosis ptf exam treatment"; // encounter flags
	query.addFilterQuery("+domain: (" + domains + ")");
	query.addFilterQuery("-removed:true"); 
	
	query.addSort(SearchService.DATETIME, ORDER.desc);
	query.setFields(SearchService.UID, SearchService.DATETIME,
			SearchService.SUMMARY, SearchService.URL_FIELD,
			SearchService.DOMAIN, SearchService.KIND,
			SearchService.FACILITY);
	task.addAction(new SolrSearchAction(query, execSolrQuery(query, task)));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:GoldSearchFrame.java

示例9: runTermQuery

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
private QueryResponse runTermQuery(String search, FrameTask task, boolean browseMode) throws FrameException {
	// query the index values for a match against drug class
	ModifiableSolrParams classQry = new ModifiableSolrParams();
	classQry.set("qt", "/terms");
	classQry.set("terms.fl", "kind");
	classQry.set("terms.sort", "count");
	
	if (browseMode) {
		// return full size list
		classQry.set("terms.limit", -1);
		classQry.set("terms.sort", "index");
	}
	
	if (StringUtils.hasText(search)) {
		// search specific value
		classQry.set("terms.regex", ".*" + ClientUtils.escapeQueryChars(search) + ".*");
		classQry.set("terms.regex.flag", "case_insensitive");
	}
	return execSolrQuery(classQry, task);
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:21,代码来源:GoldSearchFrame.java

示例10: urlSearch

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
private String urlSearch(String url) {
	if (url.startsWith("*.")) {
		if (url.contains("/")) {
			throw new IllegalArgumentException("can't use a domain wildcard with a path");
		}
		url = url.substring(2);
	}
	else{
		if(url.endsWith("*")){
			// remove the *
			url = url.substring(0, url.length()-1);
		}
	}
	url = CdxAccessControl.getSearchUrl(url);
	url = ClientUtils.escapeQueryChars(url);
  return SolrEnum.URL_TOKENIZED + ":" + url;
}
 
开发者ID:nla,项目名称:bamboo,代码行数:18,代码来源:RuleChangeUpdateManager.java

示例11: addUserRoleFilter

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
/**
 * Method build the filter query to filter the results by the user role
 * @param tenantId tenantID of the logged user
 * @param query search query
 */
private void addUserRoleFilter(int tenantId, SolrQuery query) throws SolrException {
    try {
        UserRegistry registry = Utils.getRegistryService().getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME, tenantId);
        UserRealm realm = registry.getUserRealm();
        String[] userRoles = realm.getUserStoreManager().getRoleListOfUser(getLoggedInUserName());
        StringBuilder rolesQuery = new StringBuilder();
        for (String userRole : userRoles) {
            if (rolesQuery.length() == 0) {
                rolesQuery.append('(');
                rolesQuery.append(ClientUtils.escapeQueryChars(userRole.toLowerCase()));
            } else {
                rolesQuery.append(" OR ");
                rolesQuery.append(ClientUtils.escapeQueryChars(userRole.toLowerCase()));
            }
        }
        rolesQuery.append(')');
        String queryValue = rolesQuery.toString();
        if (log.isDebugEnabled()) {
            log.debug("user roles filter query values: " +queryValue);
        }
        query.addFilterQuery(IndexingConstants.FIELD_ALLOWED_ROLES + ':' + queryValue);
    } catch (RegistryException | UserStoreException e) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Error while creating user role filter query", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:31,代码来源:SolrClient.java

示例12: tagAndAddSlowThothDocuments

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
/**
 * Tag slower documents and add them to the shrank core
 */
private void tagAndAddSlowThothDocuments() throws IOException, SolrServerException {
  // Query to return top MAX_NUMBER_SLOW_THOTH_DOCS slower thoth documents
  QueryResponse qr = realTimeServer.query(
      new SolrQuery()
          .setQuery(createThothDocsAggregationQuery())
          .addSort(QTIME, SolrQuery.ORDER.desc)
          .setRows(MAX_NUMBER_SLOW_THOTH_DOCS)
  );

  for (SolrDocument solrDocument: qr.getResults()){
    SolrInputDocument si = ClientUtils.toSolrInputDocument(solrDocument);
    // Remove old ID and version
    si.removeField(ID);
    si.removeField("_version_");
    // Tag document as slow
    si.addField(SLOW_QUERY_DOCUMENT, true);
    LOG.debug("Adding slow query document for server " + serverDetail.getName());
    shrankServer.add(si);
  }
}
 
开发者ID:trulia,项目名称:thoth,代码行数:24,代码来源:DocumentShrinker.java

示例13: buildParsedEqualsCriterion

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
private String buildParsedEqualsCriterion(String fieldName, String value, String defaultOperator) {
    String operator = (isExclusion(value)) ? "-" : defaultOperator;
    String preparedValue = value;
    if (isExclusion(value)) {
        preparedValue = preparedValue.substring(1);
    }
    if (!isPhrase(value)) {
        preparedValue = preparedValue.trim();
        preparedValue = ClientUtils.escapeQueryChars(preparedValue);
        preparedValue = escapeOperators(preparedValue);
    } else {
        preparedValue = preparedValue.replace("\\", "\\\\"); // escape backslashes inside phrase
    }
    
    return operator + fieldName + ":" + preparedValue;
}
 
开发者ID:CeON,项目名称:saos,代码行数:17,代码来源:SolrCriterionTransformer.java

示例14: removeTerm

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
@Override
public void removeTerm(Term term, String relationshipType)
{
  try
  {
    SolrCommand command = this.getCommand();
    SolrClient client = command.getClient();
    String qText = ClientUtils.escapeQueryChars(term.getId());

    client.deleteByQuery(RELATIONSHIPS + ":*" + qText + "*");

    command.doIt();
  }
  catch (SolrServerException | IOException e)
  {
    throw new ProgrammingErrorException(e);
  }
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:19,代码来源:SolrOntolgyStrategy.java

示例15: removeSynonym

import org.apache.solr.client.solrj.util.ClientUtils; //导入依赖的package包/类
@Override
public void removeSynonym(OntologyEntryIF synonym)
{
  try
  {
    SolrCommand command = this.getCommand();
    SolrClient client = command.getClient();
    String qText = ClientUtils.escapeQueryChars(synonym.getId());

    client.deleteByQuery(RELATIONSHIPS + ":*" + qText + "*");

    command.doIt();
  }
  catch (SolrServerException | IOException e)
  {
    throw new ProgrammingErrorException(e);
  }
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:19,代码来源:SolrOntolgyStrategy.java


注:本文中的org.apache.solr.client.solrj.util.ClientUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。