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


Java ClientUtils.escapeQueryChars方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: get

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
@Override
public SolrDocument get(String docId, RecordCollection collection) {
	SolrDocument doc;
	SolrServer solrServer = getSolrServer(collection);
	SolrQuery query = new SolrQuery();
	String escapedDocId = ClientUtils.escapeQueryChars(docId);
	query.setQuery(IndexField.UNIQUE_KEY_FIELD + ":" + escapedDocId + "");
	try {
		QueryResponse queryResponse = solrServer.query(query);
		SolrDocumentList solrDocumentList = queryResponse.getResults();
		if (!solrDocumentList.isEmpty()) {
			doc = solrDocumentList.get(0);
		} else {
			doc = null;
		}
	} catch (SolrServerException e) {
		throw new RuntimeException(e);
	}
	return doc;
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:21,代码来源:SolrServicesImpl.java

示例10: getAsFilterQuery

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
public String getAsFilterQuery() {
  if (_ff.getName().equals("facet_queries")) {
    return _name;
  }
  return 
     ClientUtils.escapeQueryChars( _ff._name ) + ":" + 
     ClientUtils.escapeQueryChars( _name );
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:FacetField.java

示例11: evaluate

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
@Override
public String evaluate(String expression, Context context) {
  List<Object> l = parseParams(expression, context.getVariableResolver());
  if (l.size() != 1) {
    throw new DataImportHandlerException(SEVERE, "'escapeQueryChars' must have at least one parameter ");
  }
  String s = l.get(0).toString();
  return ClientUtils.escapeQueryChars(s);
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:SolrQueryEscapingEvaluator.java

示例12: convert

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
@Override
public String convert(ReadableInstant source) {
	if (source == null) {
		return null;
	}
	return (ClientUtils.escapeQueryChars(FORMATTER.print(source.getMillis())));
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:8,代码来源:DateTimeConverters.java

示例13: escapeQuery

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
/**
 * Escape special characters and Solr reserved words.
 */
public static String escapeQuery(String value) {
  if (value.equals(QueryParser.Operator.AND.name()) || value.equals(QueryParser.Operator.OR.name())
      || value.equals(SolrConstants.SOLR_NOT_OP)) {
    return toPhraseQuery(ClientUtils.escapeQueryChars(value));
  }
  return ClientUtils.escapeQueryChars(value);
}
 
开发者ID:gbif,项目名称:common-search,代码行数:11,代码来源:QueryUtils.java

示例14: buildEqualsCriterion

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
private String buildEqualsCriterion(String fieldName, String value, Operator operator) {
    String preparedValue = value.trim();
    preparedValue = ClientUtils.escapeQueryChars(preparedValue);
    preparedValue = escapeOperators(preparedValue);
    
    return ((operator == Operator.AND) ? "+" : "") + fieldName + ":" + preparedValue;
}
 
开发者ID:CeON,项目名称:saos,代码行数:8,代码来源:SolrCriterionTransformer.java

示例15: get

import org.apache.solr.client.solrj.util.ClientUtils; //导入方法依赖的package包/类
@Override
public Map<String, Node> get(String uri) {
	String escaped = ClientUtils.escapeQueryChars(uri) ;
	String qs = docDef.getEntityField() + ":" + escaped ;
	SolrDocumentList solrResults = solrQuery(qs, 1) ;

	List<Map<String, Node>> records = process(solrResults) ;
	if ( records.size() == 0 )
		return null ;
	if ( records.size() > 1 )
		log.warn("Multiple docs for one URI: " + uri) ;
	return records.get(0) ;
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:14,代码来源:TextIndexSolr5.java


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