List of usage examples for org.apache.solr.client.solrj SolrQuery setFacetLimit
public SolrQuery setFacetLimit(int lim)
From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java
License:Apache License
public QueryResponse getSolrDocs(String solrServer, String solrCoreName, String uniqueKey, List<String> fields, Long solrDocFectCount, String cursorMark, StringBuilder filters, List<SolrAggrParam> solrAggrParams, List<SolrSortParam> solrSortParams, List<String> aggrFieldNames, boolean isGroup, boolean isCountOnlyQuery) { String solrUrl = solrServer;/*from ww w .j a va 2 s .c om*/ if (solrCoreName != null) { solrUrl = solrServer + solrCoreName; } SolrClient solrClient = new HttpSolrClient(solrUrl); String fieldStr = null; String[] fieldListArr = null; List<String> statsFieldList = Lists.newArrayList(); SolrQuery solrQuery = new SolrQuery().setQuery("{!cache=false}" + uniqueKey + ":*").setRows(0); if (filters.length() > 0) { solrQuery.setParam("fq", filters.toString()); SolrClientAPIExec.logger.debug("Filter query [ " + filters.toString() + " ]"); } if (!fields.isEmpty()) { fieldStr = Joiner.on(",").join(fields); solrQuery.setParam("fl", fieldStr); solrQuery.setRows(solrDocFectCount.intValue()); SolrClientAPIExec.logger.debug("Response field list [" + fieldStr + "]"); } if (solrAggrParams != null && !solrAggrParams.isEmpty() && !isCountOnlyQuery) { solrQuery.setGetFieldStatistics(true); String referenceToStatsTag = "{!stats=t1}"; String statsTag = "{!tag=t1}"; for (SolrAggrParam solrAggrParam : solrAggrParams) { String statsField = solrAggrParam.getFieldName(); if (!fields.contains(statsField)) { statsField = uniqueKey; } if (!statsFieldList.contains(statsField)) { statsFieldList.add(statsField); } fields.remove(statsField); } if (!fields.isEmpty()) { fieldListArr = fields.toArray(new String[fields.size()]); } SolrClientAPIExec.logger.debug("Adding stats field parameter.." + statsFieldList + ""); if (isGroup) { List<String> groupFields = Lists.newArrayList(); solrQuery.addGetFieldStatistics(statsTag + Joiner.on(",").join(statsFieldList)); for (String aggrField : fields) { if (fields.contains(aggrField)) { groupFields.add(aggrField); } } if (groupFields.size() == 1) { SolrClientAPIExec.logger.debug("Adding stats facet parameters.." + groupFields + ""); for (String statsField : statsFieldList) { solrQuery.addStatsFieldFacets(statsField, groupFields.toArray(new String[groupFields.size()])); } } else { SolrClientAPIExec.logger.debug("Adding facet pivot parameters.." + groupFields + ""); solrQuery.addFacetPivotField(referenceToStatsTag + Joiner.on(",").join(groupFields)); solrQuery.setFacetLimit(-1); } } else { for (String statsField : statsFieldList) { solrQuery.setGetFieldStatistics(statsField); } } solrQuery.setRows(0); } else if (isGroup) { fieldListArr = fields.toArray(new String[fields.size()]); solrQuery.setFacet(true); if (fields.size() == 1) { solrQuery.addFacetField(fieldListArr); solrQuery.setFacetLimit(-1); } else { solrQuery.addFacetPivotField(Joiner.on(",").join(fields)); } solrQuery.setRows(0); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit(-1); } else { solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); solrQuery.addSort(SolrQuery.SortClause.desc(uniqueKey)); } if (!solrSortParams.isEmpty()) { for (SolrSortParam solrSortParam : solrSortParams) { String solrSortField = solrSortParam.getSortFieldName(); ORDER solrSortDir = solrSortParam.getSortDir(); solrQuery.addSort(solrSortField, solrSortDir); } } QueryResponse rsp = null; try { SolrClientAPIExec.logger.info("Submitting Query :" + solrUrl + "/select" + solrQuery.toQueryString()); rsp = solrClient.query(solrQuery); SolrClientAPIExec.logger.info("Response recieved from [ " + solrServer + " ] core [ " + solrCoreName + " ] in " + rsp.getQTime() + " MS."); } catch (SolrServerException | IOException e) { SolrClientAPIExec.logger .debug("Error occured while fetching results from solr server " + e.getMessage()); } finally { try { solrClient.close(); } catch (IOException e) { SolrClientAPIExec.logger .debug("Error occured while closing connection of solr server " + e.getMessage()); } } return rsp; }
From source file:org.apache.ofbiz.solr.SolrProductSearch.java
License:Apache License
/** * Runs a query on the Solr Search Engine and returns the results. * <p>// www .ja va 2s.c o m * This function only returns an object of type QueryResponse, so it is probably not a good idea to call it directly from within the * groovy files (As a decent example on how to use it, however, use keywordSearch instead). */ public static Map<String, Object> runSolrQuery(DispatchContext dctx, Map<String, Object> context) { // get Connection HttpSolrClient client = null; String solrIndexName = (String) context.get("indexName"); Map<String, Object> result; try { client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName); // create Query Object SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery((String) context.get("query")); // solrQuery.setQueryType("dismax"); boolean faceted = (Boolean) context.get("facet"); if (faceted) { solrQuery.setFacet(faceted); solrQuery.addFacetField("manu"); solrQuery.addFacetField("cat"); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit(8); solrQuery.addFacetQuery("listPrice:[0 TO 50]"); solrQuery.addFacetQuery("listPrice:[50 TO 100]"); solrQuery.addFacetQuery("listPrice:[100 TO 250]"); solrQuery.addFacetQuery("listPrice:[250 TO 500]"); solrQuery.addFacetQuery("listPrice:[500 TO 1000]"); solrQuery.addFacetQuery("listPrice:[1000 TO 2500]"); solrQuery.addFacetQuery("listPrice:[2500 TO 5000]"); solrQuery.addFacetQuery("listPrice:[5000 TO 10000]"); solrQuery.addFacetQuery("listPrice:[10000 TO 50000]"); solrQuery.addFacetQuery("listPrice:[50000 TO *]"); } boolean spellCheck = (Boolean) context.get("spellcheck"); if (spellCheck) { solrQuery.setParam("spellcheck", spellCheck); } boolean highLight = (Boolean) context.get("highlight"); if (highLight) { solrQuery.setHighlight(highLight); solrQuery.setHighlightSimplePre("<span class=\"highlight\">"); solrQuery.addHighlightField("description"); solrQuery.setHighlightSimplePost("</span>"); solrQuery.setHighlightSnippets(2); } // Set additional Parameter // SolrQuery.ORDER order = SolrQuery.ORDER.desc; if (context.get("viewIndex") != null && (Integer) context.get("viewIndex") > 0) { solrQuery.setStart((Integer) context.get("viewIndex")); } if (context.get("viewSize") != null && (Integer) context.get("viewSize") > 0) { solrQuery.setRows((Integer) context.get("viewSize")); } // if ((List) context.get("queryFilter") != null && ((ArrayList<SolrDocument>) context.get("queryFilter")).size() > 0) { // List filter = (List) context.get("queryFilter"); // String[] tn = new String[filter.size()]; // Iterator it = filter.iterator(); // for (int i = 0; i < filter.size(); i++) { // tn[i] = (String) filter.get(i); // } // solrQuery.setFilterQueries(tn); // } String queryFilter = (String) context.get("queryFilter"); if (UtilValidate.isNotEmpty(queryFilter)) solrQuery.setFilterQueries(queryFilter.split(" ")); if ((String) context.get("returnFields") != null) { solrQuery.setFields((String) context.get("returnFields")); } // if((Boolean)context.get("sortByReverse"))order.reverse(); if ((String) context.get("sortBy") != null && ((String) context.get("sortBy")).length() > 0) { SolrQuery.ORDER order; if (!((Boolean) context.get("sortByReverse"))) order = SolrQuery.ORDER.asc; else order = SolrQuery.ORDER.desc; solrQuery.setSort(((String) context.get("sortBy")).replaceFirst("-", ""), order); } if ((String) context.get("facetQuery") != null) { solrQuery.addFacetQuery((String) context.get("facetQuery")); } QueryResponse rsp = client.query(solrQuery); result = ServiceUtil.returnSuccess(); result.put("queryResult", rsp); } catch (Exception e) { Debug.logError(e, e.getMessage(), module); result = ServiceUtil.returnError(e.toString()); } finally { if (client != null) { try { client.close(); } catch (IOException e) { // do nothing } } } return result; }
From source file:org.apache.ofbiz.solr.SolrUtil.java
License:Apache License
public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, String facetPrefix, boolean displayproducts, int viewIndex, int viewSize, String solrIndexName) { // create the data model Map<String, Object> result = new HashMap<String, Object>(); HttpSolrClient client = null;/* www . j av a 2 s . c o m*/ QueryResponse returnMap = new QueryResponse(); try { // do the basic query client = getHttpSolrClient(solrIndexName); // create Query Object String query = "inStock[1 TO *]"; if (categoryId != null) query += " +cat:" + categoryId; else if (productId != null) query += " +productId:" + productId; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query); if (catalogId != null) solrQuery.setFilterQueries("catalog:" + catalogId); if (displayproducts) { if (viewSize > -1) { solrQuery.setRows(viewSize); } else solrQuery.setRows(50000); if (viewIndex > -1) { solrQuery.setStart(viewIndex); } } else { solrQuery.setFields("cat"); solrQuery.setRows(0); } if (UtilValidate.isNotEmpty(facetPrefix)) { solrQuery.setFacetPrefix(facetPrefix); } solrQuery.setFacetMinCount(0); solrQuery.setFacet(true); solrQuery.addFacetField("cat"); solrQuery.setFacetLimit(-1); Debug.logVerbose("solr: solrQuery: " + solrQuery, module); returnMap = client.query(solrQuery, METHOD.POST); result.put("rows", returnMap); result.put("numFound", returnMap.getResults().getNumFound()); } catch (Exception e) { Debug.logError(e.getMessage(), module); } return result; }
From source file:org.codelibs.fess.service.SearchService.java
License:Apache License
public List<Map<String, Object>> getDocumentList(final String query, final int start, final int rows, final FacetInfo facetInfo, final GeoInfo geoInfo, final MoreLikeThisInfo mltInfo, final String[] responseFields, final String[] docValuesFields, final boolean forUser) { if (start > queryHelper.getMaxSearchResultOffset()) { throw new ResultOffsetExceededException("The number of result size is exceeded."); }/*from w w w .j a v a2s . c o m*/ final long startTime = System.currentTimeMillis(); final SolrGroup solrGroup = solrGroupManager.getSolrGroup(QueryType.QUERY); QueryResponse queryResponse = null; final SolrQuery solrQuery = new SolrQuery(); final SearchQuery searchQuery = queryHelper.build(query, forUser); final String q = searchQuery.getQuery(); if (StringUtil.isNotBlank(q)) { // fields solrQuery.setFields(responseFields); // query solrQuery.setQuery(q); solrQuery.setStart(start); solrQuery.setRows(rows); solrQuery.set("mm", searchQuery.getMinimumShouldMatch()); solrQuery.set("defType", searchQuery.getDefType()); for (final Map.Entry<String, String[]> entry : queryHelper.getQueryParamMap().entrySet()) { solrQuery.set(entry.getKey(), entry.getValue()); } // filter query if (searchQuery.hasFilterQueries()) { solrQuery.addFilterQuery(searchQuery.getFilterQueries()); } // sort final SortField[] sortFields = searchQuery.getSortFields(); if (sortFields.length != 0) { for (final SortField sortField : sortFields) { solrQuery.addSort(sortField.getField(), Constants.DESC.equals(sortField.getOrder()) ? SolrQuery.ORDER.desc : SolrQuery.ORDER.asc); } } else if (queryHelper.hasDefaultSortFields()) { for (final SortField sortField : queryHelper.getDefaultSortFields()) { solrQuery.addSort(sortField.getField(), Constants.DESC.equals(sortField.getOrder()) ? SolrQuery.ORDER.desc : SolrQuery.ORDER.asc); } } // highlighting if (queryHelper.getHighlightingFields() != null && queryHelper.getHighlightingFields().length != 0) { for (final String hf : queryHelper.getHighlightingFields()) { solrQuery.addHighlightField(hf); } solrQuery.setHighlightSnippets(queryHelper.getHighlightSnippetSize()); } // shards if (queryHelper.getShards() != null) { solrQuery.setParam("shards", queryHelper.getShards()); } // geo if (geoInfo != null && geoInfo.isAvailable()) { solrQuery.addFilterQuery(geoInfo.toGeoQueryString()); final String additionalGeoQuery = queryHelper.getAdditionalGeoQuery(); if (StringUtil.isNotBlank(additionalGeoQuery)) { solrQuery.addFilterQuery(additionalGeoQuery); } } // facets if (facetInfo != null) { solrQuery.setFacet(true); if (facetInfo.field != null) { for (final String f : facetInfo.field) { if (queryHelper.isFacetField(f)) { solrQuery.addFacetField(f); } else { throw new FessSolrQueryException("EFESS0002", new Object[] { f }); } } } if (facetInfo.query != null) { for (final String fq : facetInfo.query) { final String facetQuery = queryHelper.buildFacetQuery(fq); if (StringUtil.isNotBlank(facetQuery)) { solrQuery.addFacetQuery(facetQuery); } else { throw new FessSolrQueryException("EFESS0003", new Object[] { fq, facetQuery }); } } } if (facetInfo.limit != null) { solrQuery.setFacetLimit(Integer.parseInt(facetInfo.limit)); } if (facetInfo.minCount != null) { solrQuery.setFacetMinCount(Integer.parseInt(facetInfo.minCount)); } if (facetInfo.missing != null) { solrQuery.setFacetMissing(Boolean.parseBoolean(facetInfo.missing)); } if (facetInfo.prefix != null) { solrQuery.setFacetPrefix(facetInfo.prefix); } if (facetInfo.sort != null && queryHelper.isFacetSortValue(facetInfo.sort)) { solrQuery.setFacetSort(facetInfo.sort); } } // mlt if (mltInfo != null) { final String mltField = queryHelper.getMoreLikeThisField(mltInfo.field); if (mltField != null) { solrQuery.set("mlt", true); if (mltInfo.count != null) { solrQuery.set("mlt.count", Integer.parseInt(mltInfo.count)); } solrQuery.set("mlt.fl", mltField); } } if (queryHelper.getTimeAllowed() >= 0) { solrQuery.setTimeAllowed(queryHelper.getTimeAllowed()); } final Set<Entry<String, String[]>> paramSet = queryHelper.getRequestParameterSet(); if (!paramSet.isEmpty()) { for (final Map.Entry<String, String[]> entry : paramSet) { solrQuery.set(entry.getKey(), entry.getValue()); } } if (docValuesFields != null) { for (final String docValuesField : docValuesFields) { solrQuery.add(Constants.DCF, docValuesField); } } queryResponse = solrGroup.query(solrQuery, SolrRequest.METHOD.POST); } final long execTime = System.currentTimeMillis() - startTime; final QueryResponseList queryResponseList = ComponentUtil.getQueryResponseList(); queryResponseList.init(queryResponse, rows); queryResponseList.setSearchQuery(q); queryResponseList.setSolrQuery(solrQuery.toString()); queryResponseList.setExecTime(execTime); return queryResponseList; }
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 ww w .j a v a 2s . 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 w w .j a v a2 s .co 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());//from w w w .j a v a 2s. c om 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());//w w w .j a va2 s. c om 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);/* w w w . j a va2s . 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.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)); }/* w w w.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; }