List of usage examples for org.apache.solr.client.solrj SolrQuery setQuery
public SolrQuery setQuery(String query)
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
@Override public SolrQuery propertyIsEqualTo(String propertyName, Date exactDate) { String mappedPropertyName = getMappedPropertyName(propertyName, AttributeFormat.DATE, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":" + QUOTE + dateFormat.format(exactDate) + QUOTE); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery buildDateQuery(String propertyName, String startCondition, String startDate, String endDate, String endCondition) {//from ww w . j a v a2 s . c o m SolrQuery query = new SolrQuery(); query.setQuery(" " + getMappedPropertyName(propertyName, AttributeFormat.DATE, false) + startCondition + startDate + TO + endDate + endCondition); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getGreaterThanOrEqualToQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":[ " + literal.toString() + TO + "* ] "); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getEqualToQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":" + literal.toString()); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getGreaterThanQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":{ " + literal.toString() + TO + "* ] "); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getLessThanOrEqualToQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":[ * TO " + literal.toString() + " ] "); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getLessThanQuery(String propertyName, AttributeFormat format, Number literal) { String mappedPropertyName = getMappedPropertyName(propertyName, format, true); SolrQuery query = new SolrQuery(); query.setQuery(" " + mappedPropertyName + ":[ * TO " + literal.toString() + " } "); return query; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery logicalOperator(List<SolrQuery> operands, String operator) { if (operands == null || operands.size() < 1) { throw new UnsupportedOperationException("[" + operator + "] operation must contain 1 or more filters."); }//w ww .j av a2 s . co m // Due to a bug in how solr parses queries, a sorted spatial operand (combined with any // other operand) // must come first in any given expression, so we have to add it to the beginning of the // operand list. for (int i = 0; i < operands.size(); i++) { SolrQuery operand = operands.get(i); if (operand == null) { throw new UnsupportedOperationException("Null operand found"); } String operandAsString = operand.toString(); try { if (operandAsString.contains(URLEncoder.encode(SCORE_DISTANCE, "UTF-8"))) { SolrQuery temp = operands.get(0); operands.set(0, operand); operands.set(i, temp); break; } } catch (UnsupportedEncodingException e) { LOGGER.info("Unable to encode {}", SCORE_DISTANCE, e); } } int startIndex = 0; SolrQuery query = operands.get(startIndex); startIndex++; if (query == null) { throw new UnsupportedOperationException( "Query was not interpreted properly. Query should not be null."); } StringBuilder builder = new StringBuilder(); builder.append(START_PAREN); builder.append(query.getQuery()); for (int i = startIndex; i < operands.size(); i++) { SolrQuery localQuery = operands.get(i); if (localQuery != null) { String localPhrase = localQuery.getQuery(); builder.append(operator + localPhrase); } else { throw new UnsupportedOperationException( "Query was not interpreted properly. Query should not be null."); } } builder.append(END_PAREN); query.setQuery(builder.toString()); return query; }
From source file:ddf.catalog.source.solr.SolrFilterDelegate.java
License:Open Source License
private SolrQuery logicalOperator(List<SolrQuery> operands, String operator) { if (operands == null || operands.size() < 1) { throw new UnsupportedOperationException("[" + operator + "] operation must contain 1 or more filters."); }// www . ja v a 2 s .c om // Due to a bug in how solr parses queries, a sorted spatial operand (combined with any // other operand) // must come first in any given expression, so we have to add it to the beginning of the // operand list. for (int i = 0; i < operands.size(); i++) { SolrQuery operand = operands.get(i); if (operand == null) { throw new UnsupportedOperationException("Null operand found"); } String operandAsString = operand.toString(); try { if (operandAsString.contains(URLEncoder.encode(SCORE_DISTANCE, "UTF-8"))) { SolrQuery temp = operands.get(0); operands.set(0, operand); operands.set(i, temp); break; } } catch (UnsupportedEncodingException e) { LOGGER.info("Unable to encode {}", SCORE_DISTANCE, e); } } int startIndex = 0; SolrQuery query = operands.get(startIndex); startIndex++; if (query == null) { throw new UnsupportedOperationException( "Query was not interpreted properly. Query should not be null."); } StringBuilder builder = new StringBuilder(); builder.append(START_PAREN); builder.append(query.getQuery()); for (int i = startIndex; i < operands.size(); i++) { SolrQuery localQuery = operands.get(i); if (localQuery != null) { builder.append(operator).append(localQuery.getQuery()); } else { throw new UnsupportedOperationException( "Query was not interpreted properly. Query should not be null."); } } builder.append(END_PAREN); query.setQuery(builder.toString()); return query; }
From source file:ddf.catalog.source.solr.SolrMetacardClient.java
License:Open Source License
public List<Metacard> query(String queryString) throws UnsupportedQueryException { SolrQuery query = new SolrQuery(); query.setQuery(queryString); try {//from w ww . j a v a2 s . c o m QueryResponse solrResponse = server.query(query, SolrRequest.METHOD.POST); SolrDocumentList docs = solrResponse.getResults(); List<Metacard> results = new ArrayList<>(); for (SolrDocument doc : docs) { try { results.add(createMetacard(doc)); } catch (MetacardCreationException e) { LOGGER.warn("Metacard creation exception creating result", e); throw new UnsupportedQueryException("Could not create metacard(s)."); } } return results; } catch (SolrServerException e) { LOGGER.warn("Failure in Solr server query.", e); throw new UnsupportedQueryException("Could not complete solr query."); } }