List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery(String q)
From source file:cz.incad.vdkcommon.solr.Indexer.java
License:Open Source License
public void run() throws Exception { readStatus();/* ww w . j av a 2s .com*/ if (jobData.getBoolean("full_index", false)) { reindex(); } else { if (statusJson.has(LAST_UPDATE)) { update(statusJson.getString(LAST_UPDATE)); } else { update(null); } if (jobData.getBoolean("reindex_offers", false)) { removeAllOffers(); indexAllOffers(); } if (jobData.getBoolean("reindex_demands", false)) { removeAllDemands(); indexAllDemands(); } if (jobData.getBoolean("reindex_wanted", false)) { removeAllWanted(); indexAllWanted(); } if (!"".equals(jobData.getString("identifier", ""))) { LOGGER.log(Level.INFO, "----- Reindexing doc {0} ...", jobData.getString("identifier")); SolrQuery query = new SolrQuery("id:\"" + jobData.getString("identifier") + "\""); query.addField("id,code"); query.setRows(1000); SolrDocumentList docs = IndexerQuery.query(opts.getString("solrIdCore", "vdk_id"), query); Iterator<SolrDocument> iter = docs.iterator(); while (iter.hasNext()) { SolrDocument resultDoc = iter.next(); String uniqueCode = (String) resultDoc.getFieldValue("code"); reindexDoc(uniqueCode, jobData.getString("identifier")); } } } writeStatus(); }
From source file:cz.zcu.kiv.eegdatabase.logic.search.FulltextSearchService.java
License:Apache License
/** * Given the input query, finds out the total count of full text results for each full text result type. * @param solrQuery The search query.// w w w.java 2s .c om * @return Map containg category-count pairs. */ public Map<String, Long> getCategoryFacets(String solrQuery) { SolrQuery query = new SolrQuery(solrQuery); query.setParam("fl", IndexField.UUID.getValue()); query.setHighlight(false); query.setFacet(true); query.addFacetField(IndexField.CLASS.getValue()); Map<String, Long> results = new HashMap<String, Long>(); QueryResponse response = null; try { response = solrServer.query(query); } catch (SolrServerException e) { log.error(e); } long totalCount = 0; List<FacetField> facets = response.getFacetFields(); for (FacetField field : facets) { log.info("count: " + field.getValueCount()); List<FacetField.Count> facetEntries = field.getValues(); for (FacetField.Count count : facetEntries) { long countValue = count.getCount(); results.put(count.getName(), countValue); log.info(count.getName() + ", " + countValue); totalCount += countValue; } } // add a "facet" for all results results.put(ResultCategory.ALL.getValue(), totalCount); return results; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
@Override public SolrQuery not(SolrQuery operand) { return new SolrQuery(" NOT " + operand.getQuery()); }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
@Override public SolrQuery propertyIsFuzzy(String propertyName, String searchPhrase) { String mappedPropertyName = getMappedPropertyName(propertyName, AttributeFormat.STRING, false); StringBuilder phraseBuilder = new StringBuilder(); for (String term : StringUtils.split(searchPhrase)) { // On fuzzy searches, no text analysis is performed on the search phrase. Expect fuzzy // terms to be // case insensitive. phraseBuilder.append("+").append(mappedPropertyName).append(":").append(term.toLowerCase()) .append("~ "); }/*from www . ja v a2s.com*/ return new SolrQuery(phraseBuilder.toString()); }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
@Override public SolrQuery propertyIsLike(String propertyName, String pattern, boolean isCaseSensitive) { verifyInputData(propertyName, pattern); String mappedPropertyName = getMappedPropertyName(propertyName, AttributeFormat.STRING, false); if (isCaseSensitive) { mappedPropertyName = resolver.getCaseSensitiveField(mappedPropertyName); }//from w ww . j a v a2 s . c o m String searchPhrase = escapeSpecialCharacters(pattern); if (!searchPhrase.contains(SOLR_WILDCARD_CHAR) && !searchPhrase.contains(SOLR_SINGLE_WILDCARD_CHAR)) { // Not an exact phrase searchPhrase = QUOTE + searchPhrase + QUOTE; } else { searchPhrase = "(" + searchPhrase + ")"; } return new SolrQuery(mappedPropertyName + ":" + searchPhrase); }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
@Override public SolrQuery propertyIsEqualTo(String propertyName, String literal, boolean isCaseSensitive) { if (!isCaseSensitive) { throw new UnsupportedOperationException("Case insensitive exact searches are not supported."); }//from w w w .j a v a 2 s . c om verifyInputData(propertyName, literal); String mappedPropertyName = getMappedPropertyName(propertyName, AttributeFormat.STRING, true); return new SolrQuery(mappedPropertyName + ":" + QUOTE + escapeSpecialCharacters(literal) + QUOTE); }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
/** * This builds a "is null" query based on the property name provided. * * Since no type is provided with this method, we build a OR chained expression with anonymous field names. * The actually expression uses a negative ranged query expression. The null query needs to be used in order for this * expression to play well with other nested expressions. The query used is outlined in: * http://stackoverflow.com/questions/17044661/how-to-filter-search-by-values-that-are-not-available/17045097#17045097 * * @param propertyName the property to null check against. * @return the solr query with the is null expression. *//*from w w w . j av a 2 s .c o m*/ @Override public SolrQuery propertyIsNull(String propertyName) { List<String> possibleFields = resolver.getAnonymousField(propertyName); if (possibleFields.isEmpty()) { throw new UnsupportedOperationException("Anonymous Field Property does not exist. " + propertyName); } List<String> solrExpressions = new ArrayList<>(); for (String possibleField : possibleFields) { solrExpressions.add(" (*:* -" + possibleField + ":[* TO *]) "); } String fullExpression = StringUtils.join(solrExpressions, " "); return new SolrQuery(fullExpression); }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getXPathQuery(final String pattern, final String searchPhrase, final boolean isCaseSensitive) { // TODO should use XPath parser to make sure to only remove namespace pattern from path and not quoted text // replace quotes and remove namespaces String xpath = pattern.replace("\"", "'").replaceAll("[\\w]+:(?!:)", ""); String query = "*:*"; if (StringUtils.isNotBlank(searchPhrase)) { String result = "."; String phrase = searchPhrase; if (!isCaseSensitive) { result = "lower-case(" + result + ")"; phrase = phrase.toLowerCase(); }/*w w w .j a v a 2 s . c o m*/ xpath = xpath + "[contains(" + result + ", '" + phrase + "')]"; query = TOKENIZED_METADATA_FIELD + ":\"" + searchPhrase.replaceAll("\"", "\\\\") + "\""; } SolrQuery solrQuery = new SolrQuery(query); solrQuery.addFilterQuery(XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY + ":\"" + xpath + "\"", XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY_INDEX + ":\"" + xpath + "\""); return solrQuery; }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery getSolrQueryWithSort(String givenSpatialString) { if (sortBy != null && sortBy.getPropertyName() != null && Result.DISTANCE.equals(sortBy.getPropertyName().getPropertyName())) { String spatialQueryWithDistance = SCORE_DISTANCE + givenSpatialString; SolrQuery solrQuery = new SolrQuery(spatialQueryWithDistance); solrQuery.setFields("*", "score"); ORDER sortOrder = ORDER.asc;/* w w w . j ava2 s . c o m*/ if (SortOrder.DESCENDING.equals(sortBy.getSortOrder())) { sortOrder = ORDER.desc; } solrQuery.setSortField("score", sortOrder); return new SolrQuery(spatialQueryWithDistance); } else { return new SolrQuery(givenSpatialString); } }
From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java
License:Open Source License
private SolrQuery operationOnIndexToQuery(String operation, String indexName, String wkt) { if (StringUtils.isNotEmpty(wkt)) { String geoQuery = indexName + ":\"" + operation + "(" + wkt + ")\""; return new SolrQuery(geoQuery); } else {/* ww w . ja va2 s . co m*/ throw new UnsupportedOperationException("Wkt should not be null or empty."); } }