List of usage examples for org.apache.solr.common SolrDocumentList getNumFound
public long getNumFound()
From source file:org.dspace.app.webui.cris.components.statistics.ASolrStatsConfigurerComponent.java
protected BarrChartStatisticDatasBean generateTotalView(String key1, String key2, String key3) { BarrChartStatisticDatasBean totalResolutBean = new BarrChartStatisticDatasBean(key1, key2, key3); totalResolutBean.setName(key2);//from w w w .j a v a 2s . c o m totalResolutBean.setHits(1); SolrDocumentList sdl = (SolrDocumentList) solrResponse.getResponse().get("response"); totalResolutBean.setDataTable(new String[][] { new String[] { Long.toString(sdl.getNumFound()) } }); return totalResolutBean; }
From source file:org.dspace.app.webui.cris.servlet.DeptNetworkServlet.java
private boolean checkAvailableData(HttpServletRequest request, String connection, String value) throws SearchServiceException { String query = "type:" + connection + " AND focus_val:\"" + value + "\"" + " AND entity:" + ConstantNetwork.ENTITY_DEPT; QueryResponse rsp = shootQuery(query, false, null); SolrDocumentList docs = rsp.getResults(); if (docs != null) { if (docs.getNumFound() > 0) { return true; }//from w ww . jav a 2s.co m } return false; }
From source file:org.dspace.app.webui.cris.servlet.ResearcherNetworkServlet.java
private boolean checkAvailableData(HttpServletRequest request, String connection, String authority) throws SearchServiceException { String query = "type:" + connection + " AND focus_auth:" + authority + " AND entity:" + ConstantNetwork.ENTITY_RP; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query);/*w ww . j a v a 2 s .co m*/ solrQuery.setStart(0); solrQuery.setRows(0); QueryResponse rsp = getService().search(solrQuery); SolrDocumentList docs = rsp.getResults(); if (docs != null) { if (docs.getNumFound() > 0) { return true; } } return false; }
From source file:org.dspace.app.xmlui.aspect.discovery.AbstractSearch.java
License:Open Source License
/** * Attach a division to the given search division named "search-results" * which contains results for this search query. * * @param search The search division to contain the search-results division. *//*ww w.j a v a 2s .c o m*/ protected void buildSearchResultsDivision(Division search) throws IOException, SQLException, WingException, SearchServiceException { try { if (queryResults == null || queryResults.getResults() == null) { DSpaceObject scope = getScope(); this.performSearch(scope); } } catch (Throwable t) { log.error(t.getMessage(), t); queryResults = null; } if (queryResults != null) { if (getQuery().length() > 0) { search.addPara("result-query", "result-query").addContent( T_result_query.parameterize(getQuery(), queryResults.getResults().getNumFound())); } else { search.addPara("result-query", "result-query") .addContent(T_result_empty_query.parameterize(queryResults.getResults().getNumFound())); } } // Adding different types of listing (e.g. list, grid). String view = this.getParameterView(); Division results = search.addDivision("search-results", view); DSpaceObject searchScope = getScope(); if (searchScope instanceof Community) { Community community = (Community) searchScope; String communityName = community.getMetadata("name"); results.setHead(T_head1_community.parameterize(communityName)); } else if (searchScope instanceof Collection) { Collection collection = (Collection) searchScope; String collectionName = collection.getMetadata("name"); results.setHead(T_head1_collection.parameterize(collectionName)); } else { results.setHead(T_head1_none); } if (queryResults != null && queryResults.getResults().getNumFound() > 0) { SolrDocumentList solrResults = queryResults.getResults(); // Pagination variables. int itemsTotal = (int) solrResults.getNumFound(); int firstItemIndex = (int) solrResults.getStart() + 1; int lastItemIndex = (int) solrResults.getStart() + solrResults.size(); //if (itemsTotal < lastItemIndex) // lastItemIndex = itemsTotal; int currentPage = (int) (solrResults.getStart() / this.queryArgs.getRows()) + 1; int pagesTotal = (int) ((solrResults.getNumFound() - 1) / this.queryArgs.getRows()) + 1; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("page", "{pageNum}"); String pageURLMask = generateURL(parameters); //Check for facet queries ? If we have any add them String[] fqs = getParameterFacetQueries(); if (fqs != null) { for (String fq : fqs) { pageURLMask += "&fq=" + fq; } } results.setMaskedPagination(itemsTotal, firstItemIndex, lastItemIndex, currentPage, pagesTotal, pageURLMask); // Look for any communities or collections in the mix // UPDATE: mix everything. It's what is expected from a search. // UPDATE 2: actually not. Comm/coll should appear separated. ReferenceSet referenceSet = null; //* boolean resultsContainsBothContainersAndItems = false; for (SolrDocument doc : solrResults) { DSpaceObject resultDSO = SearchUtils.findDSpaceObject(context, doc); if (resultDSO instanceof Community || resultDSO instanceof Collection) { if (referenceSet == null) { referenceSet = results.addReferenceSet("search-results-repository", ReferenceSet.TYPE_SUMMARY_LIST, null, "repository-search-results"); // Set a heading showing that we will be listing containers that matched: referenceSet.setHead(T_head2); resultsContainsBothContainersAndItems = true; } referenceSet.addReference(resultDSO); } } //*/ // Put in palce top level referenceset referenceSet = results.addReferenceSet("search-results-repository", ReferenceSet.TYPE_SUMMARY_LIST, null, "repository-search-results"); for (SolrDocument doc : solrResults) { DSpaceObject resultDSO = SearchUtils.findDSpaceObject(context, doc); // if (resultDSO instanceof Item) { String group_by = this.getParameterGroup(); // If we are grouping, attempt to acquire the dc.isPartOf parent of the Item and group on it. // Otherwise, Group on the current Item. // TODO: this is a hack to always make sure any subItem is grouped under its parent if (!group_by.equals("none")) { Item parent = getParent((Item) resultDSO); // if parent not null, use parent otherwise use existing item. if (parent != null) { Reference parentRef = referenceSet.addReference(parent); addCollapsedDocuments(parentRef, parent, doc); } else { referenceSet.addReference(resultDSO); } } else { referenceSet.addReference(resultDSO); } // } } // Add hit highlighting information // <dri:referenceSet type="hitHighlighting"> // <dri:reference> // </dri:referenceSet> /* Map<String, Map<String, java.util.List<String>>> hl = queryResults.getHighlighting(); referenceSet = results.addReferenceSet("search-results-repository", ReferenceSet.TYPE_SUMMARY_LIST, null, "repository-hit-highlighting"); Reference ref = referenceSet.addReference(null); */ } else { results.addPara(T_no_results); } //}// Empty query }
From source file:org.dspace.authority.SolrAuthority.java
License:BSD License
@Override public String getLabel(String field, String key, String locale) { try {//from w w w . ja v a 2s . c o m if (log.isDebugEnabled()) { log.debug("requesting label for key " + key + " using locale " + locale); } SolrQuery queryArgs = new SolrQuery(); queryArgs.setQuery("id:" + key); queryArgs.setRows(1); QueryResponse searchResponse = getSearchService().search(queryArgs); SolrDocumentList docs = searchResponse.getResults(); if (docs.getNumFound() == 1) { String label = null; try { label = (String) docs.get(0).getFieldValue("value_" + locale); } catch (Exception e) { //ok to fail here } if (label != null) { if (log.isDebugEnabled()) { log.debug("returning label " + label + " for key " + key + " using locale " + locale + " and fieldvalue " + "value_" + locale); } return label; } try { label = (String) docs.get(0).getFieldValue("value"); } catch (Exception e) { log.error("couldn't get field value for key " + key, e); } if (label != null) { if (log.isDebugEnabled()) { log.debug("returning label " + label + " for key " + key + " using locale " + locale + " and fieldvalue " + "value"); } return label; } try { label = (String) docs.get(0).getFieldValue("value_en"); } catch (Exception e) { log.error("couldn't get field value for key " + key, e); } if (label != null) { if (log.isDebugEnabled()) { log.debug("returning label " + label + " for key " + key + " using locale " + locale + " and fieldvalue " + "value_en"); } return label; } } } catch (Exception e) { log.error("error occurred while trying to get label for key " + key, e); } return key; }
From source file:org.dspace.xoai.app.XOAI.java
License:BSD License
public int index() throws DSpaceSolrIndexerException { int result = 0; try {//www . jav a 2 s . c o m if (clean) { clearIndex(); System.out.println("Using full import."); this.indexAll(); } else { SolrQuery solrParams = new SolrQuery("*:*").addField("item.lastmodified") .addSortField("item.lastmodified", ORDER.desc).setRows(1); SolrDocumentList results = DSpaceSolrSearch.query(solrServerResolver.getServer(), solrParams); if (results.getNumFound() == 0) { System.out.println("There are no indexed documents, using full import."); result = this.indexAll(); } else result = this.index((Date) results.get(0).getFieldValue("item.lastmodified")); } solrServerResolver.getServer().commit(); if (optimize) { println("Optimizing Index"); solrServerResolver.getServer().optimize(); println("Index optimized"); } // Set last compilation date xoaiLastCompilationCacheService.put(new Date()); return result; } catch (DSpaceSolrException ex) { throw new DSpaceSolrIndexerException(ex.getMessage(), ex); } catch (SolrServerException ex) { throw new DSpaceSolrIndexerException(ex.getMessage(), ex); } catch (IOException ex) { throw new DSpaceSolrIndexerException(ex.getMessage(), ex); } }
From source file:org.dspace.xoai.data.DSpaceItemSolrRepository.java
License:BSD License
private ListItemsResults getResult(String where, int offset, int length) { List<AbstractItem> list = new ArrayList<AbstractItem>(); try {/* www. j a va 2 s . co m*/ SolrQuery params = new SolrQuery(where).setRows(length).setStart(offset); SolrDocumentList docs = DSpaceSolrSearch.query(params); for (SolrDocument doc : docs) { list.add(new DSpaceSolrItem(doc)); } return new ListItemsResults((docs.getNumFound() > offset + length), list, (int) docs.getNumFound()); } catch (DSpaceSolrException ex) { log.error(ex.getMessage(), ex); return new ListItemsResults(false, list); } }
From source file:org.dspace.xoai.data.DSpaceItemSolrRepository.java
License:BSD License
private ListItemIdentifiersResult getIdentifierResult(String where, int offset, int length) { List<AbstractItemIdentifier> list = new ArrayList<AbstractItemIdentifier>(); try {// w w w . j a va 2s. co m SolrQuery params = new SolrQuery(where).setRows(length).setStart(offset); boolean hasMore = false; SolrDocumentList docs = DSpaceSolrSearch.query(params); hasMore = (offset + length) < docs.getNumFound(); for (SolrDocument doc : docs) { list.add(new DSpaceSolrItem(doc)); } return new ListItemIdentifiersResult(hasMore, list, (int) docs.getNumFound()); } catch (DSpaceSolrException ex) { log.error(ex.getMessage(), ex); return new ListItemIdentifiersResult(false, list); } }
From source file:org.dspace.xoai.services.impl.xoai.DSpaceItemSolrRepository.java
License:BSD License
private QueryResult retrieveItems(List<ScopedFilter> filters, int offset, int length) throws DSpaceSolrException { List<Item> list = new ArrayList<Item>(); SolrQuery params = new SolrQuery(solrQueryResolver.buildQuery(filters)).setRows(length).setStart(offset); SolrDocumentList solrDocuments = DSpaceSolrSearch.query(server, params); for (SolrDocument doc : solrDocuments) list.add(new DSpaceSolrItem(doc)); return new QueryResult(list, (solrDocuments.getNumFound() > offset + length), (int) solrDocuments.getNumFound()); }
From source file:org.eclipse.orion.internal.server.search.IndexPurgeJob.java
License:Open Source License
@Override protected IStatus run(IProgressMonitor monitor) { Logger logger = LoggerFactory.getLogger(Indexer.class); if (logger.isDebugEnabled()) logger.debug("Purging indexes"); //$NON-NLS-1$ long start = System.currentTimeMillis(); SolrQuery query = findAllQuery();/*ww w . j ava 2 s.c o m*/ try { QueryResponse solrResponse = this.server.query(findAllQuery); SolrDocumentList result = solrResponse.getResults(); long numFound = result.getNumFound(); long processed = 0; List<String> listIds = new ArrayList<String>(); if (numFound > processed) { while (true) { checkCanceled(monitor); markStaleIndexes(result, listIds); processed += PAGE_SIZE; if (processed >= numFound) break; query.setParam(CommonParams.START, Long.toString(processed)); solrResponse = this.server.query(query); result = solrResponse.getResults(); // New indexes may have been added, perhaps numFound = result.getNumFound(); } } checkCanceled(monitor); if (listIds.size() > 0) { this.server.deleteById(listIds); this.server.commit(); } if (logger.isDebugEnabled()) logger.debug("\tPurged: " + listIds.size()); //$NON-NLS-1$ } catch (Exception e) { handleIndexingFailure(e); } long duration = System.currentTimeMillis() - start; if (logger.isDebugEnabled()) logger.debug("Purge job took " + duration + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //throttle scheduling frequency so the job never runs more than 5% of the time long delay = Math.max(DEFAULT_DELAY, duration * 20); schedule(delay); return Status.OK_STATUS; }