List of usage examples for org.apache.solr.client.solrj SolrQuery setRows
public SolrQuery setRows(Integer rows)
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);/* ww w. java 2 s. co m*/ solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setFacetMinCount(1); 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.cris.statistics.CrisSolrLogger.java
@Override public SolrDocumentList getRawData(int type) throws SolrServerException { if (type >= CrisConstants.CRIS_TYPE_ID_START) { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setFilterQueries("type:" + type); query.setRows(Integer.MAX_VALUE); query.setFields("ip", "id", "sectionid", "type", "time", "dns", "epersonid", "isBot", "userAgent"); QueryResponse resp = getSolr().query(query); return resp.getResults(); } else {//from www. j av a2 s. c o m return super.getRawData(type); } }
From source file:org.dspace.app.cris.ws.AWSServices.java
private SolrQuery buildQuery(String query, String start, String limit, User userWS, String type, String... projection) {/*from w w w .j av a2 s .co m*/ SolrQuery solrQuery = new SolrQuery(); int resource_type = getSupportedType(); solrQuery.setQuery(query); solrQuery.setStart(Integer.parseInt(start)); solrQuery.setRows(Integer.parseInt(limit)); internalBuildFieldList(solrQuery, projection); solrQuery.addFilterQuery("search.resourcetype:" + resource_type); for (Criteria criteria : userWS.getCriteria()) { if (type.equals(criteria.getCriteria())) { // parse criteria follow solr form: // "fq=type:bllababl&fq=text:balglballlbab" List<String> result = new ArrayList<String>(); if (criteria.getFilter() != null && !criteria.getFilter().isEmpty()) { // Split String[] fqs = criteria.getFilter().split("&"); for (String fq : fqs) { // remove prefix String newfq = fq.replaceFirst("fq=", ""); result.add(newfq); // add to tmp list } // add fq solrQuery.addFilterQuery(result.toArray(new String[result.size()])); } } } return solrQuery; }
From source file:org.dspace.app.webui.cris.components.statistics.ASolrStatsConfigurerComponent.java
protected void _addBasicConfiguration(SolrQuery solrQuery, Integer yearsQuery) { solrQuery.setRows(0); solrQuery.setFacet(true);/*from w w w .j a v a 2 s . c o m*/ solrQuery.set("facet.date", "time"); solrQuery.set("facet.date.end", "NOW/MONTH+1MONTH"); solrQuery.set("facet.date.start", "NOW/MONTH-" + yearsQuery + "YEARS"); solrQuery.set("facet.date.include", "upper"); solrQuery.set("facet.date.gap", "+1MONTHS"); // solrQuery.set("facet.mincount", "1"); }
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)); }// www. j a v a 2s. c om 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 2 s .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.DeptMetricsNetworkServlet.java
@Override protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { String dept = request.getParameter("dept"); boolean found = false; if (dept == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "A department name could be passed as parameter"); } else {/*from ww w . j a v a 2s. c o m*/ found = true; } // load all publications SolrQuery solrQuery = new SolrQuery(); List<DTOMetric> results = new ArrayList<DTOMetric>(); String connection = ConfigurationManager.getProperty(NetworkPlugin.CFG_MODULE, "network.connection"); String[] connections = connection.split(","); List<String> fieldsToRetrieve = new ArrayList<String>(); fieldsToRetrieve.add("search.resourceid"); fieldsToRetrieve.add("rp_fullname"); for (String conn : connections) { fieldsToRetrieve.add(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1_RETRIEVE + conn); fieldsToRetrieve.add(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2_RETRIEVE + conn); fieldsToRetrieve.add(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3_RETRIEVE + conn); fieldsToRetrieve.add(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_4_RETRIEVE + conn); } String[] fields = fieldsToRetrieve.toArray(new String[] {}); QueryResponse rsp; try { solrQuery = new SolrQuery(); solrQuery.setQuery("search.resourcetype:" + CrisConstants.RP_TYPE_ID + " AND rp_dept:\"" + dept + "\""); solrQuery.setFields(fields); solrQuery.setRows(Integer.MAX_VALUE); rsp = getService().getSearcher().search(solrQuery); SolrDocumentList rows = rsp.getResults(); external: for (String conn : connections) { Iterator<SolrDocument> iter = rows.iterator(); internal: while (iter.hasNext()) { DTOMetric metric = new DTOMetric(); SolrDocument publication = iter.next(); Integer rp_id = (Integer) publication.getFirstValue("search.resourceid"); String rp_fullname = (String) publication.getFirstValue("rp_fullname"); String averageStrength = (String) publication .getFirstValue(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3_RETRIEVE + conn); String maxStrength = (String) publication .getFirstValue(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2_RETRIEVE + conn); String numbersConnections = (String) publication .getFirstValue(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1_RETRIEVE + conn); String quadraticVariance = (String) publication .getFirstValue(ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_4_RETRIEVE + conn); metric.setAuthority(ResearcherPageUtils.getPersistentIdentifier(rp_id, ResearcherPage.class)); metric.setFullName(rp_fullname); metric.setType(conn); metric.setAverageStrength(averageStrength); metric.setMaxStrength(maxStrength); metric.setNumbersConnections(numbersConnections); metric.setQuadraticVariance(quadraticVariance); if ((averageStrength == null || averageStrength.isEmpty()) && (maxStrength == null || maxStrength.isEmpty()) && (numbersConnections == null || numbersConnections.isEmpty()) && (quadraticVariance == null || quadraticVariance.isEmpty())) { //do not show anythings } else { results.add(metric); } } } } catch (SearchServiceException e) { log.error(e.getMessage(), new ServletException(e)); } request.setAttribute("dept", dept); request.setAttribute("metrics", results); JSPManager.showJSP(request, response, "/graph/dmetrics.jsp"); }
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);/*w ww . j av a 2 s . c om*/ solrQuery.setStart(0); solrQuery.setRows(0); if (facet) { solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.addFacetField(facetField); } QueryResponse rsp = service.search(solrQuery); return rsp; }
From source file:org.dspace.app.webui.cris.servlet.ProfileResearcherNetworkServlet.java
public Map<String, Integer> getRelations(String from, String to) throws SearchServiceException { Map<String, Integer> result = new HashMap<String, Integer>(); SolrQuery solrQuery = new SolrQuery(); Matcher matcher = patternRP.matcher(from); String field1 = ""; String field2 = ""; if (matcher.find()) { field1 = "focus_auth"; } else {// w w w .ja v a 2 s .c om field1 = "focus_val"; } matcher = patternRP.matcher(to); if (matcher.find()) { field2 = "focus_auth"; } else { field2 = "focus_val"; } solrQuery.setQuery( field1 + ":\"" + from + "\" AND " + field2 + ":\"" + to + "\"" ); solrQuery.setFacet(true); solrQuery.addFacetField("type"); solrQuery.setFacetLimit(Integer.MAX_VALUE); solrQuery.setFacetMinCount(1); solrQuery.setRows(0); QueryResponse rsp = service.search(solrQuery); FacetField facets = rsp.getFacetField("type"); for (Count facet : facets.getValues()) { result.put(facet.getName(), Integer.valueOf((int) facet.getCount())); } return result; }
From source file:org.dspace.app.webui.cris.servlet.RelationsResearcherNetworkServlet.java
public MultiValueMap getRelationsInformation(String type, String from, String to) throws SearchServiceException { MultiValueMap result = new MultiValueMap(); SolrQuery solrQuery = new SolrQuery(); Matcher matcher = patternRP.matcher(from); String field1 = ""; String field2 = ""; if (matcher.find()) { field1 = "focus_auth"; } else {//from ww w . j a v a 2 s .c o m field1 = "focus_val"; } matcher = patternRP.matcher(to); if (matcher.find()) { field2 = "focus_auth"; } else { field2 = "focus_val"; } solrQuery.setQuery(field1 + ":\"" + from + "\" AND " + field2 + ":\"" + to + "\""); solrQuery.addFilterQuery("type:" + type); solrQuery.setRows(Integer.MAX_VALUE); QueryResponse rsp = service.search(solrQuery); for (SolrDocument doc : rsp.getResults()) { String resultField = ""; if (doc.getFieldValue("value") instanceof String) { resultField = (String) doc.getFieldValue("value"); } else { for (String ss : (List<String>) doc.getFieldValue("value")) { resultField += ss; } } String resultFieldExtra = ""; if (doc.getFieldValue("extra") != null) { if (doc.getFieldValue("extra") instanceof String) { resultFieldExtra = (String) doc.getFieldValue("extra"); } else { for (String ss : (List<String>) doc.getFieldValue("extra")) { resultFieldExtra += ss; } } } result.put(resultField, resultFieldExtra); } return result; }