本文整理汇总了Java中org.apache.solr.common.SolrDocument.getFieldValue方法的典型用法代码示例。如果您正苦于以下问题:Java SolrDocument.getFieldValue方法的具体用法?Java SolrDocument.getFieldValue怎么用?Java SolrDocument.getFieldValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.SolrDocument
的用法示例。
在下文中一共展示了SolrDocument.getFieldValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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());
}
}
示例3: 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;
}
示例4: getString
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
/**
* Safely gets a String for the given field.
*
* @param solrDocument the docoument to get the field from
* @param field the field to get
* @return the String value of the field
*/
default String getString(SolrDocument solrDocument, String field) {
String returnVal = null;
final Object object = solrDocument.getFieldValue(field);
if (object != null) {
if (object instanceof String) {
returnVal = (String) object;
} else if (object instanceof ArrayList) {
Collection<Object> objects = solrDocument.getFieldValues(field);
if (objects.size() > 0) {
returnVal = (String) objects.iterator().next();
}
} else {
returnVal = object.toString();
}
}
return returnVal;
}
示例5: getAnchorTitle
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
private static String getAnchorTitle(SolrDocument doc, SolrSearchIndex solr) throws SolrServerException {
String iddocParent = (String) doc.getFieldValue(SolrConstants.IDDOC_PARENT);
SolrDocumentList hits = solr.search(SolrConstants.IDDOC + ":" + iddocParent);
if (hits != null && !hits.isEmpty()) {
return (String) hits.get(0).getFirstValue("MD_TITLE");
}
return null;
}
示例6: getEarliestRecordDatestamp
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
public String getEarliestRecordDatestamp() throws SolrServerException {
try {
String searchStr = SolrConstants.ISWORK + ":true" + getAllSuffixes();
SolrQuery solrQuery = new SolrQuery(searchStr);
solrQuery.setRows(1);
solrQuery.addField(SolrConstants.DATECREATED);
solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
QueryResponse resp = server.query(solrQuery);
if (resp.getResults().size() > 0) {
SolrDocument doc = resp.getResults().get(0);
if (doc.getFieldValue(SolrConstants.DATECREATED) != null) {
Date d = new Date((Long) doc.getFieldValue(SolrConstants.DATECREATED));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// ;YYYY-MM-DDThh:mm:ssZ
SimpleDateFormat hours = new SimpleDateFormat("HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
hours.setTimeZone(TimeZone.getTimeZone("GMT"));
String yearMonthDay = format.format(d);
String hourMinuteSeconde = hours.format(d);
return yearMonthDay + "T" + hourMinuteSeconde + "Z";
}
}
} catch (NullPointerException e) {
logger.error(e.getMessage(), e);
}
return "";
}
示例7: getAnchorTitle
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
/**
*
* @param doc
* @return
*/
private String getAnchorTitle(SolrDocument doc) {
String iddocParent = (String) doc.getFieldValue(SolrConstants.IDDOC_PARENT);
try {
SolrDocumentList hits = solr.search(SolrConstants.IDDOC + ":" + iddocParent);
if (hits != null && !hits.isEmpty()) {
return (String) hits.get(0).getFirstValue(SolrConstants.TITLE);
}
} catch (SolrServerException e) {
logger.error(e.getMessage(), e);
}
return null;
}
示例8: search_shouldSortResultsCorrectly
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
/**
* @see SolrSearchIndex#search(String,int,int,List,List,Map)
* @verifies sort results correctly
*/
@Test
public void search_shouldSortResultsCorrectly() throws Exception {
SolrDocumentList result = DataManager.getInstance().getSearchIndex().search(null, null, null, Metadata.oai_dc.name(), 0, 10, false, null);
Assert.assertFalse(result.isEmpty());
long previous = 0;
for (SolrDocument doc : result) {
Long dateCreated = (long) doc.getFieldValue(SolrConstants.DATECREATED);
Assert.assertNotNull(dateCreated);
Assert.assertTrue(dateCreated > previous);
previous = dateCreated;
}
}
示例9: fieldValue2ColumnValue
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
private Object fieldValue2ColumnValue(SolrDocument doc, String fieldName, SqlTypeName targetType)
throws SolrSqlException {
Object value = doc.getFieldValue(fieldName);
if (value == null) {
return null;
}
switch (targetType) {
case CHAR:
case VARCHAR:
return value instanceof String ? value : value.toString();
case INTEGER:
return value instanceof Integer ? value : Integer.valueOf(value.toString());
case BIGINT:
return value instanceof Long ? value : Long.valueOf(value.toString());
case FLOAT:
return value instanceof Float ? value : Float.valueOf(value.toString());
case DOUBLE:
return value instanceof Double ? value : Double.valueOf(value.toString());
case DATE:
try {
return value instanceof Date ? value : new SimpleDateFormat("yyyy-mm-dd").parse(value.toString());
} catch (ParseException e) {
logger.error(e);
}
default:
throw new SolrSqlException(String.format("unexpected value: %s, type %s required",value,targetType));
}
}
示例10: checkIndex
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
/**
* Integrity check.
*/
public void checkIndex()
{
try
{
SolrQuery query = new SolrQuery("*:*");
query.setFilterQueries("*");
query.setStart(0);
Iterator<SolrDocument> it = solrDao.scroll(query);
while (it.hasNext())
{
SolrDocument doc = it.next();
Long pid = (Long) doc.get("id");
Product product = productService.systemGetProduct(pid);
if (product == null)
{
Long id = (Long) doc.getFieldValue("id");
LOGGER.warn("Removing unknown product " + id + " from solr index");
try
{
solrDao.remove(id);
// decrease the offset, because a product has been removed
query.setStart(query.getStart() - 1);
}
catch (IOException e)
{
LOGGER.error("Cannot remove Solr entry " + id, e);
}
}
}
}
catch (IOException|SolrServerException ex)
{
LOGGER.error("Cannot check the index", ex);
}
}
示例11: newArtifactWithVersion
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
public static Artifact newArtifactWithVersion(SolrDocument document) {
String groupId = (String) document.getFieldValue("g");
String artifactId = (String) document.getFieldValue("a");
String classifier = null;
String extension = (String) document.getFieldValue("p");
String version = (String) document.getFieldValue("v");
Map<String, String> properties = new HashMap<>();
properties.put("timestamp", ((Long) document.getFieldValue("timestamp")).toString());
File file = null;
return new DefaultArtifact(groupId, artifactId, classifier, extension, version, properties, file);
}
示例12: newArtifactWithLatestVersion
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
public static Artifact newArtifactWithLatestVersion(SolrDocument document) {
String groupId = (String) document.getFieldValue("g");
String artifactId = (String) document.getFieldValue("a");
String classifier = null;
String extension = (String) document.getFieldValue("p");
String version = (String) document.getFieldValue("latestVersion");
Map<String, String> properties = new HashMap<>();
properties.put("timestamp", ((Long) document.getFieldValue("timestamp")).toString());
File file = null;
return new DefaultArtifact(groupId, artifactId, classifier, extension, version, properties, file);
}
示例13: prepareUpdate
import org.apache.solr.common.SolrDocument; //导入方法依赖的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());
}
}
示例14: updateAllAnchorChildren
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
/***
* Re-indexes all child records of the given anchor document.
*
* @param indexObj {@link IndexObject}
* @throws IOException -
* @throws SolrServerException
*/
private void updateAllAnchorChildren(IndexObject indexObj) throws IOException, SolrServerException {
logger.debug("Scheduling all METS files that belong to this anchor for re-indexing...");
SolrDocumentList hits = hotfolder.getSolrHelper().search(new StringBuilder(SolrConstants.PI_PARENT).append(":").append(indexObj.getPi())
.append(" AND ").append(SolrConstants.ISWORK).append(":true").toString(), null);
if (hits.isEmpty()) {
logger.debug("No volume METS files found for this anchor.");
return;
}
for (SolrDocument doc : hits) {
// Do not use PI here, as older documents might not have that field, use PPN instead
String pi = doc.getFieldValue(SolrConstants.PI).toString();
if (doc.getFieldValue(SolrConstants.IDDOC_PARENT) != null && doc.getFieldValue(SolrConstants.IDDOC_PARENT).toString().equals(String
.valueOf(indexObj.getIddoc()))) {
logger.debug("{} already has the correct parent, skipping.", pi);
continue;
}
// String indexedMetsFilePath = URLEncoder.encode(Hotfolder.getIndexedMets() + File.separator + pi + AbstractIndexer.XML_EXTENSION, "utf-8");
String indexedMetsFilePath = dataRepository.getDir(DataRepository.PARAM_INDEXED_METS) + File.separator + pi
+ AbstractIndexer.XML_EXTENSION;
Path indexedMets = Paths.get(indexedMetsFilePath);
if (Files.exists(indexedMets)) {
hotfolder.getReindexQueue().add(indexedMets);
MetsIndexer.reindexedChildrenFileList.add(indexedMets);
logger.debug("Added '{}' to reindexedChildrenPiList.", pi);
}
}
}
示例15: toHeader
import org.apache.solr.common.SolrDocument; //导入方法依赖的package包/类
Header toHeader(SolrDocument doc, Collection<MCROAISetResolver<String, SolrDocument>> setResolver) {
Date modified = (Date) doc.getFieldValue(getModifiedField());
String docId = doc.getFieldValue("id").toString();
Header header = new Header(getObjectManager().getOAIId(docId), modified.toInstant());
setResolver.parallelStream()
.map(r -> r.getSets(docId))
.flatMap(Collection::stream)
.sorted(this::compare)
.sequential()
.forEachOrdered(header.getSetList()::add);
return header;
}