List of usage examples for org.apache.solr.client.solrj SolrQuery remove
public String[] remove(String name)
From source file:au.org.ala.biocache.dao.SearchDAOImpl.java
License:Open Source License
/** * Writes the values for the first supplied facet to output stream * * @param includeCount true when the count should be included in the download * @param lookupName true when a name lsid should be looked up in the bie *//*from w w w .j a v a2 s.c om*/ public void writeFacetToStream(SpatialSearchRequestParams searchParams, boolean includeCount, boolean lookupName, boolean includeSynonyms, boolean includeLists, OutputStream out, DownloadDetailsDTO dd) throws Exception { //set to unlimited facets searchParams.setFlimit(-1); queryFormatUtils.formatSearchQuery(searchParams); String queryString = searchParams.getFormattedQuery(); SolrQuery solrQuery = initSolrQuery(searchParams, false, null); solrQuery.setQuery(queryString); //don't want any results returned solrQuery.setRows(0); searchParams.setPageSize(0); solrQuery.setFacetLimit(FACET_PAGE_SIZE); int offset = 0; boolean shouldLookup = lookupName && (searchParams.getFacets()[0].contains("_guid") || searchParams.getFacets()[0].contains("_lsid")); if (dd != null) { dd.resetCounts(); } QueryResponse qr = runSolrQuery(solrQuery, searchParams); if (logger.isDebugEnabled()) { logger.debug("Retrieved facet results from server..."); } if (qr.getResults().getNumFound() > 0) { FacetField ff = qr.getFacetField(searchParams.getFacets()[0]); //write the header line if (ff != null) { String[] header = new String[] { ff.getName() }; // out.write(ff.getName().getBytes()); if (shouldLookup) { header = speciesLookupService.getHeaderDetails(ff.getName(), includeCount, includeSynonyms); } else if (includeCount) { //out.write(",Count".getBytes()); header = (String[]) ArrayUtils.add(header, "count"); } if (includeLists) { header = (String[]) ArrayUtils.addAll(header, listsService.getTypes().toArray(new String[] {})); } CSVRecordWriter writer = new CSVRecordWriter(new CloseShieldOutputStream(out), header); try { boolean addedNullFacet = false; //out.write("\n".getBytes()); //PAGE through the facets until we reach the end. //do not continue when null facet is already added and the next facet is only null while (ff.getValueCount() > 1 || !addedNullFacet || (ff.getValueCount() == 1 && ff.getValues().get(0).getName() != null)) { //process the "species_guid_ facet by looking up the list of guids if (shouldLookup) { List<String> guids = new ArrayList<String>(); List<Long> counts = new ArrayList<Long>(); List<String[]> speciesLists = new ArrayList<String[]>(); if (logger.isDebugEnabled()) { logger.debug("Downloading " + ff.getValueCount() + " species guids"); } for (FacetField.Count value : ff.getValues()) { //only add null facet once if (value.getName() == null) addedNullFacet = true; if (value.getCount() == 0 || (value.getName() == null && addedNullFacet)) continue; guids.add(value.getName()); if (includeCount) { counts.add(value.getCount()); } //Only want to send a sub set of the list so that the URI is not too long for BIE if (guids.size() == 30) { //now get the list of species from the web service TODO may need to move this code //handle null values being returned from the service... writeTaxonDetailsToStream(guids, counts, includeCount, includeSynonyms, includeLists, writer); guids.clear(); counts.clear(); } } //now write any guids that remain at the end of the looping writeTaxonDetailsToStream(guids, counts, includeCount, includeSynonyms, includeLists, writer); } else { //default processing of facets for (FacetField.Count value : ff.getValues()) { //only add null facet once if (value.getName() == null) addedNullFacet = true; if (value.getCount() == 0 || (value.getName() == null && addedNullFacet)) continue; String name = value.getName() != null ? value.getName() : ""; String[] row = includeCount ? new String[] { name, Long.toString(value.getCount()) } : new String[] { name }; writer.write(row); } } offset += FACET_PAGE_SIZE; if (dd != null) { dd.updateCounts(FACET_PAGE_SIZE); } //get the next values solrQuery.remove("facet.offset"); solrQuery.add("facet.offset", Integer.toString(offset)); qr = runSolrQuery(solrQuery, searchParams); ff = qr.getFacetField(searchParams.getFacets()[0]); } } finally { writer.finalise(); } } } }
From source file:edu.unc.lib.dl.ui.service.SolrQueryLayerService.java
License:Apache License
private void executeChildrenCounts(StringBuilder query, List<BriefObjectMetadata> containerObjects, SolrQuery solrQuery, String countName, Integer tier) { String ancestorPathField = solrSettings.getFieldName(SearchFieldKeys.ANCESTOR_PATH.name()); // Remove all ancestor path related filter queries or filter queries from previous count executions, so the counts // won't be cut off if (solrQuery.getFilterQueries() != null) { for (String filterQuery : solrQuery.getFilterQueries()) { if (filterQuery.contains(ancestorPathField)) { solrQuery.removeFilterQuery(filterQuery); }/*from w w w . j a v a2 s . c om*/ } } if (tier != null) { solrQuery.remove("f." + ancestorPathField + ".facet.prefix"); solrQuery.add("f." + ancestorPathField + ".facet.prefix", tier + ","); } solrQuery.addFilterQuery(query.toString()); try { long startTime = System.currentTimeMillis(); QueryResponse queryResponse = this.executeQuery(solrQuery); LOG.info("Query executed in " + (System.currentTimeMillis() - startTime)); assignChildrenCounts(queryResponse.getFacetField(ancestorPathField), containerObjects, countName); } catch (SolrServerException e) { LOG.error("Error retrieving Solr search result request", e); } }
From source file:org.openmrs.module.chartsearch.solr.ChartSearchSearcher.java
License:Mozilla Public License
public List<ChartListItem> getDocumentList(Integer patientId, String searchText, Integer start, Integer length, List<String> selectedCategories) throws Exception { SolrServer solrServer = SolrSingleton.getInstance().getServer(); SolrQuery query = new SolrQuery(); List<ChartListItem> list = new ArrayList<ChartListItem>(); ChartSearchNonFacetFiltering nonFaceting = new ChartSearchNonFacetFiltering(); searchText = StringUtils.isNotBlank(searchText) ? searchText : "*"; //check for existence of characters such as ", and : in the search text and submit as it is if so if (searchText.contains("\"")) { String searchWhole = "text:" + searchText; query.setQuery(searchWhole);/* ww w . j a va2s .c o m*/ } else if (searchText.contains(":")) { query.setQuery(searchText); } else if (searchText.equals("*")) { query.setQuery(String.format("text:(%s)", searchText)); } else { ChartSearchSyntax searchSyntax = new ChartSearchSyntax(searchText); searchText = searchSyntax.getSearchQuery(); if (StringUtils.isNumeric(searchText)) { //this allows 36 returning 36.* for numerics searchText = searchText + ".*" + " || " + searchText; } query.setQuery(String.format("text:(%s)", searchText)); } query.addFilterQuery(String.format("person_id:%d", patientId)); addSelectedFilterQueriesToQuery(query, selectedCategories); query.setStart(start); query.setRows(length); query.setHighlight(true).setHighlightSnippets(1).setHighlightSimplePre("<b>") .setHighlightSimplePost("</b>"); query.setParam("hl.fl", "text"); query.remove(FacetParams.FACET_FIELD); query.setFacet(true); //adding facet field for concept_class query.addFacetField("concept_class_name"); nonFaceting.applyNonFacetingLogicWhileSearching(patientId, searchText, selectedCategories, solrServer, query, list); return list; }