本文整理匯總了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!");
}
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
}
}
示例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)));
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}