List of usage examples for org.apache.solr.common SolrDocumentList getNumFound
public long getNumFound()
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFingerPrintTest.java
License:Open Source License
@Test public void testFingerPrint4() throws Exception { putHandleDefaults();// w w w . j a v a 2 s. c o m QueryResponse response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}", params("q", "FINGERPRINT:" + NODES_METADATA[0].getNodeRef().getId(), "qt", "/afts", "shards.qt", "/afts", "start", "0", "fl", "DBID,score", "rows", "100")); SolrDocumentList docs = response.getResults(); assertEquals(4, docs.getNumFound()); SolrDocument doc0 = docs.get(0); long dbid0 = (long) doc0.getFieldValue("DBID"); assertEquals(dbid0, NODES[0].getId()); SolrDocument doc1 = docs.get(1); long dbid1 = (long) doc1.getFieldValue("DBID"); assertEquals(dbid1, NODES[2].getId()); SolrDocument doc2 = docs.get(2); long dbid2 = (long) doc2.getFieldValue("DBID"); assertEquals(dbid2, NODES[1].getId()); SolrDocument doc3 = docs.get(3); long dbid3 = (long) doc3.getFieldValue("DBID"); assertEquals(dbid3, NODES[3].getId()); }
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFingerPrintTest.java
License:Open Source License
@Test public void testFingerPrint5() throws Exception { putHandleDefaults();/* w w w .j av a 2 s .c o m*/ QueryResponse response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}", params("q", "FINGERPRINT:" + NODES_METADATA[0].getNodeRef().getId() + "_70", "qt", "/afts", "shards.qt", "/afts", "start", "0", "fl", "DBID,score", "rows", "100")); SolrDocumentList docs = response.getResults(); assertEquals(2, docs.getNumFound()); SolrDocument doc0 = docs.get(0); long dbid0 = (long) doc0.getFieldValue("DBID"); assertEquals(dbid0, NODES[0].getId()); SolrDocument doc1 = docs.get(1); long dbid1 = (long) doc1.getFieldValue("DBID"); assertEquals(dbid1, NODES[2].getId()); }
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFingerPrintTest.java
License:Open Source License
@Test public void testFingerPrint6() throws Exception { putHandleDefaults();//from ww w . j a va 2s. co m QueryResponse response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}", params("q", "FINGERPRINT:" + NODES_METADATA[0].getNodeRef().getId() + "_45", "qt", "/afts", "shards.qt", "/afts", "start", "0", "fl", "DBID,score", "rows", "100")); SolrDocumentList docs = response.getResults(); assertEquals(3, docs.getNumFound()); SolrDocument doc0 = docs.get(0); long dbid0 = (long) doc0.getFieldValue("DBID"); assertEquals(dbid0, NODES[0].getId()); SolrDocument doc1 = docs.get(1); long dbid1 = (long) doc1.getFieldValue("DBID"); assertEquals(dbid1, NODES[2].getId()); SolrDocument doc2 = docs.get(2); long dbid2 = (long) doc2.getFieldValue("DBID"); assertEquals(dbid2, NODES[1].getId()); }
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFingerPrintTest.java
License:Open Source License
@Test public void testFingerprintStillExistsAfterNodeMetadataUpdate() throws Exception { putHandleDefaults();// ww w.ja v a2 s. co m Transaction txn = getTransaction(0, 1); Node fileNode = getNode(txn, ACL, Node.SolrApiNodeStatus.UPDATED); NodeMetaData fileMetaData = getNodeMetaData(fileNode, txn, ACL, "mike", null, false); indexTransaction(txn, singletonList(fileNode), singletonList(fileMetaData), singletonList("This is a text content which is longer than the default hello world " + fileNode.getId() + " returned by the Mock SOLRAPIQueueClient. This is needed because the \"min_hash\" field type " + "definition in Solr doesn't take in account fields which produce less than 5 tokens (see the " + "ShingleFilter settings).")); makeSureContentNodeHasBeenIndexed(fileNode, "mike", "longer"); QueryResponse response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}", params("q", "FINGERPRINT:" + fileMetaData.getNodeRef().getId(), "qt", "/afts", "shards.qt", "/afts", "start", "0", "fl", "DBID,score", "rows", "100")); SolrDocumentList docs = response.getResults(); assertEquals(1, docs.getNumFound()); assertEquals(fileNode.getId(), docs.iterator().next().getFieldValue("DBID")); // Let's update the test node fileMetaData.setOwner("Andrea"); fileMetaData.getProperties().put(ContentModel.PROP_TITLE, new StringPropertyValue("This is the new file \"title\" metadata attribute.")); txn = getTransaction(0, 1); indexTransaction(txn, singletonList(fileNode), singletonList(fileMetaData)); makeSureContentNodeHasBeenIndexed(fileNode, "Andrea", "longer"); response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}", params("q", "FINGERPRINT:" + fileMetaData.getNodeRef().getId(), "qt", "/afts", "shards.qt", "/afts", "start", "0", "fl", "DBID,score", "rows", "100")); docs = response.getResults(); assertEquals(1, docs.getNumFound()); assertEquals(fileNode.getId(), docs.iterator().next().getFieldValue("DBID")); }
From source file:org.alfresco.solr.SolrInformationServer.java
License:Open Source License
@Override public TrackerState getTrackerInitialState() { try (SolrQueryRequest request = newSolrQueryRequest()) { TrackerState state = new TrackerState(); SolrRequestHandler handler = core.getRequestHandler(REQUEST_HANDLER_GET); ModifiableSolrParams newParams = new ModifiableSolrParams(request.getParams()).set("ids", "TRACKER!STATE!ACLTX,TRACKER!STATE!TX"); request.setParams(newParams);//from w w w . j a v a 2s.com SolrDocumentList response = executeQueryRequest(request, newSolrQueryResponse(), handler); if (response == null) { LOGGER.error("No response when getting the tracker state"); return state; } // We can find either or both docs here. for (int i = 0; i < response.getNumFound(); i++) { SolrDocument current = response.get(i); // ACLTX if (current.getFieldValue(FIELD_S_ACLTXCOMMITTIME) != null) { if (state.getLastIndexedChangeSetCommitTime() == 0) { state.setLastIndexedChangeSetCommitTime( getFieldValueLong(current, FIELD_S_ACLTXCOMMITTIME)); } if (state.getLastIndexedChangeSetId() == 0) { state.setLastIndexedChangeSetId(getFieldValueLong(current, FIELD_S_ACLTXID)); } } // TX if (current.getFieldValue(FIELD_S_TXCOMMITTIME) != null) { if (state.getLastIndexedTxCommitTime() == 0) { state.setLastIndexedTxCommitTime(getFieldValueLong(current, FIELD_S_TXCOMMITTIME)); } if (state.getLastIndexedTxId() == 0) { state.setLastIndexedTxId(getFieldValueLong(current, FIELD_S_TXID)); } } } long startTime = System.currentTimeMillis(); state.setLastStartTime(startTime); state.setTimeToStopIndexing(startTime - lag); state.setTimeBeforeWhichThereCanBeNoHoles(startTime - holeRetention); long timeBeforeWhichThereCanBeNoTxHolesInIndex = state.getLastIndexedTxCommitTime() - holeRetention; state.setLastGoodTxCommitTimeInIndex( timeBeforeWhichThereCanBeNoTxHolesInIndex > 0 ? timeBeforeWhichThereCanBeNoTxHolesInIndex : 0); long timeBeforeWhichThereCanBeNoChangeSetHolesInIndex = state.getLastIndexedChangeSetCommitTime() - holeRetention; state.setLastGoodChangeSetCommitTimeInIndex(timeBeforeWhichThereCanBeNoChangeSetHolesInIndex > 0 ? timeBeforeWhichThereCanBeNoChangeSetHolesInIndex : 0); return state; } }
From source file:org.ambraproject.article.service.BrowseServiceImpl.java
License:Apache License
/** * Returns a list of articles for a given category * @param params a collection filters / parameters to browse by * @return articles/*from w w w. j a v a2 s .co m*/ */ private BrowseResult getArticlesBySubjectViaSolr(BrowseParameters params) { BrowseResult result = new BrowseResult(); ArrayList<SearchHit> articles = new ArrayList<SearchHit>(); long total = 0; SolrQuery query = createCommonQuery(params.getJournalKey()); query.addField("title_display"); query.addField("author_display"); query.addField("article_type"); query.addField("publication_date"); query.addField("id"); query.addField("abstract_primary_display"); query.addField("eissn"); if (params.getSubjects() != null && params.getSubjects().length > 0) { StringBuffer subjectQuery = new StringBuffer(); for (String subject : params.getSubjects()) { subjectQuery.append("\"").append(subject).append("\"").append(" AND "); } // remove the last " AND " query.setQuery("subject_level_1:(" + subjectQuery.substring(0, subjectQuery.length() - 5) + ")"); } // we use subject_level_1 field instead of subject_facet field because // we are only interested in the top level subjects query.setFacet(true); query.addFacetField("subject_level_1"); query.setFacetMinCount(1); query.setFacetSort("index"); setSort(query, params); query.setStart(params.getPageNum() * params.getPageSize()); query.setRows(params.getPageSize()); try { QueryResponse response = this.serverFactory.getServer().query(query); SolrDocumentList documentList = response.getResults(); total = documentList.getNumFound(); for (SolrDocument document : documentList) { SearchHit sh = createArticleBrowseDisplay(document, query.toString()); articles.add(sh); } result.setSubjectFacet(facetCountsToHashMap(response.getFacetField("subject_level_1"))); } catch (SolrServerException e) { log.error("Unable to execute a query on the Solr Server.", e); } result.setTotal(total); result.setArticles(articles); return result; }
From source file:org.ambraproject.article.service.BrowseServiceImpl.java
License:Apache License
/** * Returns list of articles in a given date range, from newest to oldest * @param params the collection class of parameters. * @return the articles//from w w w . jav a 2 s.c o m */ private BrowseResult getArticlesByDateViaSolr(BrowseParameters params) { BrowseResult result = new BrowseResult(); ArrayList<SearchHit> articles = new ArrayList<SearchHit>(); long totalSize = 0; SolrQuery query = createCommonQuery(params.getJournalKey()); query.addField("title_display"); query.addField("author_display"); query.addField("article_type"); query.addField("publication_date"); query.addField("id"); query.addField("abstract_primary_display"); query.addField("eissn"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String sDate = sdf.format(params.getStartDate().getTime()); String eDate = sdf.format(params.getEndDate().getTime()); sDate = sDate + "T00:00:00Z"; eDate = eDate + "T00:00:00Z"; query.addFilterQuery("publication_date:[" + sDate + " TO " + eDate + "]"); StringBuffer sb = new StringBuffer(); if (params.getArticleTypes() != null && params.getArticleTypes().size() > 0) { for (URI uri : params.getArticleTypes()) { String path = uri.getPath(); int index = path.lastIndexOf("/"); if (index != -1) { String articleType = path.substring(index + 1); sb.append("\"").append(articleType).append("\"").append(" OR "); } } String articleTypesQuery = sb.substring(0, sb.length() - 4); if (articleTypesQuery.length() > 0) { query.addFilterQuery("article_type_facet:" + articleTypesQuery); } } setSort(query, params); query.setStart(params.getPageNum() * params.getPageSize()); query.setRows(params.getPageSize()); log.info("getArticlesByDate Solr Query:" + query.toString()); try { QueryResponse response = this.serverFactory.getServer().query(query); SolrDocumentList documentList = response.getResults(); totalSize = documentList.getNumFound(); for (SolrDocument document : documentList) { SearchHit sh = createArticleBrowseDisplay(document, query.toString()); articles.add(sh); } } catch (SolrServerException e) { log.error("Unable to execute a query on the Solr Server.", e); } result.setArticles(articles); result.setTotal(totalSize); return result; }
From source file:org.ambraproject.search.service.ArticleIndexingServiceTest.java
License:Apache License
@Test(dataProvider = "articleData", groups = { "originalConfig" }) public void testArticlePublished(Article article) throws Exception { String articleId = article.getDoi(); articleIndexingService.articlePublished(articleId); String solrID = articleId.replaceAll("info:doi/", ""); SolrQuery query = new SolrQuery("id:" + solrID); QueryResponse solrRes = solrServerFactory.getServer().query(query); SolrDocumentList sdl = solrRes.getResults(); assertEquals(1l, sdl.getNumFound(), "didn't send article to solr server"); }
From source file:org.ambraproject.search.service.ArticleIndexingServiceTest.java
License:Apache License
@Test(dataProvider = "articleData", groups = { "originalConfig" }, dependsOnMethods = { "testIndexArticle" }) public void testArticleDeleted(Article article) throws Exception { String articleId = article.getDoi(); articleIndexingService.indexArticle(articleId); String solrID = articleId.replaceAll("info:doi/", ""); //delete it./*from ww w . j a v a2s . c om*/ articleIndexingService.articleDeleted(articleId); //confirm it was removed. SolrQuery query = new SolrQuery("id:" + solrID); QueryResponse solrRes = solrServerFactory.getServer().query(query); SolrDocumentList sdl = solrRes.getResults(); assertEquals(0, sdl.getNumFound(), "failed to remove article from solr server"); }
From source file:org.ambraproject.search.service.ArticleIndexingServiceTest.java
License:Apache License
@Test(dataProvider = "articleData", groups = { "originalConfig" }) public void testIndexAllArticles(Article article) throws Exception { String message = articleIndexingService.indexAllArticles(); assertTrue(message.contains(" 2 articles "), "Wrong count of articles"); SolrQuery query = new SolrQuery("*:*"); QueryResponse solrRes = solrServerFactory.getServer().query(query); SolrDocumentList sdl = solrRes.getResults(); assertEquals(sdl.getNumFound(), getArticleData().length, "didn't index correct number of articles"); }