List of usage examples for org.apache.solr.client.solrj SolrQuery addFacetField
public SolrQuery addFacetField(String... fields)
From source file:org.dspace.app.cris.network.AVisualizationGraph.java
@Override public JsGraph search(String authority, String name, Integer level, boolean showExternal, boolean showSameDept, String dept, Integer modeEntity) throws Exception { SolrQuery solrQuery = new SolrQuery(); String query = buildQuery(authority, name, showSameDept, dept, modeEntity, level); String[] fqs = { "type:" + getConnectionName(), "entity:" + modeEntity }; solrQuery.setQuery(query);/*from www . j a va2 s .c o m*/ solrQuery.addFilterQuery(fqs); if (!showExternal && authority != null && !authority.isEmpty()) { solrQuery.addFilterQuery(new String[] { "a_auth:rp*", "b_auth:rp*" }); } solrQuery.setFacet(true); solrQuery.addFacetField(FACET_SEARCH); if (modeEntity == ConstantNetwork.ENTITY_RP) { solrQuery.setFacetLimit(getLimitLevel(level)); } else if (modeEntity == ConstantNetwork.ENTITY_DEPT) { solrQuery.setFacetLimit(Integer.MAX_VALUE); } solrQuery.setFacetMinCount(1); solrQuery.setRows(0); QueryResponse rsp = service.search(solrQuery); FacetField facets = rsp.getFacetField(FACET_SEARCH); JsGraph rsGraph = null; String src = null; if (authority != null && !authority.isEmpty()) { src = authority; rsGraph = new JsGraph(); rsGraph.setId(authority); rsGraph.setName(name); JsGraphNodeData dataNode = new JsGraphNodeData(); dataNode.setColor(getNodeCustomColor()); dataNode.setType(getType()); dataNode.setModeStyle("fill"); rsGraph.setData(dataNode); } else { src = name; rsGraph = new JsGraph(); rsGraph.setId(name); rsGraph.setName(name); JsGraphNodeData dataNodeLeaf = new JsGraphNodeData(); dataNodeLeaf.setColor(getNodeLeafCustomColor()); dataNodeLeaf.setType(getType()); dataNodeLeaf.setModeStyle("stroke"); rsGraph.setData(dataNodeLeaf); } if (rsGraph != null) { if (facets != null && facets.getValueCount() > 0) { for (Count facet : facets.getValues()) { if (facet.getCount() > 0) { String node2 = (String) facet.getName(); String split[] = node2.split("\\|\\|\\|"); String srcnode2 = null; String displayValue = ""; String authorityValue = null; boolean isAuthority = false; if (split.length > 1) { String[] splitAuthority = split[1].split(splitterAuthority); displayValue = splitAuthority[0]; srcnode2 = displayValue; if (splitAuthority.length > 1) { isAuthority = true; authorityValue = splitAuthority[1]; srcnode2 = authorityValue; } } else if (split.length == 1) { displayValue = split[0]; srcnode2 = displayValue; } if (!(src.equals(srcnode2))) { JsGraphAdjacence adjacence = new JsGraphAdjacence(); JsGraphData data = new JsGraphData(); adjacence.setSrc(node2); if (isAuthority) { adjacence.setNodeTo(authorityValue); } else { adjacence.setNodeTo(displayValue); } if (authorityValue != null || showExternal) { data.setColor(getEdgeCustomColor()); data.setLineWidth(getCustomLineWidth((int) facet.getCount())); data.setCount((int) facet.getCount()); data.setType(getType()); adjacence.setData(data); rsGraph.getAdjacencies().add(adjacence); } } } } } } return rsGraph; }
From source file:org.dspace.app.cris.network.AVisualizationGraph.java
public List<ResearcherPage> loadMetrics(List<String[]> discardedNode, Integer importedNodes, Boolean otherError) throws SearchServiceException { // load all publications SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("type:" + getType() + " AND entity:" + ConstantNetwork.ENTITY_RP); solrQuery.addFacetField(FACET_METRICS); solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setFacetMinCount(1);/*from w ww. ja va 2 s .c o m*/ solrQuery.setRows(0); QueryResponse rsp = getService().search(solrQuery); FacetField facets = rsp.getFacetField(FACET_METRICS); // for each interests get authority's authors List<ResearcherPage> result = new LinkedList<ResearcherPage>(); int counter = 0; external: for (Count facetElement : facets.getValues()) { counter++; log.debug("" + counter + " of " + facets.getValueCount()); ResearcherPage researcher = null; try { String facetValue = facetElement.getName(); Integer realPersistentIdentifier = ResearcherPageUtils.getRealPersistentIdentifier(facetValue, ResearcherPage.class); researcher = applicationService.get(ResearcherPage.class, realPersistentIdentifier); //researcher.getDynamicField().setAnagraficaLazy(applicationService.getAnagraficaByRP(realPersistentIdentifier)); solrQuery = new SolrQuery(); solrQuery.setQuery("type:" + getType() + " AND entity:" + ConstantNetwork.ENTITY_RP + " AND " + FACET_METRICS + ":\"" + facetValue + "\""); solrQuery.addFacetField(FACET_SEARCH); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setRows(0); rsp = getService().search(solrQuery); FacetField relations = rsp.getFacetField(FACET_SEARCH); int i = 0; int nConnections = 0; int maxStrength = 0; int sumStrength = 0; List<Long> quadraticVarianceArrays = new ArrayList<Long>(); nConnections = Integer.valueOf(relations.getValueCount() - 1); internal: for (Count relation : relations.getValues()) { log.debug("" + counter + " works on " + i + " of " + relations.getValueCount()); if (i == 0) { i++; continue internal; } else { if (i == 1) { // max maxStrength = Integer.valueOf((int) relation.getCount()); } sumStrength += Integer.valueOf((int) relation.getCount()); quadraticVarianceArrays.add(relation.getCount()); } i++; } RPAdditionalFieldStorage anagraficaObject = researcher.getDynamicField(); setMetadata(String.valueOf(nConnections), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1 + getType()); setMetadata(String.valueOf(maxStrength), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2 + getType()); double averageStrength = ((double) sumStrength / ((double) nConnections)); setMetadata(String.valueOf(df.format(averageStrength)), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3 + getType()); double quadraticVariance = 0; double n = quadraticVarianceArrays.size(); for (Long variance : quadraticVarianceArrays) { quadraticVariance += ((variance - averageStrength) * (variance - averageStrength)); } quadraticVariance = Math.sqrt(quadraticVariance / n); setMetadata(String.valueOf(df.format(quadraticVariance)), anagraficaObject, ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_4 + getType()); result.add(researcher); } catch (Exception e) { log.error("Error try to build object to index with ID:" + researcher.getId()); log.error(e.getMessage(), e); otherError = true; continue; } } committnode: for (ResearcherPage node : result) { // try // { applicationService.saveOrUpdate(ResearcherPage.class, node); boolean rr = ((CrisSearchService) getIndexer().getIndexer()).indexCrisObject(node, true); // index node if (rr) { importedNodes++; } else { discardedNode.add(new String[] { getConnectionName() + " - " + node.getId() }); } // } // catch (SolrServerException e) // { // log.error(e.getMessage(), e); // discardedNode.add(new String[] { getConnectionName() + " - " + node.getId()}); // continue committnode; // } // catch (IOException e) // { // log.error(e.getMessage(), e); // discardedNode.add(new String[] { getConnectionName() + " - " + node.getId()}); // continue committnode; // } } log.debug("commit " + getType()); getIndexer().getIndexer().commit(); return result; }
From source file:org.dspace.app.cris.network.AVisualizationGraphModeFour.java
@Override public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes, Boolean otherError) throws Exception { // load all publications SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(getQuery());// ww w. j ava 2 s. co m solrQuery.addFacetField(getFacetFieldQuery()); // solrQuery.addFilterQuery("authors_fauthority:rp00001"); solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setFacetMinCount(1); solrQuery.setRows(0); QueryResponse rsp = getService().getSearcher().search(solrQuery); FacetField facets = rsp.getFacetField(getFacetFieldQuery()); System.out.println(facets.getValueCount()); // for each interests get authority's authors List<VisualizationGraphNode> result = null; int counter = 0; external: for (Count facetElement : facets.getValues()) { counter++; log.debug(getConnectionName() + " - " + counter + " of " + facets.getValueCount()); System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount()); result = new LinkedList<VisualizationGraphNode>(); try { String facetValue = facetElement.getName(); List<String> relations = getValues(facetValue); int i = 0; internal: for (String relation : relations) { log.debug("" + counter + " works on " + i + " of " + relations.size()); System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount() + " works on " + i + " of " + relations.size()); String aaa = relation; String[] split = aaa.split("\\|\\|\\|"); String a = aaa; String a_authority = null; String a_dept = null; String a_displayValue = ""; if (split.length > 1) { String[] splitAuthority = split[1].split(splitterAuthority); a_displayValue = splitAuthority[0]; if (splitAuthority.length > 1) { a_authority = splitAuthority[1]; // a_dept = ResearcherPageUtils // .getDepartment(a_authority); a_dept = getDepartmentFromSOLR(a_authority); } } internalprivate: for (int j = i; j < relations.size(); j++) { List<String> values = new LinkedList<String>(); values.add(facetValue); String bbb = relations.get(j); split = bbb.split("\\|\\|\\|"); String b = bbb; String b_authority = null; String b_dept = null; String b_displayValue = ""; if (split.length > 1) { String[] splitAuthority = split[1].split(splitterAuthority); b_displayValue = splitAuthority[0]; if (splitAuthority.length > 1) { b_authority = splitAuthority[1]; // a_dept = ResearcherPageUtils // .getDepartment(a_authority); b_dept = getDepartmentFromSOLR(b_authority); } } if (j == i) { buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue, values, buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_PLACEHOLDER_RP); } else { if (!a.equals(b)) { buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue, values, buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_RP); } } } i++; } } catch (Exception e) { log.error("Error try to build object to index with ID:" + ""); log.error(e.getMessage(), e); otherError = true; continue; } importedNodes = indexNode(discardedNode, importedNodes, result); } log.debug("commit " + getType()); getIndexer().commit(); return result; }
From source file:org.dspace.app.cris.network.AVisualizationGraphModeTwo.java
@Override public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes, Boolean otherError) throws Exception { // load all publications SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(getQuery());/* ww w . j a v a 2 s . co m*/ solrQuery.addFacetField(getFacetFieldQuery()); // solrQuery.addFilterQuery("authors_fauthority:rp00001"); solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setFacetMinCount(1); solrQuery.setRows(0); QueryResponse rsp = getService().getSearcher().search(solrQuery); FacetField facets = rsp.getFacetField(getFacetFieldQuery()); System.out.println(facets.getValueCount()); // for each interests get authority's authors List<VisualizationGraphNode> result = null; int counter = 0; external: for (Count facetElement : facets.getValues()) { counter++; log.debug(getConnectionName() + " - " + counter + " of " + facets.getValueCount()); System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount()); result = new LinkedList<VisualizationGraphNode>(); try { String facetValue = facetElement.getName(); solrQuery = new SolrQuery(); String query = (useJoin() ? getJoin() : "") + getFacetFieldQuery() + ":\"" + ClientUtils.escapeQueryChars(facetValue) + "\""; solrQuery.setQuery(query); solrQuery.addFacetField(getFacet(facetValue)); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit(getFacetLimit()); solrQuery.setRows(0); rsp = getService().getSearcher().search(solrQuery); FacetField relations = rsp.getFacetField(getFacet(facetValue)); int i = 0; internal: for (Count relation : relations.getValues()) { log.debug("" + counter + " works on " + i + " of " + relations.getValueCount()); System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount() + " works on " + i + " of " + relations.getValueCount()); String aaa = relation.getName(); String[] split = aaa.split("\\|\\|\\|"); String a = aaa; String a_authority = null; String a_dept = null; String a_displayValue = ""; if (split.length > 1) { String[] splitAuthority = split[1].split(splitterAuthority); a_displayValue = splitAuthority[0]; if (splitAuthority.length > 1) { a_authority = splitAuthority[1]; // a_dept = ResearcherPageUtils // .getDepartment(a_authority); a_dept = getDepartmentFromSOLR(a_authority); } } internalprivate: for (int j = i; j < relations.getValues().size(); j++) { List<String> values = new LinkedList<String>(); values.add(facetValue); String bbb = relations.getValues().get(j).getName(); split = bbb.split("\\|\\|\\|"); String b = bbb; String b_authority = null; String b_dept = null; String b_displayValue = ""; if (split.length > 1) { String[] splitAuthority = split[1].split(splitterAuthority); b_displayValue = splitAuthority[0]; if (splitAuthority.length > 1) { b_authority = splitAuthority[1]; // a_dept = ResearcherPageUtils // .getDepartment(a_authority); b_dept = getDepartmentFromSOLR(b_authority); } } if (j == i) { buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue, values, buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_PLACEHOLDER_RP); } else { if (!a.equals(b)) { buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue, values, buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_RP); } } } i++; } } catch (Exception e) { log.error("Error try to build object to index with ID:" + ""); log.error(e.getMessage(), e); otherError = true; continue; } importedNodes = indexNode(discardedNode, importedNodes, result); } log.debug("commit " + getType()); getIndexer().commit(); return result; }
From source file:org.dspace.app.cris.network.DepartmentNetworkPlugin.java
public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes, Boolean otherError, List<String> connections) throws Exception { for (String connection : connections) { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("type:" + connection); solrQuery.addFacetField(FACET); solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setFacetMinCount(1);/*from w w w . j a va 2 s . c om*/ solrQuery.setRows(0); QueryResponse rsp = service.search(solrQuery); FacetField facets = rsp.getFacetField(FACET); // for each interests get authority's authors List<VisualizationGraphNode> result = null; int counter = 0; external: for (Count facetElement : facets.getValues()) { counter++; log.debug("" + counter + " of " + facets.getValueCount()); result = new LinkedList<VisualizationGraphNode>(); try { String facetValue = facetElement.getName(); String[] splittedFacetValue = facetValue.split("\\|\\|\\|"); if (!splittedFacetValue[0].equals("null") && splittedFacetValue[0].equals(splittedFacetValue[1])) { SolrQuery solrQuery2 = new SolrQuery(); solrQuery2.setQuery("type:" + connection + " AND " + FACET + ":\"" + ClientUtils.escapeQueryChars(facetValue) + "\" AND a_auth:[* TO *] AND b_auth:[* TO *]"); solrQuery2.addFacetField(FACET_AUTHOR); solrQuery2.setFacetMinCount(1); solrQuery2.setFacetLimit(Integer.MAX_VALUE); solrQuery2.setRows(0); QueryResponse rsp2 = service.search(solrQuery2); FacetField relations = rsp2.getFacetField(FACET_AUTHOR); int i = 0; internal: for (Count relation : relations.getValues()) { log.debug("" + counter + " works on " + i + " of " + relations.getValueCount()); List<String> values = new LinkedList<String>(); values.add(splittedFacetValue[0]); String aaa = relation.getName(); String[] split = aaa.split("\\|\\|\\|"); String a = aaa; String a_authority = null; String a_displayValue = ""; if (split.length > 1) { a_displayValue = split[1]; } if (split.length > 2) { a_authority = split[2]; } buildRow(result, splittedFacetValue[0], null, splittedFacetValue[1], a, a_authority, a_displayValue, values, buildExtra(splittedFacetValue[0]), connection); i++; } importedNodes = importNode(discardedNode, importedNodes, result); log.debug("commit DEPARTMENT " + facetValue); indexer.getSolr().commit(); } } catch (Exception e) { log.error("Error try to build object to index with ID:" + ""); log.error(e.getMessage(), e); otherError = true; continue; } } } return null; }
From source file:org.dspace.app.webui.cris.components.statistics.StatSelectedObjectComponent.java
@Override public TreeKeyMap query(String id, HttpSolrServer solrServer) throws Exception { statisticDatasBeans = new TreeKeyMap(); if (id != null && !id.equals("") && StatComponentsService.getYearsQuery() != null) { solrServer.setMaxRetries(0);/*from w w w . ja v a2 s .co m*/ SolrQuery solrQuery = new SolrQuery(); _prepareBasicQuery(solrQuery, StatComponentsService.getYearsQuery()); if (StatComponentsService.isExcludeBot()) { solrQuery.addFilterQuery("-isBot:true"); } Integer relationType = getRelationObjectType(); if (relationType == null) { relationType = CrisConstants.getEntityType(getRelationObjectClass().newInstance()); } solrQuery.addFilterQuery("type:" + relationType); String query = STATS_QUERY; if (getBean() != null) { String beanQuery = getBean().getQuery(); query += (beanQuery != null && !beanQuery.isEmpty()) ? beanQuery : ""; for (String filter : getBean().getFilters()) { solrQuery.addFilterQuery(filter); } } solrQuery.setQuery(MessageFormat.format(query, id)); if (getBean() instanceof BeanFacetComponent) { BeanFacetComponent beanFacet = (BeanFacetComponent) getBean(); solrQuery.setFacet(true); solrQuery.addFacetQuery(beanFacet.getFacetQuery()); solrQuery.addFacetField(beanFacet.getFacetField()); } solrResponse = solrServer.query(solrQuery); buildPageResultModules(StatComponentsService._SELECTED_OBJECT); } else { throw new Exception("Item Id not valid"); } return statisticDatasBeans; }
From source file:org.dspace.app.webui.cris.components.statistics.StatTopObjectComponent.java
@Override public TreeKeyMap query(String id, HttpSolrServer solrServer) throws Exception { statisticDatasBeans = new TreeKeyMap(); if (id != null && !id.equals("") && StatComponentsService.getYearsQuery() != null) { // HttpSolrServer solrServer = new HttpSolrServer( // solrConfig.getUrl()+solrCore); solrServer.setMaxRetries(0);//from w w w. java2 s.com SolrQuery solrQuery = new SolrQuery(); // http://localhost:8983/solr/statistics/select/?q=type%3A2&rows=20&facet=true&facet.date=time&facet.date.start=2008-07-00T00:00:00.000Z&facet.date.end=2009-06-31T00:00:00.000Z&facet.date.gap=%2B1MONTHS&facet.field=id _prepareBasicQuery(solrQuery, StatComponentsService.getYearsQuery()); // _prepareTopQuery(type, id, fieldName, solrQuery); if (StatComponentsService.isExcludeBot()) { solrQuery.addFilterQuery("-isBot:true"); } Integer relationType = getRelationObjectType(); if (relationType == null) { relationType = CrisConstants.getEntityType(getRelationObjectClass().newInstance()); } solrQuery.addFilterQuery("type:" + relationType); for (String filter : getBean().getFilters()) { solrQuery.addFilterQuery(filter); } String query = MessageFormat.format(QUERY_COMMON, getFromField(), getBean().getQuery()); String sID = getObjectId(id); query = MessageFormat.format(query, sID); solrQuery.setQuery(query); if (getBean() instanceof BeanFacetComponent) { BeanFacetComponent beanFacet = (BeanFacetComponent) getBean(); solrQuery.setFacet(true); solrQuery.addFacetQuery(beanFacet.getFacetQuery()); solrQuery.addFacetField(beanFacet.getFacetField()); } solrResponse = solrServer.query(solrQuery); if (!getBean().getSubQueries().isEmpty()) { statisticDatasBeans.addValue(TOP, CrisConstants.getEntityTypeText(relationType), CATEGORY, generateCategoryView(solrServer, TOP, relationType.toString(), CATEGORY, StatComponentsService.getTopCityLength(), query, getBean().getSubQueries(), sID)); } buildTopResultModules(relationType); } else { throw new Exception("Object Id not valid"); } return statisticDatasBeans; }
From source file:org.dspace.app.webui.cris.controller.PJSearchFormController.java
@Override protected Map referenceData(HttpServletRequest request) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); Context context = UIUtil.obtainContext(request); EPerson currUser = context.getCurrentUser(); boolean isAdmin = AuthorizeManager.isAdmin(context); if (currUser != null) { model.put("researcher_page_menu", new Boolean(true)); }/*from w ww.j a v a 2 s .c o m*/ if (isAdmin) { model.put("see_search_grantcode", new Boolean(true)); } SolrQuery query = new SolrQuery(); query.setQuery("disabled:false"); query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(1); query.setFacetMissing(true); query.setFacetSort(FacetParams.FACET_SORT_INDEX); // check table name query.addFacetField("pjsponsor_filter"); query.addFacetField("pjstatus_filter"); query.setRows(0); QueryResponse qResponse = ((CrisSearchService) searchService).search(query); FacetField facetField = qResponse.getFacetField("pjsponsor_filter"); List<DiscoverResult.FacetResult> sponsors = new ArrayList<DiscoverResult.FacetResult>(); List<Count> values = facetField.getValues(); if (values != null) { for (FacetField.Count facetValue : values) { DiscoverResult.FacetResult fr = searchService.getDiscoveryFacet(context, facetField, facetValue); sponsors.add(fr); } } FacetField facetFieldStatus = qResponse.getFacetField("pjstatus_filter"); List<DiscoverResult.FacetResult> status = new ArrayList<DiscoverResult.FacetResult>(); List<Count> valuesStatus = facetFieldStatus.getValues(); if (valuesStatus != null) { for (FacetField.Count facetValue : valuesStatus) { DiscoverResult.FacetResult fr = searchService.getDiscoveryFacet(context, facetFieldStatus, facetValue); status.add(fr); } } DiscoveryConfiguration discoveryConf = SearchUtils.getDiscoveryConfigurationByName("crisproject"); List<String> searchFields = new LinkedList<String>(); for (DiscoverySearchFilter field : discoveryConf.getSearchFilters()) { searchFields.add(field.getIndexFieldName()); } model.put("state", status); model.put("sponsors", sponsors); model.put("fields", searchFields); return model; }
From source file:org.dspace.app.webui.cris.controller.RPSearchFormController.java
@Override protected Map referenceData(HttpServletRequest request) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); Context context = UIUtil.obtainContext(request); EPerson currUser = context.getCurrentUser(); boolean isAdmin = AuthorizeManager.isAdmin(context); if (currUser != null) { model.put("researcher_page_menu", new Boolean(true)); }/*from w w w . j a v a 2s .c om*/ if (isAdmin) { model.put("see_search_staffno", new Boolean(true)); model.put("see_search_rp", new Boolean(true));// not used on jsp // (now search for // RP // is public) } SolrQuery query = new SolrQuery(); query.setQuery("disabled:false"); query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(1); query.setFacetMissing(true); query.setFacetSort(FacetParams.FACET_SORT_INDEX); // check table name query.addFacetField("faculty_filter"); query.setRows(0); QueryResponse qResponse = ((CrisSearchService) searchService).search(query); FacetField facetField = qResponse.getFacetField("faculty_filter"); List<DiscoverResult.FacetResult> faculties = new ArrayList<DiscoverResult.FacetResult>(); List<Count> values = facetField.getValues(); if (values != null) { for (FacetField.Count facetValue : values) { DiscoverResult.FacetResult fr = searchService.getDiscoveryFacet(context, facetField, facetValue); faculties.add(fr); } } DiscoveryConfiguration discoveryConf = SearchUtils.getDiscoveryConfigurationByName("crisrp"); List<String> searchFields = new LinkedList<String>(); for (DiscoverySearchFilter field : discoveryConf.getSearchFilters()) { searchFields.add(field.getIndexFieldName()); } model.put("faculties", faculties); model.put("fields", searchFields); return model; }
From source file:org.dspace.app.webui.cris.servlet.DeptNetworkServlet.java
private QueryResponse shootQuery(String query, boolean facet, String facetField) throws SearchServiceException { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query);/*from ww w .j a v a2 s . co m*/ solrQuery.setStart(0); solrQuery.setRows(0); if (facet) { solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.addFacetField(facetField); } QueryResponse rsp = service.search(solrQuery); return rsp; }