本文整理汇总了Java中org.apache.solr.common.SolrDocumentList类的典型用法代码示例。如果您正苦于以下问题:Java SolrDocumentList类的具体用法?Java SolrDocumentList怎么用?Java SolrDocumentList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SolrDocumentList类属于org.apache.solr.common包,在下文中一共展示了SolrDocumentList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
public static void main(String[] args) throws MalformedURLException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer solr = new CloudSolrServer(zkHost);
solr.setDefaultCollection(defaultCollection);
/* ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "cat:electronics");
params.set("defType", "edismax");
params.set("start", "0");*/
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例2: main
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
public static void main(String[] args) throws MalformedURLException, SolrServerException {
HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
// ModifiableSolrParams params = new ModifiableSolrParams();
// params.setQuery("name:Samsung ");
// params.setStart(0);
// params.setRows(100);
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例3: search
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
* searches and returns a list of {@link SolrDocument}
*
* @param from startdate
* @param until enddate
* @param set which collection
* @param metadataPrefix
* @param firstRow
* @param numRows
* @param urnOnly
* @param querySuffix
* @return list of hits as {@link SolrDocument}
* @throws IOException
* @throws SolrServerException
*/
public SolrDocumentList search(String from, String until, String set, String metadataPrefix, int firstRow, int numRows, boolean urnOnly,
String querySuffix) throws IOException, SolrServerException {
StringBuilder sbQuery = new StringBuilder(buildQueryString(from, until, set, metadataPrefix, urnOnly, querySuffix));
if (urnOnly) {
sbQuery.append(" AND (").append(SolrConstants.URN).append(":* OR ").append(SolrConstants.IMAGEURN_OAI).append(":*)");
}
sbQuery.append(getAllSuffixes());
logger.debug("OAI query: {}", sbQuery.toString());
SolrQuery solrQuery = new SolrQuery(sbQuery.toString());
solrQuery.setStart(firstRow);
solrQuery.setRows(numRows);
solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
QueryResponse resp = server.query(solrQuery);
logger.debug("Total hits: {}, fetched records {} - {}", resp.getResults().getNumFound(), firstRow, firstRow + resp.getResults().size() - 1);
return resp.getResults();
}
示例4: query
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
*
* @param identifier
* @param metadataPrefix
* @param rows
* @return
* @throws SolrServerException
*/
private SolrDocumentList query(final String identifier, String metadataPrefix, int rows) throws SolrServerException {
String useIdentifier = ClientUtils.escapeQueryChars(identifier);
StringBuilder sb = new StringBuilder();
sb.append('(').append(SolrConstants.PI).append(':').append(useIdentifier).append(" OR ").append(SolrConstants.URN).append(':').append(
useIdentifier).append(" OR ").append(SolrConstants.IMAGEURN).append(':').append(useIdentifier).append(')');
sb.append(getAllSuffixes());
logger.debug(sb.toString());
SolrQuery solrQuery = new SolrQuery(sb.toString());
solrQuery.setRows(rows);
QueryResponse resp = server.query(solrQuery);
// if (resp.getResults().isEmpty() && Metadata.epicur.name().equals(metadataPrefix)) {
// solrQuery = new SolrQuery(new StringBuilder(SolrConstants.IMAGEURN_OAI).append(":").append(identifier).toString());
// solrQuery.setRows(rows);
// resp = server.query(solrQuery);
// }
return resp.getResults();
}
示例5: getLatestVolumeTimestamp
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
* If the given SolrDocument is an anchor, retrieve the latest DATEUPDATED timestamp value from its volumes.
*
* @param anchorDoc
* @param untilTimestamp
* @return
* @throws SolrServerException
*/
public long getLatestVolumeTimestamp(SolrDocument anchorDoc, long untilTimestamp) throws SolrServerException {
if (anchorDoc.getFieldValue(SolrConstants.ISANCHOR) != null && (Boolean) anchorDoc.getFieldValue(SolrConstants.ISANCHOR)) {
SolrDocumentList volumes = search(SolrConstants.ISWORK + ":true AND " + SolrConstants.IDDOC_PARENT + ":" + (String) anchorDoc
.getFieldValue(SolrConstants.IDDOC));
if (volumes != null) {
long latest = 0;
for (SolrDocument volume : volumes) {
long volumeTimestamp = getLatestValidDateUpdated(volume, untilTimestamp);
if (latest < volumeTimestamp) {
latest = volumeTimestamp;
}
}
if (latest > 0) {
return latest;
}
}
}
return -1;
}
示例6: 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;
}
示例7: 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;
}
示例8: search
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
* Search.
* <p>
* Set `start` and `rows` values in the SolrQuery parameter to paginate the results.<br>
* <strong>If no `rows` have been set, solr will only return 10 documents, no more.</strong>
* <p>
* To get the total number of document matching the given query, use {@code res.getNumFound()}.
*
* @param query a SolrQuery with at least a 'q' parameter set.
* @return A list of solr document matching the given query.
*/
@PreAuthorize("hasRole('ROLE_SEARCH')")
public SolrDocumentList search(SolrQuery query)
{
Objects.requireNonNull(query);
query.setQuery(solrDao.updateQuery(query.getQuery()));
try
{
return solrDao.search(query).getResults();
}
catch (SolrServerException | IOException ex)
{
LOGGER.error(ex);
throw new DHusSearchException("An exception occured while searching", ex);
}
}
示例9: init
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
@Before
public void init() throws IOException, SolrServerException {
MockitoAnnotations.initMocks(this);
when(solrClient.ping()).thenReturn(solrPingResponse);
when(solrPingResponse.getStatus()).thenReturn(0);
when(solrPingResponse.getQTime()).thenReturn(10);
when(solrClient.query(any())).thenReturn(response);
when(response.getResults()).thenReturn(new SolrDocumentList());
when(response.getResponse()).thenReturn(responseObject);
when(responseObject.get("responseHeader")).thenReturn(responseObject);
when(responseObject.get("params")).thenReturn(responseObject);
when(responseObject.get("suggestion.field")).thenReturn("category");
//we use the protected constructor to avoid schema checking
server = new SolrSearchServerTestClass(solrClient);
}
示例10: buildRealTimeGetResult
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
public static GetResult buildRealTimeGetResult(QueryResponse response, RealTimeGet query, DocumentFactory factory) {
final String DOC = "doc";
long nResults = 0;
List<Document> docResults = new ArrayList<>();
final SolrDocumentList results = response.getResults();
if(results != null && results.size() >0){
docResults = buildResultList(results, null, factory, null);
nResults = docResults.size();
} else {
final SolrDocument solrDoc = (SolrDocument)response.getResponse().get(DOC);
if(solrDoc != null) {
final SolrDocumentList solrDocuments = new SolrDocumentList();
solrDocuments.add(solrDoc);
docResults = buildResultList(solrDocuments, null, factory, null);
nResults = 1;
}
}
return new GetResult(nResults,docResults,query,factory);
}
示例11: 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());
}
}
示例12: removeGrievingAnchors
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
public int removeGrievingAnchors() throws FatalIndexerException {
String[] fields = { SolrConstants.IDDOC, SolrConstants.PI };
try {
List<String> toDelete = new ArrayList<>();
SolrDocumentList anchors = search(SolrConstants.ISANCHOR + ":true", Arrays.asList(fields));
for (SolrDocument anchor : anchors) {
String iddoc = (String) anchor.getFirstValue(SolrConstants.IDDOC);
String pi = (String) anchor.getFirstValue(SolrConstants.PI);
if (search(SolrConstants.PI_PARENT + ":" + pi, Collections.singletonList(SolrConstants.IDDOC)).getNumFound() == 0) {
toDelete.add(iddoc);
logger.info("{} has no volumes and will be deleted.", pi);
}
}
if (!toDelete.isEmpty()) {
deleteDocuments(toDelete);
commit(false);
return toDelete.size();
}
} catch (SolrServerException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
示例13: writeDocs_shouldWriteAllStructureDocsCorrectly
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
* @see LazySolrWriteStrategy#writeDocs()
* @verifies write all structure docs correctly
*/
@Test
public void writeDocs_shouldWriteAllStructureDocsCorrectly() throws Exception {
Map<String, Path> dataFolders = new HashMap<>();
dataFolders.put(DataRepository.PARAM_FULLTEXT, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_txt"));
dataFolders.put(DataRepository.PARAM_TEIMETADATA, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_wc"));
dataFolders.put(DataRepository.PARAM_TEIWC, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_wc"));
dataFolders.put(DataRepository.PARAM_OVERVIEW, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_overview"));
SolrHelper sh = new SolrHelper(server);
LazySolrWriteStrategy strat = new LazySolrWriteStrategy(sh);
MetsIndexer indexer = new MetsIndexer(hotfolder);
indexer.index(metsFile, false, dataFolders, strat, 1);
SolrDocumentList docList = hotfolder.getSolrHelper().search(SolrConstants.PI_TOPSTRUCT + ":PPN517154005 AND " + SolrConstants.DOCTYPE + ":"
+ DocType.DOCSTRCT.name(), null);
Assert.assertEquals(4, docList.size());
}
示例14: writeDocs_shouldWriteAllPageDocsCorrectly
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
* @see LazySolrWriteStrategy#writeDocs()
* @verifies write all page docs correctly
*/
@Test
public void writeDocs_shouldWriteAllPageDocsCorrectly() throws Exception {
Map<String, Path> dataFolders = new HashMap<>();
dataFolders.put(DataRepository.PARAM_FULLTEXT, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_txt"));
dataFolders.put(DataRepository.PARAM_TEIMETADATA, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_wc"));
dataFolders.put(DataRepository.PARAM_TEIWC, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_wc"));
dataFolders.put(DataRepository.PARAM_OVERVIEW, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_overview"));
SolrHelper sh = new SolrHelper(server);
LazySolrWriteStrategy strat = new LazySolrWriteStrategy(sh);
MetsIndexer indexer = new MetsIndexer(hotfolder);
indexer.index(metsFile, false, dataFolders, strat, 1);
SolrDocumentList docList = hotfolder.getSolrHelper().search(SolrConstants.PI_TOPSTRUCT + ":PPN517154005 AND " + SolrConstants.DOCTYPE + ":"
+ DocType.PAGE.name(), null);
Assert.assertEquals(16, docList.size());
}
示例15: writeDocs_shouldWriteAllStructureDocsCorrectly
import org.apache.solr.common.SolrDocumentList; //导入依赖的package包/类
/**
* @see SerializingSolrWriteStrategy#writeDocs()
* @verifies write all structure docs correctly
*/
@Test
public void writeDocs_shouldWriteAllStructureDocsCorrectly() throws Exception {
Map<String, Path> dataFolders = new HashMap<>();
dataFolders.put(DataRepository.PARAM_FULLTEXT, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_txt"));
dataFolders.put(DataRepository.PARAM_TEIMETADATA, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_wc"));
dataFolders.put(DataRepository.PARAM_OVERVIEW, Paths.get("resources/test/METS/kleiuniv_PPN517154005/kleiuniv_PPN517154005_overview"));
SolrHelper sh = new SolrHelper(server);
SerializingSolrWriteStrategy strat = new SerializingSolrWriteStrategy(sh, tempFolder);
MetsIndexer indexer = new MetsIndexer(hotfolder);
indexer.index(metsFile, false, dataFolders, strat, 1);
SolrDocumentList docList = hotfolder.getSolrHelper().search(SolrConstants.PI_TOPSTRUCT + ":PPN517154005 AND " + SolrConstants.DOCTYPE + ":"
+ DocType.DOCSTRCT.name(), null);
Assert.assertEquals(4, docList.size());
}