List of usage examples for org.apache.solr.client.solrj SolrQuery setFacetMinCount
public SolrQuery setFacetMinCount(int cnt)
From source file:org.opencastproject.workflow.impl.WorkflowServiceSolrIndex.java
License:Educational Community License
/** * {@inheritDoc}//from www . j a v a 2 s . c om * * @see org.opencastproject.workflow.impl.WorkflowServiceIndex#getStatistics() */ @Override public WorkflowStatistics getStatistics() throws WorkflowDatabaseException { long total = 0; long paused = 0; long failed = 0; long failing = 0; long instantiated = 0; long running = 0; long stopped = 0; long succeeded = 0; WorkflowStatistics stats = new WorkflowStatistics(); // Get all definitions and then query for the numbers and the current operation per definition try { String orgId = securityService.getOrganization().getId(); StringBuilder queryString = new StringBuilder().append(ORG_KEY).append(":") .append(escapeQueryChars(orgId)); appendSolrAuthFragment(queryString, WRITE_PERMISSION); SolrQuery solrQuery = new SolrQuery(queryString.toString()); solrQuery.addFacetField(WORKFLOW_DEFINITION_KEY); solrQuery.addFacetField(OPERATION_KEY); solrQuery.setFacetMinCount(0); solrQuery.setFacet(true); QueryResponse response = solrServer.query(solrQuery); FacetField templateFacet = response.getFacetField(WORKFLOW_DEFINITION_KEY); FacetField operationFacet = response.getFacetField(OPERATION_KEY); // For every template and every operation if (templateFacet != null && templateFacet.getValues() != null) { for (Count template : templateFacet.getValues()) { WorkflowDefinitionReport templateReport = new WorkflowDefinitionReport(); templateReport.setId(template.getName()); long templateTotal = 0; long templatePaused = 0; long templateFailed = 0; long templateFailing = 0; long templateInstantiated = 0; long templateRunning = 0; long templateStopped = 0; long templateSucceeded = 0; if (operationFacet != null && operationFacet.getValues() != null) { for (Count operation : operationFacet.getValues()) { OperationReport operationReport = new OperationReport(); operationReport.setId(operation.getName()); StringBuilder baseSolrQuery = new StringBuilder().append(ORG_KEY).append(":") .append(escapeQueryChars(orgId)); appendSolrAuthFragment(baseSolrQuery, WRITE_PERMISSION); solrQuery = new SolrQuery(baseSolrQuery.toString()); solrQuery.addFacetField(STATE_KEY); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.FAILED); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.FAILING); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.INSTANTIATED); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.PAUSED); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.RUNNING); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.STOPPED); solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.SUCCEEDED); solrQuery.addFilterQuery(WORKFLOW_DEFINITION_KEY + ":" + template.getName()); solrQuery.addFilterQuery(OPERATION_KEY + ":" + operation.getName()); solrQuery.setFacetMinCount(0); solrQuery.setFacet(true); response = solrServer.query(solrQuery); // Add the states FacetField stateFacet = response.getFacetField(STATE_KEY); for (Count stateValue : stateFacet.getValues()) { WorkflowState state = WorkflowState.valueOf(stateValue.getName().toUpperCase()); templateTotal += stateValue.getCount(); total += stateValue.getCount(); switch (state) { case FAILED: operationReport.setFailed(stateValue.getCount()); templateFailed += stateValue.getCount(); failed += stateValue.getCount(); break; case FAILING: operationReport.setFailing(stateValue.getCount()); templateFailing += stateValue.getCount(); failing += stateValue.getCount(); break; case INSTANTIATED: operationReport.setInstantiated(stateValue.getCount()); templateInstantiated += stateValue.getCount(); instantiated += stateValue.getCount(); break; case PAUSED: operationReport.setPaused(stateValue.getCount()); templatePaused += stateValue.getCount(); paused += stateValue.getCount(); break; case RUNNING: operationReport.setRunning(stateValue.getCount()); templateRunning += stateValue.getCount(); running += stateValue.getCount(); break; case STOPPED: operationReport.setStopped(stateValue.getCount()); templateStopped += stateValue.getCount(); stopped += stateValue.getCount(); break; case SUCCEEDED: operationReport.setFinished(stateValue.getCount()); templateSucceeded += stateValue.getCount(); succeeded += stateValue.getCount(); break; default: throw new IllegalStateException("State '" + state + "' is not handled"); } } templateReport.getOperations().add(operationReport); } } // Update the template statistics templateReport.setTotal(templateTotal); templateReport.setFailed(templateFailed); templateReport.setFailing(templateFailing); templateReport.setInstantiated(templateInstantiated); templateReport.setPaused(templatePaused); templateReport.setRunning(templateRunning); templateReport.setStopped(templateStopped); templateReport.setFinished(templateSucceeded); // Add the definition report to the statistics stats.getDefinitions().add(templateReport); } } } catch (SolrServerException e) { throw new WorkflowDatabaseException(e); } stats.setTotal(total); stats.setFailed(failed); stats.setFailing(failing); stats.setInstantiated(instantiated); stats.setPaused(paused); stats.setRunning(running); stats.setStopped(stopped); stats.setFinished(succeeded); return stats; }
From source file:org.opencommercesearch.AbstractSearchServer.java
License:Apache License
@Override public Facet getFacet(Site site, Locale locale, String fieldFacet, int facetLimit, int depthLimit, String separator, FilterQuery... filterQueries) throws SearchServerException { try {/*w w w. ja va 2 s . c o m*/ SolrQuery query = new SolrQuery(); query.setRows(0); query.setQuery("*:*"); query.addFacetField(fieldFacet); query.setFacetLimit(facetLimit); query.setFacetMinCount(1); query.addFilterQuery("country:" + locale.getCountry()); RepositoryItem catalog = (RepositoryItem) site.getPropertyValue("defaultCatalog"); String catalogId = catalog.getRepositoryId(); query.setFacetPrefix(CATEGORY_PATH, catalogId + "."); query.addFilterQuery(CATEGORY_PATH + ":" + catalogId); if (filterQueries != null) { for (FilterQuery filterQuery : filterQueries) { query.addFilterQuery(filterQuery.toString()); } } QueryResponse queryResponse = getCatalogSolrServer(locale).query(query); Facet facet = null; if (queryResponse != null && queryResponse.getFacetFields() != null) { FacetField facetField = queryResponse.getFacetField(fieldFacet); if (facetField != null) { List<Count> values = facetField.getValues(); if (values != null && !values.isEmpty()) { facet = new Facet(); facet.setName(StringUtils.capitalize(fieldFacet)); List<Filter> filters = new ArrayList<Facet.Filter>(); boolean filterByDepth = depthLimit > 0 && StringUtils.isNotBlank(separator); for (Count count : values) { if (filterByDepth && StringUtils.countMatches(count.getName(), separator) > depthLimit) { continue; } Filter filter = new Filter(); filter.setName(count.getName()); filter.setCount(count.getCount()); filter.setFilterQuery(count.getAsFilterQuery()); filter.setFilterQueries(count.getAsFilterQuery()); filters.add(filter); } facet.setFilters(filters); } } } return facet; } catch (SolrServerException ex) { throw create(SEARCH_EXCEPTION, ex); } catch (SolrException ex) { throw create(SEARCH_EXCEPTION, ex); } }
From source file:org.pentaho.di.trans.steps.solrinput.SolrInput.java
License:Apache License
/** * Once the transformation starts executing, the processRow() method is called repeatedly * by PDI for as long as it returns true. To indicate that a step has finished processing rows * this method must call setOutputDone() and return false; * /*w w w . j a va 2s.co m*/ * Steps which process incoming rows typically call getRow() to read a single row from the * input stream, change or add row content, call putRow() to pass the changed row on * and return true. If getRow() returns null, no more rows are expected to come in, * and the processRow() implementation calls setOutputDone() and returns false to * indicate that it is done too. * * Steps which generate rows typically construct a new row Object[] using a call to * RowDataUtil.allocateRowData(numberOfFields), add row content, and call putRow() to * pass the new row on. Above process may happen in a loop to generate multiple rows, * at the end of which processRow() would call setOutputDone() and return false; * * @param smi the step meta interface containing the step settings * @param sdi the step data interface that should be used to store * * @return true to indicate that the function should be called again, false if the step is done */ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { if (first) { first = false; // Create the output row meta-data data.outputRowMeta = new RowMeta(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore); // For String to <type> conversions, we allocate a conversion meta data row as well... data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING); // get real values boolean tryCursor = true; Integer startRecord = 0; Integer chunkRowSize = 20; String realURL = meta.getURL(); String realQ = meta.getQ(); String realSort = meta.getSort(); String realCursor = meta.getCursor(); String realFq = meta.getFq(); String realFl = meta.getFl(); String realFacetQuery = meta.getFacetQuery(); String realFacetField = meta.getFacetField(); /* Send and Get the report */ SolrQuery query = new SolrQuery(); query.set("rows", chunkRowSize); if (realQ != null && !realQ.equals("")) { query.set("q", realQ); } if (realSort != null && !realSort.equals("")) { query.set("sort", realSort); } else { tryCursor = false; } if (realCursor != null && !realCursor.equals("")) { if (realCursor.equals("No")) { tryCursor = false; } } if (realFl != null && !realFl.equals("")) { query.set("fl", realFl); } if (realFq != null && !realFq.equals("")) { query.set("fq", realFq); } if (realFacetField != null && !realFacetField.equals("")) { //TODO incorporate multiple facet fields at once //String[] facetFields = realFacetField.split("\\s*,\\s*"); //for(int i =0; i < facetFields.length; i++){ query.addFacetField(realFacetField); //} query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(0); query.setFacetSort("count"); query.set("rows", 0); tryCursor = false; data.facetRequested = true; } if (realFacetQuery != null && !realFacetQuery.equals("")) { query.addFacetQuery(realFacetQuery); } // You can't use "TimeAllowed" with "CursorMark" // The documentation says "Values <= 0 mean // no time restriction", so setting to 0. query.setTimeAllowed(0); HttpSolrServer solr = new HttpSolrServer(realURL); String cursorMark = CursorMarkParams.CURSOR_MARK_START; boolean done = false; QueryResponse rsp = null; while (!done) { if (tryCursor) { query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); } else { query.setStart(startRecord); } try { rsp = solr.query(query); } catch (SolrServerException e) { e.printStackTrace(); } if (data.facetRequested) { data.facetCountName = rsp.getFacetFields().get(0).getName(); data.facetCounts = rsp.getFacetFields().get(0).getValues(); done = true; } else { SolrDocumentList theseDocs = rsp.getResults(); for (SolrDocument doc : theseDocs) { data.documentList.add(doc); } } if (tryCursor) { String nextCursorMark = rsp.getNextCursorMark(); if (cursorMark.equals(nextCursorMark)) { done = true; } else { cursorMark = nextCursorMark; } } else { startRecord = startRecord + chunkRowSize; if (startRecord >= rsp.getResults().getNumFound()) { done = true; } } } } Object[] outputRowData = null; try { if (data.facetRequested) { // get one row if we can if (data.facetCounts.size() - 1 < data.recordIndex) { setOutputDone(); return false; } FacetField.Count facetRecord = data.facetCounts.get(data.recordIndex); outputRowData = prepareFacetRecord(facetRecord); } else { // get one row if we can if (data.documentList.size() - 1 < data.recordIndex) { setOutputDone(); return false; } SolrDocument record = data.documentList.get(data.recordIndex); outputRowData = prepareRecord(record); } putRow(data.outputRowMeta, outputRowData); // copy row to output rowset(s); data.recordIndex++; return true; } catch (KettleException e) { boolean sendToErrorRow = false; String errorMessage = null; if (getStepMeta().isDoingErrorHandling()) { sendToErrorRow = true; errorMessage = e.toString(); } else { logError(BaseMessages.getString(PKG, "SolrInput.log.Exception", e.getMessage())); logError(Const.getStackTracker(e)); setErrors(1); stopAll(); setOutputDone(); // signal end to receiver(s) return false; } if (sendToErrorRow) { // Simply add this row to the error row putError(getInputRowMeta(), outputRowData, 1, errorMessage, null, "SolrInput001"); } } return true; }
From source file:org.pentaho.di.ui.trans.steps.solrinput.SolrInputDialog.java
License:Apache License
private void getFields() { try {//from w w w. j a v a 2 s . c o m SolrInputMeta meta = new SolrInputMeta(); getInfo(meta); // clear the current fields grid wFields.removeAll(); // get real values boolean tryCursor = true; boolean facetRequested = false; Integer startRecord = 0; Integer chunkRowSize = 20; String realURL = transMeta.environmentSubstitute(meta.getURL()); String realQ = transMeta.environmentSubstitute(meta.getQ()); String realSort = transMeta.environmentSubstitute(meta.getSort()); String realCursor = transMeta.environmentSubstitute(meta.getCursor()); String realFq = transMeta.environmentSubstitute(meta.getFq()); String realFl = transMeta.environmentSubstitute(meta.getFl()); String realFacetQuery = transMeta.environmentSubstitute(meta.getFacetQuery()); String realFacetField = transMeta.environmentSubstitute(meta.getFacetField()); /* Send and Get the report */ SolrQuery query = new SolrQuery(); query.set("rows", chunkRowSize); if (realQ != null && !realQ.equals("")) { query.set("q", realQ); } if (realSort != null && !realSort.equals("")) { query.set("sort", realSort); } else { tryCursor = false; } if (realCursor != null && !realCursor.equals("")) { if (realCursor.equals("No")) { tryCursor = false; } } if (realFl != null && !realFl.equals("")) { query.set("fl", realFl); } if (realFq != null && !realFq.equals("")) { query.set("fq", realFq); } if (realFacetField != null && !realFacetField.equals("")) { //TODO incorporate multiple facet fields at once //String[] facetFields = realFacetField.split("\\s*,\\s*"); //for(int i =0; i < facetFields.length; i++){ query.addFacetField(realFacetField); //} query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(0); query.setFacetSort("count"); query.set("rows", 0); tryCursor = false; facetRequested = true; } if (realFacetQuery != null && !realFacetQuery.equals("")) { query.addFacetQuery(realFacetQuery); } // You can't use "TimeAllowed" with "CursorMark" // The documentation says "Values <= 0 mean // no time restriction", so setting to 0. query.setTimeAllowed(0); HttpSolrServer solr = new HttpSolrServer(realURL); String cursorMark = CursorMarkParams.CURSOR_MARK_START; boolean done = false; List<String> headerNames = new ArrayList<String>(); QueryResponse rsp = null; while (!done) { if (tryCursor) { query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); } else { query.setStart(startRecord); } try { rsp = solr.query(query); } catch (SolrServerException e) { e.printStackTrace(); } if (facetRequested) { headerNames.add(rsp.getFacetFields().get(0).getName()); headerNames.add("count"); done = true; } else { SolrDocumentList docs = rsp.getResults(); for (SolrDocument doc : docs) { Collection<String> thisNamesArray = doc.getFieldNames(); String[] a = thisNamesArray.toArray(new String[thisNamesArray.size()]); for (int j = 0; j < a.length; j++) { if (!headerNames.contains(a[j])) { headerNames.add(a[j]); } } } } if (tryCursor) { String nextCursorMark = rsp.getNextCursorMark(); if (cursorMark.equals(nextCursorMark)) { done = true; } else { cursorMark = nextCursorMark; } } else { startRecord = startRecord + chunkRowSize; if (startRecord >= rsp.getResults().getNumFound()) { done = true; } } } getTableView().table.setItemCount(headerNames.size()); for (int j = 0; j < headerNames.size(); j++) { TableItem item = getTableView().table.getItem(j); item.setText(1, headerNames.get(j)); } wFields.removeEmptyRows(); wFields.setRowNums(); wFields.optWidth(true); getInput().setChanged(); } catch (Exception e) { new ErrorDialog(shell, BaseMessages.getString(PKG, "SolrInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "SolrInputMeta.ErrorRetrieveData.DialogMessage"), e); } }
From source file:org.springframework.data.solr.core.DefaultQueryParser.java
License:Apache License
private boolean enableFaceting(SolrQuery solrQuery, FacetQuery query) { FacetOptions facetOptions = query.getFacetOptions(); if (facetOptions == null || (!facetOptions.hasFields() && !facetOptions.hasFacetQueries() && !facetOptions.hasPivotFields())) { return false; }/*www. j av a 2 s . c om*/ solrQuery.setFacet(true); solrQuery.setFacetMinCount(facetOptions.getFacetMinCount()); solrQuery.setFacetLimit(facetOptions.getPageable().getPageSize()); if (facetOptions.getPageable().getPageNumber() > 0) { int offset = Math.max(0, facetOptions.getPageable().getOffset()); solrQuery.set(FacetParams.FACET_OFFSET, offset); } if (FacetOptions.FacetSort.INDEX.equals(facetOptions.getFacetSort())) { solrQuery.setFacetSort(FacetParams.FACET_SORT_INDEX); } return true; }
From source file:org.wso2.carbon.registry.indexing.solr.SolrClient.java
License:Open Source License
private String addFacetFields(Map<String, String> fields, SolrQuery query) { //set the facet true to enable facet //Need to set the Facet to true to enable Facet Query. query.setFacet(true);/*from w w w. j av a2s . com*/ String fieldName = fields.get(IndexingConstants.FACET_FIELD_NAME); String queryField = null; if (fieldName != null) { //set the field for the facet if (IndexingConstants.FIELD_TAGS.equals(fieldName) || IndexingConstants.FIELD_COMMENTS.equals(fieldName) || IndexingConstants.FIELD_ASSOCIATION_DESTINATIONS.equals(fieldName) || IndexingConstants.FIELD_ASSOCIATION_TYPES.equals(fieldName)) { queryField = fieldName + SolrConstants.SOLR_MULTIVALUED_STRING_FIELD_KEY_SUFFIX; query.addFacetField(queryField); } else { queryField = fieldName + SolrConstants.SOLR_STRING_FIELD_KEY_SUFFIX; query.addFacetField(queryField); } //remove the facet field avoid affecting to query results fields.remove(IndexingConstants.FACET_FIELD_NAME); //set the limit for the facet if (fields.get(IndexingConstants.FACET_LIMIT) != null) { query.setFacetLimit(Integer.parseInt(fields.get(IndexingConstants.FACET_LIMIT))); fields.remove(IndexingConstants.FACET_LIMIT); } else { query.setFacetLimit(IndexingConstants.FACET_LIMIT_DEFAULT); } //set the min count for the facet if (fields.get(IndexingConstants.FACET_MIN_COUNT) != null) { query.setFacetMinCount(Integer.parseInt(fields.get(IndexingConstants.FACET_MIN_COUNT))); fields.remove(IndexingConstants.FACET_MIN_COUNT); } else { query.setFacetMinCount(IndexingConstants.FACET_MIN_COUNT_DEFAULT); } //set the sort value for facet: possible values : index or count if (fields.get(IndexingConstants.FACET_SORT) != null) { query.setFacetSort(fields.get(IndexingConstants.FACET_SORT)); fields.remove(IndexingConstants.FACET_SORT); } // set the prefix value for facet if (fields.get(IndexingConstants.FACET_PREFIX) != null) { query.setFacetPrefix(fields.get(IndexingConstants.FACET_PREFIX)); fields.remove(IndexingConstants.FACET_PREFIX); } } return queryField; }
From source file:org.zaizi.sensefy.api.service.SolrSmartAutoCompleteService.java
License:Open Source License
/** * <p>// ww w . j a v a2 s. co m * Suggestions from Facet Prefix * </p> * * @param attributesQuery * @param termToComplete * @param numberOfSuggestions * @param suggestionField * @param solrCore * @return * @throws SolrServerException */ private List<String> suggestionsFromFacetPrefix(SolrQuery attributesQuery, String termToComplete, int numberOfSuggestions, String suggestionField, SolrServer solrCore) throws SolrServerException, IOException { List<String> suggestions = new ArrayList<String>(); attributesQuery.setRows(0); attributesQuery.setFacet(true); attributesQuery.addFacetField(suggestionField); attributesQuery.setFacetMinCount(1); attributesQuery.setFacetLimit(numberOfSuggestions); // if ( termToComplete != null && !termToComplete.isEmpty() ) attributesQuery.setFacetPrefix(suggestionField, termToComplete); QueryResponse attributesQueryResponse; attributesQueryResponse = solrCore.query(attributesQuery); FacetField facetField = attributesQueryResponse.getFacetField(suggestionField); List<FacetField.Count> facets = facetField.getValues(); for (FacetField.Count singleFacet : facets) { suggestions.add(singleFacet.getName()); } return suggestions; }
From source file:org.zenoss.zep.index.impl.solr.SolrEventIndexBackend.java
License:Open Source License
@Override protected void searchEventTagSeverities(EventFilter filter, final EventTagSeverityCounter counter) throws ZepException { assertReady();//from w w w .java2s. c om if (filter.getTagFilterCount() == 0) { SolrQuery solrQuery = buildSolrQuery(filter, null, null, null, null, SolrFieldFilter.DEFAULTS); solrQuery.setRows(0); solrQuery.setFields(); solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit(-1); solrQuery.addFacetPivotField(IndexConstants.FIELD_ELEMENT_IDENTIFIER, IndexConstants.FIELD_SEVERITY, IndexConstants.FIELD_STATUS, IndexConstants.FIELD_COUNT); try { QueryResponse response = queryServer.query(solrQuery); for (PivotField pivotElementId : response.getFacetPivot().getVal(0)) { final String uuid = (String) pivotElementId.getValue(); for (PivotField pivotSeverity : pivotElementId.getPivot()) { final EventSeverity severity = EventSeverity .valueOf(Integer.parseInt((String) pivotSeverity.getValue())); for (PivotField pivotStatus : pivotSeverity.getPivot()) { final EventStatus status = EventStatus .valueOf(Integer.parseInt((String) pivotStatus.getValue())); final boolean acknowledged = EventStatus.STATUS_ACKNOWLEDGED.equals(status); for (PivotField pivotCount : pivotStatus.getPivot()) { final Integer count = pivotCount.getCount() * (Integer) pivotCount.getValue(); counter.update(uuid, severity, count, acknowledged); } } } } } catch (SolrServerException e) { throw new ZepException(e); } } else { SolrQuery solrQuery = buildSolrQuery(filter, null, null, null, null, SolrFieldFilter.SEARCH_EVENT_TAG_SEVERITIES); try { queryServer.queryAndStreamResponse(solrQuery, new StreamingResponseCallback() { @Override public void streamSolrDocument(SolrDocument doc) { final EventSeverity severity = EventSeverity .valueOf(Integer.parseInt((String) doc.getFieldValue(FIELD_SEVERITY))); final EventStatus status = EventStatus .valueOf(Integer.parseInt((String) doc.getFieldValue(FIELD_STATUS))); final boolean acknowledged = EventStatus.STATUS_ACKNOWLEDGED.equals(status); final int count = Integer.parseInt((String) doc.getFieldValue(FIELD_COUNT)); for (String fieldName : new String[] { FIELD_ELEMENT_IDENTIFIER, FIELD_ELEMENT_SUB_IDENTIFIER }) { final String uuid = (String) doc.getFieldValue(fieldName); counter.update(uuid, severity, count, acknowledged); } for (Object tag : doc.getFieldValues(FIELD_TAGS)) { counter.update((String) tag, severity, count, acknowledged); } } @Override public void streamDocListInfo(long numFound, long start, Float maxScore) { // ignored } }); } catch (SolrServerException e) { throw new ZepException(e); } catch (IOException e) { throw new ZepException(e); } } }
From source file:ru.org.linux.search.SearchViewer.java
License:Apache License
public QueryResponse performSearch(SolrServer search) throws SolrServerException { SolrQuery params = new SolrQuery(); // set search query params params.set("q", query.getQ()); params.set("rows", SEARCH_ROWS); params.set("start", query.getOffset()); params.set("qt", "edismax"); if (query.getRange().getParam() != null) { params.add("fq", query.getRange().getParam()); }/*www. j a v a 2s . c o m*/ if (query.getInterval().getRange() != null) { params.add("fq", query.getInterval().getRange()); } params.setFacetMinCount(1); params.setFacet(true); String section = query.getSection(); if (section != null && !section.isEmpty() && !"0".equals(section)) { params.add("fq", "{!tag=dt}section:" + query.getSection()); params.addFacetField("{!ex=dt}section"); params.addFacetField("{!ex=dt}group_id"); } else { params.addFacetField("section"); params.addFacetField("group_id"); } if (query.getUser() != null) { User user = query.getUser(); if (query.isUsertopic()) { params.add("fq", "topic_user_id:" + user.getId()); } else { params.add("fq", "user_id:" + user.getId()); } } if (query.getGroup() != 0) { params.add("fq", "{!tag=dt}group_id:" + query.getGroup()); } params.set("sort", query.getSort().getParam()); return search.query(params); }
From source file:uk.ac.ebi.atlas.solr.query.builders.FacetedPropertyValueQueryBuilder.java
License:Apache License
private SolrQuery buildQueryObject(String queryString) { SolrQuery solrQuery = new SolrQuery(queryString); solrQuery.addFacetField(PROPERTY_LOWER_FIELD); solrQuery.setRows(0);/*from ww w . j av a2 s .co m*/ solrQuery.setFacet(true); solrQuery.setFacetLimit(DEFAULT_LIMIT); solrQuery.setFacetMinCount(1); return solrQuery; }