當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。