本文整理匯總了Java中org.apache.solr.common.SolrDocument類的典型用法代碼示例。如果您正苦於以下問題:Java SolrDocument類的具體用法?Java SolrDocument怎麽用?Java SolrDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SolrDocument類屬於org.apache.solr.common包,在下文中一共展示了SolrDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLatestValidDateUpdated
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
/**
* Returns the latest DATEUPDATED value on the given <code>SolrDocument</code> that is no larger than <code>untilTimestamp</code>. Returns 0 if no
* such value is found.
*
* @param doc
* @param untilTimestamp
* @return Latest DATEUPDATED value is less than or equals untilTimestamp on doc; 0 if none found.
* @should return correct value
* @should return 0 if no valid value is found
*/
public static Long getLatestValidDateUpdated(SolrDocument doc, long untilTimestamp) {
long ret = 0;
Collection<Object> dateUpdatedValues = doc.getFieldValues(SolrConstants.DATEUPDATED);
if (dateUpdatedValues != null && !dateUpdatedValues.isEmpty()) {
// Get latest DATEUPDATED values
for (Object o : dateUpdatedValues) {
long dateUpdated = (Long) o;
if (dateUpdated > ret && dateUpdated <= untilTimestamp) {
ret = dateUpdated;
}
}
}
return ret;
}
示例2: fetchExistingOrCreateNewSolrDoc
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
private SolrInputDocument fetchExistingOrCreateNewSolrDoc(String id) throws SolrServerException, IOException {
Map<String, String> p = new HashMap<String, String>();
p.put("q", PHRASE + ":\"" + ClientUtils.escapeQueryChars(id) + "\"");
SolrParams params = new MapSolrParams(p);
QueryResponse res = solrAC.query(params);
if (res.getResults().size() == 0) {
return new SolrInputDocument();
} else if (res.getResults().size() == 1) {
SolrDocument doc = res.getResults().get(0);
SolrInputDocument tmp = new SolrInputDocument();
for (String fieldName : doc.getFieldNames()) {
tmp.addField(fieldName, doc.getFieldValue(fieldName));
}
return tmp;
} else {
throw new IllegalStateException("Query with params : " + p + " returned more than 1 hit!");
}
}
示例3: getUrlString
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
@Override
public String getUrlString(Class<? extends Page> pageClass, QueryFacetsSelection selection, SolrDocument document) {
final PageParameters params = new PageParameters();
if (selection != null) {
params.mergeWith(paramsConverter.toParameters(selection));
}
if (document != null) {
params.add(VloWebAppParameters.DOCUMENT_ID, document.getFirstValue(FacetConstants.FIELD_ID));
}
final String style = Session.get().getStyle();
if (style != null) {
params.add(VloWebAppParameters.THEME, style);
}
final CharSequence url = RequestCycle.get().urlFor(pageClass, params);
final String absoluteUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(url));
return absoluteUrl;
}
示例4: getLatestVolumeTimestamp
import org.apache.solr.common.SolrDocument; //導入依賴的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;
}
示例5: createListIdentifiers
import org.apache.solr.common.SolrDocument; //導入依賴的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;
}
示例6: readNextPage
import org.apache.solr.common.SolrDocument; //導入依賴的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;
}
示例7: buildRealTimeGetResult
import org.apache.solr.common.SolrDocument; //導入依賴的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);
}
示例8: newMapper
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
private Function<Object, Object> newMapper(String mapper) {
if (mapper.equals(MAPPER_NEW_URI)) {
return object -> {
try {
return Dependent.newUri((Artifact) object);
} catch (URISyntaxException exception) {
throw new RuntimeException(exception);
}
};
}
if (mapper.equals(MAPPER_NEW_ARTIFACT_WITH_VERSION)) {
return object -> Match.newArtifactWithVersion((SolrDocument) object);
}
if (mapper.equals(MAPPER_NEW_ARTIFACT_WITH_LATEST_VERSION)) {
return object -> Match.newArtifactWithLatestVersion((SolrDocument) object);
}
if (mapper.equals(MAPPER_NEW_SOLR_QUERY_FOR_ALL_VERSIONS)) {
return object -> Match.newSolrQueryForAllVersions((Artifact) object);
}
if (mapper.equals(MAPPER_NEW_SOLR_QUERY_FOR_LATEST_VERSION)) {
return object -> Match.newSolrQueryForLatestVersion((Artifact) object);
}
throw new IllegalArgumentException(
"Mapper must be one of newUri, newArtifactWithVersion, newArtifactWithLatestVersion or newSolrQuery");
}
示例9: prepareUpdate
import org.apache.solr.common.SolrDocument; //導入依賴的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());
}
}
示例10: updateDoc
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
/**
* Performs an atomic update of the given solr document. Updates defined in partialUpdates will be applied to the existing document without making
* any changes to other fields.
*
* @param doc
* @param partialUpdates Map of update operations (usage: Map<field, Map<operation, value>>)
* @return
* @throws FatalIndexerException
* @should update doc correctly
* @should add GROUPFIELD if original doc doesn't have it
*/
public boolean updateDoc(SolrDocument doc, Map<String, Map<String, Object>> partialUpdates) throws FatalIndexerException {
String iddoc = (String) doc.getFieldValue(SolrConstants.IDDOC);
SolrInputDocument newDoc = new SolrInputDocument();
newDoc.addField(SolrConstants.IDDOC, iddoc);
if (!doc.containsKey(SolrConstants.GROUPFIELD)) {
logger.warn("Document to update {} doesn't contain {} adding now.", iddoc, SolrConstants.GROUPFIELD);
Map<String, Object> update = new HashMap<>();
update.put("set", iddoc);
newDoc.addField(SolrConstants.GROUPFIELD, update);
}
for (String field : partialUpdates.keySet()) {
newDoc.addField(field, partialUpdates.get(field));
}
if (writeToIndex(newDoc)) {
commit(false);
return true;
}
return false;
}
示例11: removeGrievingAnchors
import org.apache.solr.common.SolrDocument; //導入依賴的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;
}
示例12: toHassoResult
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
@Override
protected ConversationResult toHassoResult(ComponentConfiguration conf, SolrDocument solrDocument, String type) {
final ConversationResult hassoResult = new ConversationResult(getCreatorName(conf));
hassoResult.setScore(Double.parseDouble(String.valueOf(solrDocument.getFieldValue("score"))));
hassoResult.setContent(String.valueOf(solrDocument.getFirstValue(FIELD_MESSAGE)));
hassoResult.setReplySuggestion(hassoResult.getContent());
hassoResult.setConversationId(String.valueOf(solrDocument.getFieldValue(FIELD_CONVERSATION_ID)));
hassoResult.setMessageId(String.valueOf(solrDocument.getFieldValue(FIELD_MESSAGE_ID)));
hassoResult.setMessageIdx(Integer.parseInt(String.valueOf(solrDocument.getFieldValue(FIELD_MESSAGE_IDX))));
hassoResult.setVotes(Integer.parseInt(String.valueOf(solrDocument.getFieldValue(FIELD_VOTE))));
hassoResult.setTimestamp((Date) solrDocument.getFieldValue(FIELD_TIME));
hassoResult.setUserName((String) solrDocument.getFieldValue(FIELD_USER_NAME));
return hassoResult;
}
示例13: indexPDFDocumentToExtractingRequestHandler
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
@Test
public void indexPDFDocumentToExtractingRequestHandler() throws Exception {
solrEndpoint.setRequestHandler("/update/extract");
Exchange exchange = createExchangeWithBody(new File("src/test/resources/data/tutorial.pdf"));
exchange.getIn().setHeader(SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
exchange.getIn().setHeader("SolrParam.literal.id", "tutorial.pdf");
template.send("direct:start", exchange);
solrCommit();
QueryResponse response = executeSolrQuery("*:*");
assertEquals(0, response.getStatus());
assertEquals(1, response.getResults().getNumFound());
SolrDocument doc = response.getResults().get(0);
assertEquals("Solr", doc.getFieldValue("subject"));
assertEquals("tutorial.pdf", doc.getFieldValue("id"));
assertEquals(Arrays.asList("application/pdf"), doc.getFieldValue("content_type"));
}
示例14: responseIs
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
private synchronized boolean responseIs( QueryResponse rsp, String field, String ... queries ) {
System.out.println( field + " " + rsp.getResults( ).size( ) );
HashSet<String> expected = new HashSet<String>( );
for ( int i = 0; i < queries.length; i++) {
System.out.println( "adding '" + queries[i] + "'" );
expected.add( queries[i] );
}
for (SolrDocument doc : rsp.getResults() ) {
String val = String.valueOf( doc.getFirstValue( field ) );
System.out.println( " '" + val + "'" );
if (expected.contains( val )) {
System.out.println( "removing '" + val + "'" );
expected.remove( val );
}
}
System.out.println( expected.size( ) + " left " );
return expected.size() == 0;
}
示例15: solrQuery
import org.apache.solr.common.SolrDocument; //導入依賴的package包/類
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
SolrQuery query = getBaseQuery(CommonParams.Q);
// set support
if (this.set != null) {
String setId = this.set.getSetId();
MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
setConfig.getHandler().apply(this.set, query);
}
// from & until
if (this.from != null || this.until != null) {
String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
query.add(CommonParams.FQ, fromUntilCondition);
}
// cursor
query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
query.set(CommonParams.SORT, "id asc");
// do the query
SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
QueryResponse response = solrClient.query(query);
Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}