本文整理匯總了Java中org.apache.solr.common.SolrDocumentList.getNumFound方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrDocumentList.getNumFound方法的具體用法?Java SolrDocumentList.getNumFound怎麽用?Java SolrDocumentList.getNumFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.common.SolrDocumentList
的用法示例。
在下文中一共展示了SolrDocumentList.getNumFound方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createListIdentifiers
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* for the server request ?verb=ListIdentifiers this method build the xml section
*
* @param handler
* @param firstRow
* @param numRows
* @return
* @throws SolrServerException
*/
public Element createListIdentifiers(RequestHandler handler, int firstRow, int numRows) throws SolrServerException {
Map<String, String> datestamp = filterDatestampFromRequest(handler);
SolrDocumentList listIdentifiers = solr.getListIdentifiers(datestamp, firstRow, numRows, false);
if (listIdentifiers == null || listIdentifiers.isEmpty()) {
return new ErrorCode().getNoRecordsMatch();
}
Namespace xmlns = DataManager.getInstance().getConfiguration().getStandardNameSpace();
Element xmlListIdentifiers = new Element("ListIdentifiers", xmlns);
long totalHits = listIdentifiers.getNumFound();
for (int i = 0; i < listIdentifiers.size(); i++) {
SolrDocument doc = listIdentifiers.get(i);
Element header = getHeader(doc, null, handler);
xmlListIdentifiers.addContent(header);
}
// Create resumption token
if (totalHits > firstRow + numRows) {
Element resumption = createResumptionTokenAndElement(totalHits, firstRow + numRows, xmlns, handler);
xmlListIdentifiers.addContent(resumption);
}
return xmlListIdentifiers;
}
示例2: readNextPage
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private boolean readNextPage() {
if (totalCountOfRows < 0 || startOfCurrentPage < totalCountOfRows) {
mySolrQuery.set("start", startOfCurrentPage);
mySolrQuery.set("rows", pageSize);
startOfCurrentPage += pageSize;
QueryResponse rsp = null;
List<Object[]> rows = new ArrayList<>();
try {
rsp = solrClientFactory.getClient().query(mySolrQuery);
SolrDocumentList docs = rsp.getResults();
totalCountOfRows = docs.getNumFound();
for (SolrDocument doc : docs) {
rows.add(doc2Row(doc));
}
} catch (Exception e) {
logger.error(e);
}
rowIteratorWithinCurrentPage = rows.iterator();
return true;
}
return false;
}
示例3: prepareUpdate
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* Prepares the given record for an update. Creation timestamp is preserved. A new update timestamp is added, child docs are removed.
*
* @param indexObj {@link IndexObject}
* @throws IOException -
* @throws SolrServerException
* @throws FatalIndexerException
*/
private void prepareUpdate(IndexObject indexObj) throws IOException, SolrServerException, FatalIndexerException {
String pi = indexObj.getPi().trim();
SolrDocumentList hits = hotfolder.getSolrHelper().search(SolrConstants.PI + ":" + pi, null);
if (hits != null && hits.getNumFound() > 0) {
logger.debug("This file has already been indexed, initiating an UPDATE instead...");
indexObj.setUpdate(true);
SolrDocument doc = hits.get(0);
// Set creation timestamp, if exists (should never be updated)
Object dateCreated = doc.getFieldValue(SolrConstants.DATECREATED);
if (dateCreated != null) {
// Set creation timestamp, if exists (should never be updated)
indexObj.setDateCreated((Long) dateCreated);
}
// Set update timestamp
Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
if (dateUpdatedValues != null) {
for (Object date : dateUpdatedValues) {
indexObj.getDateUpdated().add((Long) date);
}
}
// Recursively delete all children
deleteWithPI(pi, false, hotfolder.getSolrHelper());
}
}
示例4: filterNonEmpty
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private void filterNonEmpty(String classId, Element e) {
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
for (int i = 0; i < e.getChildren("category").size(); i++) {
Element cat = e.getChildren("category").get(i);
SolrQuery solrQquery = new SolrQuery();
solrQquery.setQuery(
"category:\"" + MCRSolrUtils.escapeSearchValue(classId + ":" + cat.getAttributeValue("ID")) + "\"");
solrQquery.setRows(0);
try {
QueryResponse response = solrClient.query(solrQquery);
SolrDocumentList solrResults = response.getResults();
if (solrResults.getNumFound() == 0) {
e.removeContent(cat);
i--;
}
} catch (SolrServerException | IOException exc) {
LOGGER.error(exc);
}
}
for (int i = 0; i < e.getChildren("category").size(); i++) {
filterNonEmpty(classId, e.getChildren("category").get(i));
}
}
示例5: getSolrDocument
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public SolrDocument getSolrDocument(String docId) {
if (docId == null) {
throw new NullPointerException("Cannot get SOLR document for null docId");
}
SolrDocument result = null;
SolrQuery query = new SolrQuery();
query.setQuery("id:" + ClientUtils.escapeQueryChars(docId));
query.setFields("*");
SolrDocumentList docs = fireQuery(query).getResults();
if (docs.getNumFound() > 1) {
logger.error("Error: found multiple documents for id (will return first one): " + docId + " \nDocuments found: " + docs);
result = docs.get(0);
} else if (docs.getNumFound() == 1) {
result = docs.get(0);
}
return result;
}
示例6: compareSolrDocumentList
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public boolean compareSolrDocumentList(Object expected, Object actual) {
if (!(expected instanceof SolrDocumentList) || !(actual instanceof SolrDocumentList)) {
return false;
}
if (expected == actual) {
return true;
}
SolrDocumentList list1 = (SolrDocumentList) expected;
SolrDocumentList list2 = (SolrDocumentList) actual;
if(Float.compare(list1.getMaxScore(), list2.getMaxScore()) != 0 || list1.getNumFound() != list2.getNumFound() ||
list1.getStart() != list2.getStart()) {
return false;
}
for(int i=0; i<list1.getNumFound(); i++) {
if(!compareSolrDocument(list1.get(i), list2.get(i))) {
return false;
}
}
return true;
}
示例7: testCommitWithin
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
@Test
public void testCommitWithin() throws Exception {
DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml);
ModifiableSolrParams params = params("command", "full-import",
"clean", "false", UpdateParams.COMMIT, "false",
UpdateParams.COMMIT_WITHIN, "1000");
req.setParams(params);
HttpSolrServer solrServer = new HttpSolrServer(buildUrl(jetty.getLocalPort(), "/solr"));
solrServer.request(req);
Thread.sleep(100);
ModifiableSolrParams queryAll = params("q", "*");
QueryResponse qres = solrServer.query(queryAll);
SolrDocumentList results = qres.getResults();
assertEquals(0, results.getNumFound());
Thread.sleep(1000);
for (int i = 0; i < 10; i++) {
qres = solrServer.query(queryAll);
results = qres.getResults();
if (2 == results.getNumFound()) {
solrServer.shutdown();
return;
}
Thread.sleep(500);
}
fail("Commit should have occured but it did not");
}
示例8: createSolrResultPage
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private <T> SolrResultPage<T> createSolrResultPage(Query query, Class<T> clazz, QueryResponse response,
Map<String, Object> objectsName) {
List<T> beans = convertQueryResponseToBeans(response, clazz);
SolrDocumentList results = response.getResults();
long numFound = results == null ? 0 : results.getNumFound();
Float maxScore = results == null ? null : results.getMaxScore();
Pageable pageRequest = query.getPageRequest();
SolrResultPage<T> page = new SolrResultPage<T>(beans, pageRequest, numFound, maxScore);
page.setFieldStatsResults(ResultHelper.convertFieldStatsInfoToFieldStatsResultMap(response.getFieldStatsInfo()));
page.setGroupResults(ResultHelper.convertGroupQueryResponseToGroupResultMap(query, objectsName, response, this,
clazz));
return page;
}
示例9: fetchPage
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public Page<SolrQuery, SolrDocument> fetchPage(SolrQuery query) throws SolrServerException, IOException {
SolrDocumentList documentList = this.fetchDocumentList(query);
Optional<SolrQuery> next = Optional.empty();
if (documentList.getStart() + documentList.size() < documentList.getNumFound()) {
SolrQuery copy = query.getCopy();
copy.setStart((int) (documentList.getStart() + documentList.size()));
next = Optional.of(copy);
}
return new Page<>(next, documentList);
}
示例10: prepareUpdate
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* Prepares the given record for an update. Creation timestamp and representative thumbnail and anchor IDDOC are preserved. A new update timestamp
* is added, child docs are removed.
*
* @param indexObj {@link IndexObject}
* @throws IOException
* @throws SolrServerException
* @throws FatalIndexerException
* @should keep creation timestamp
* @should set update timestamp correctly
* @should keep representation thumbnail
* @should keep anchor IDDOC
* @should delete anchor secondary docs
*/
protected void prepareUpdate(IndexObject indexObj) throws IOException, SolrServerException, FatalIndexerException {
String pi = indexObj.getPi().trim();
SolrDocumentList hits = hotfolder.getSolrHelper().search(SolrConstants.PI + ":" + pi, null);
if (hits != null && hits.getNumFound() > 0) {
logger.debug("This file has already been indexed, initiating an UPDATE instead...");
indexObj.setUpdate(true);
SolrDocument doc = hits.get(0);
// Set creation timestamp, if exists (should never be updated)
Object dateCreated = doc.getFieldValue(SolrConstants.DATECREATED);
if (dateCreated != null) {
// Set creation timestamp, if exists (should never be updated)
indexObj.setDateCreated((Long) dateCreated);
}
// Set update timestamp
Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
if (dateUpdatedValues != null) {
for (Object date : dateUpdatedValues) {
indexObj.getDateUpdated().add((Long) date);
}
}
// Set previous representation thumbnail, if available
Object thumbnail = doc.getFieldValue(SolrConstants.THUMBNAILREPRESENT);
if (thumbnail != null) {
indexObj.setThumbnailRepresent((String) thumbnail);
}
// Recursively delete all children, if not an anchor
deleteWithPI(pi, false, hotfolder.getSolrHelper());
}
}
示例11: execute
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
@Override
public SearchResult<? extends Result> execute(ComponentConfiguration conf, Template intent, Conversation conversation, MultiValueMap<String, String> queryParams) throws IOException {
// read default page-size from builder-configuration
int pageSize = conf.getConfiguration(CONFIG_KEY_PAGE_SIZE, 3);
// if present, a queryParam 'rows' takes precedence.
pageSize = toInt(queryParams.getFirst("rows"), pageSize);
long offset = toInt(queryParams.getFirst("start"), 0);
final QueryRequest solrRequest = buildSolrRequest(conf, intent, conversation, offset, pageSize, queryParams);
if (solrRequest == null) {
return new SearchResult<ConversationResult>(pageSize);
}
try (SolrClient solrClient = solrServer.getSolrClient(conversationCore)) {
final NamedList<Object> response = solrClient.request(solrRequest);
final QueryResponse solrResponse = new QueryResponse(response, solrClient);
final SolrDocumentList solrResults = solrResponse.getResults();
final List<ConversationResult> results = new ArrayList<>();
for (SolrDocument solrDocument : solrResults) {
//get the answers /TODO hacky, should me refactored (at least ordered by rating)
SolrQuery query = new SolrQuery("*:*");
query.add("fq",String.format("conversation_id:\"%s\"",solrDocument.get("conversation_id")));
query.add("fq", "message_idx:[1 TO *]");
query.setFields("*","score");
query.setSort("time", SolrQuery.ORDER.asc);
//query.setRows(3);
QueryResponse answers = solrClient.query(query);
results.add(toHassoResult(conf, solrDocument, answers.getResults(), intent.getType()));
}
return new SearchResult<>(solrResults.getNumFound(), solrResults.getStart(), pageSize, results);
} catch (SolrServerException e) {
throw new IOException(e);
}
}
示例12: isAlreadyStored
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private boolean isAlreadyStored(String publicationID) {
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
SolrQuery query = new SolrQuery();
query.setQuery(field2queryID + ":" + MCRSolrUtils.escapeSearchValue(publicationID));
query.setRows(0);
SolrDocumentList results;
try {
results = solrClient.query(query).getResults();
return (results.getNumFound() > 0);
} catch (Exception ex) {
throw new MCRException(ex);
}
}
示例13: toStr
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private static String toStr(SolrDocumentList lst, int maxSz) {
if (lst.size() <= maxSz) return lst.toString();
StringBuilder sb = new StringBuilder("SolrDocumentList[sz=" + lst.size());
if (lst.size() != lst.getNumFound()) {
sb.append(" numFound=" + lst.getNumFound());
}
sb.append("]=");
sb.append(lst.subList(0, maxSz / 2).toString());
sb.append(" , [...] , ");
sb.append(lst.subList(lst.size() - maxSz / 2, lst.size()).toString());
return sb.toString();
}
示例14: SolrDocumentListIterator
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public SolrDocumentListIterator(SolrDocumentList solrDocumentList) {
this.solrDocumentIterator = solrDocumentList.iterator();
this.numFound = solrDocumentList.getNumFound();
// SolrQuery has the start field of type int while SolrDocumentList of
// type long. We are always querying with an int so we can't receive a
// long as output. That's the reason why the following cast seems safe
this.start = (int) solrDocumentList.getStart();
this.size = solrDocumentList.size();
}
示例15: PageTool
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public PageTool(SolrQueryRequest request, SolrQueryResponse response) {
String rows = request.getParams().get("rows");
if (rows != null) {
results_per_page = new Integer(rows);
}
//TODO: Handle group by results
Object docs = response.getValues().get("response");
if (docs != null) {
if (docs instanceof DocSlice) {
DocSlice doc_slice = (DocSlice) docs;
results_found = doc_slice.matches();
start = doc_slice.offset();
} else if(docs instanceof ResultContext) {
DocList dl = ((ResultContext) docs).docs;
results_found = dl.matches();
start = dl.offset();
} else if(docs instanceof SolrDocumentList) {
SolrDocumentList doc_list = (SolrDocumentList) docs;
results_found = doc_list.getNumFound();
start = doc_list.getStart();
} else {
throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Unknown response type "+docs+". Expected one of DocSlice, ResultContext or SolrDocumentList");
}
}
page_count = (int) Math.ceil(results_found / (double) results_per_page);
current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0);
}