本文整理汇总了Java中org.apache.solr.common.SolrInputDocument.setField方法的典型用法代码示例。如果您正苦于以下问题:Java SolrInputDocument.setField方法的具体用法?Java SolrInputDocument.setField怎么用?Java SolrInputDocument.setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.SolrInputDocument
的用法示例。
在下文中一共展示了SolrInputDocument.setField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRuntimeLib
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
SearchServer server = testSearchServer.getSearchServer();
SolrClient client = (SolrClient) server.getBackend();
SolrInputDocument document = new SolrInputDocument();
document.setField("_id_", "1");
document.setField("_type_", "doc");
document.setField("dynamic_multi_facet_string_f1", "test");
document.setField("dynamic_multi_facet_string_f2", "hello");
client.add(document);
client.commit();
SolrQuery query = new SolrQuery("t");
query.setRequestHandler("/suggester");
query.set("suggestion.df", "facets");
query.set("suggestion.field", "dynamic_multi_facet_string_f1");
QueryResponse response = client.query(query);
assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
示例2: addContextFields
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
private void addContextFields(final SolrInputDocument solrDoc, Conversation conversation) {
if (conversation.getContext() != null) {
Context ctx = conversation.getContext();
solrDoc.setField(FIELD_CONTEXT, ctx.getContextType());
solrDoc.setField(FIELD_ENVIRONMENT, ctx.getEnvironmentType());
solrDoc.setField(FIELD_DOMAIN, ctx.getDomain());
if(ctx.getEnvironment() != null){
ctx.getEnvironment().entrySet().stream()
.filter(e -> Objects.nonNull(e.getValue()))
.filter(e -> StringUtils.isNotBlank(e.getKey()) && !e.getValue().isEmpty())
.filter(e -> !NOT_INDEXED_ENVIRONMENT_FIELDS.contains(e.getKey()))
.forEach(e -> {
solrDoc.setField(getEnvironmentField(e.getKey()), e.getValue());
});
}
}
if(conversation.getMeta() != null){
conversation.getMeta().getProperties().entrySet().stream()
.filter(e -> Objects.nonNull(e.getValue()))
.filter(e -> StringUtils.isNotBlank(e.getKey()) && !e.getValue().isEmpty())
.filter(e -> !NOT_INDEXED_META_FIELDS.contains(e.getKey()))
.forEach(e -> {
solrDoc.setField(getMetaField(e.getKey()), e.getValue());
});
}
}
示例3: createDocuments
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
/**
* Generates a list of test documents for insertion.
*
* @return the list of json String representing the documents
*/
static List<SolrInputDocument> createDocuments(long numDocs) {
String[] scientists = {
"Lovelace",
"Franklin",
"Meitner",
"Hopper",
"Curie",
"Faraday",
"Newton",
"Bohr",
"Galilei",
"Maxwell"
};
ArrayList<SolrInputDocument> data = new ArrayList<>();
for (int i = 0; i < numDocs; i++) {
int index = i % scientists.length;
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", String.valueOf(i));
doc.setField("scientist", scientists[index]);
data.add(doc);
}
return data;
}
示例4: checkAndCreateGroupDoc
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
/**
*
* @param groupIdField Field name of the group identifier.
* @param groupId Field value of the group identifier.
* @param metadata Map with additional metadat fields to add to the group document.
* @param iddoc IDDOC for the new document.
* @return Group SolrInputDocument, if created.
* @should create new document with all values if none exists
* @should create updated document with all values if one already exists
*/
public SolrInputDocument checkAndCreateGroupDoc(String groupIdField, String groupId, Map<String, String> metadata, long iddoc) {
try {
SolrDocumentList docs = search(SolrConstants.PI + ":" + groupId, null);
SolrInputDocument doc = new SolrInputDocument();
Date now = new Date();
if (docs.isEmpty()) {
// Document does not exist yet
doc.setField(SolrConstants.IDDOC, String.valueOf(iddoc));
doc.setField(SolrConstants.GROUPFIELD, String.valueOf(iddoc));
doc.setField(SolrConstants.DOCTYPE, DocType.GROUP.name());
doc.setField(SolrConstants.DATECREATED, now.getTime());
} else {
// A document already exists for this groupId
SolrDocument oldDoc = docs.get(0);
doc.setField(SolrConstants.IDDOC, oldDoc.getFieldValue(SolrConstants.IDDOC));
if (doc.getField(SolrConstants.GROUPFIELD) == null) {
doc.setField(SolrConstants.GROUPFIELD, oldDoc.getFieldValue(SolrConstants.IDDOC));
}
doc.setField(SolrConstants.DOCTYPE, DocType.GROUP.name());
doc.setField(SolrConstants.DATECREATED, oldDoc.getFieldValue(SolrConstants.DATECREATED));
}
doc.setField(SolrConstants.DATEUPDATED, now.getTime());
doc.setField(SolrConstants.PI, groupId);
doc.setField(SolrConstants.PI_TOPSTRUCT, groupId);
doc.setField(SolrConstants.GROUPTYPE, groupIdField);
if (metadata != null) {
for (String fieldName : metadata.keySet()) {
String fieldValue = metadata.get(fieldName);
doc.setField(fieldName, fieldValue);
}
}
return doc;
} catch (SolrServerException e) {
logger.error(e.getMessage(), e);
}
return null;
}
示例5: updateConversation
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
@Override
public void updateConversation(Conversation conversation, Date syncDate) {
try (SolrClient solr = solrServer.getSolrClient(conversationCore)){
SolrInputDocument doc = toSolrInputDocument(conversation);
if(doc != null){
doc.setField(FIELD_SYNC_DATE, syncDate);
solr.add(doc, commitWithin);
} else { //remove from index
solr.deleteByQuery(getDeleteQuery(conversation),commitWithin);
}
} catch (IOException | SolrServerException e) {
log.warn("Unable to index Conversation {} ({}: {})",conversation.getId(), e.getClass().getSimpleName(), e.getMessage());
log.debug("STACKTRACE",e);
}
}
示例6: toSolrInputDocument
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
private SolrInputDocument toSolrInputDocument(Message message, int i, Conversation conversation) {
final SolrInputDocument solrMsg = new SolrInputDocument();
String id = new StringBuilder(conversation.getId().toHexString()).append('_')
//we prefer to use the messageId but some system might not provide a such so we have a fallback
//to the index within the conversation
.append(StringUtils.isNoneBlank(message.getId()) ? message.getId() : String.valueOf(i)).toString();
solrMsg.setField(FIELD_ID, id);
solrMsg.setField(FIELD_CONVERSATION_ID, conversation.getId());
solrMsg.setField(FIELD_MESSAGE_ID, message.getId());
solrMsg.setField(FIELD_MESSAGE_IDX, i);
//#150 index the current version of the index so that we can detect the need of a
//full re-index after a software update on startup
solrMsg.setField(FIELD_INDEX_VERSION, CONVERSATION_INDEX_VERSION);
solrMsg.setField(FIELD_TYPE, TYPE_MESSAGE);
if (message.getUser() != null) {
solrMsg.setField(FIELD_USER_ID, message.getUser().getId());
solrMsg.setField(FIELD_USER_NAME, message.getUser().getDisplayName());
}
//add owner and context information
solrMsg.setField(FIELD_OWNER, conversation.getOwner().toHexString());
addContextFields(solrMsg, conversation);
solrMsg.setField(FIELD_MESSAGE, message.getContent());
solrMsg.setField(FIELD_TIME, message.getTime());
solrMsg.setField(FIELD_VOTE, message.getVotes());
// TODO: Add keywords, links, ...
return solrMsg;
}
示例7: accumulate
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
@Override
public void accumulate(SolrInputDocument document, Path filePath, BasicFileAttributes attributes)
throws IOException {
MCRPath mcrPath = MCRPath.toMCRPath(filePath); //check if this is an MCRPath -> more metadata
String ownerID = mcrPath.getOwner();
String absolutePath = '/' + filePath.subpath(0, filePath.getNameCount()).toString();
String urn = MCRURNManager.getURNForFile(ownerID,
absolutePath.substring(0, absolutePath.lastIndexOf("/") + 1), filePath.getFileName().toString());
if (urn != null) {
document.setField("fileURN", urn);
}
}
示例8: toSolrDocument
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
public SolrInputDocument toSolrDocument() {
SolrInputDocument doc = new SolrInputDocument();
LinkedList<MCRCategory> ancestors = MCRSolrClassificationUtil.getAncestors(category);
MCRCategory parent = !ancestors.isEmpty() ? ancestors.getLast() : null;
// ids
MCRCategoryID id = category.getId();
doc.setField("id", id.toString());
doc.setField("classification", id.getRootID());
doc.setField("type", "node");
if (category.isCategory()) {
doc.setField("category", id.getID());
}
// labels
Set<MCRLabel> labels = category.getLabels();
for (MCRLabel label : labels) {
doc.addField("label." + label.getLang(), label.getText());
}
// children
if (category.hasChildren()) {
for (MCRCategory child : category.getChildren()) {
doc.addField("children", child.getId().toString());
}
}
// parent
if (parent != null) {
doc.setField("parent", parent.getId().toString());
doc.setField("index", parent.getChildren().indexOf(category));
}
// ancestors
for (MCRCategory ancestor : ancestors) {
doc.addField("ancestors", ancestor.getId().toString());
}
return doc;
}
示例9: setUp
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
/**
* Indexes some sample data as test fixture.
*
* @throws Exception hopefully never, otherwise the test will fail.
*/
@Before
public void setUp() throws Exception {
super.setUp();
final SolrClient indexer = getSolrClient();
final SolrInputDocument book1 = new SolrInputDocument();
book1.setField("id","1");
book1.setField("title","Apache Solr Essentials");
book1.setField("author","Andrea Gazzarini");
indexer.add(book1);
indexer.commit();
}
示例10: SolrCloudFixture
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
public SolrCloudFixture(String solrHome) throws Exception {
String xml = IOHelper.loadText(new FileInputStream(new File(solrHome, "solr-no-core.xml")));
miniCluster = new MiniSolrCloudCluster(1, "/solr", new File("target/tmp").toPath(), xml, null, null);
String zkAddr = miniCluster.getZkServer().getZkAddress();
String zkHost = miniCluster.getZkServer().getZkHost();
buildZooKeeper(zkHost, zkAddr, new File(solrHome), "solrconfig.xml", "schema.xml");
List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
for (JettySolrRunner jetty : jettys) {
if (!jetty.isRunning()) {
log.warn("JETTY NOT RUNNING!");
} else {
log.info("JETTY RUNNING AT " + jetty.getBaseUrl() + " PORT " + jetty.getLocalPort());
}
}
solrClient = new CloudSolrClient(zkAddr, true);
solrClient.connect();
createCollection(solrClient, "collection1", 1, 1, "conf1");
Thread.sleep(1000); // takes some time to setup the collection...
// otherwise you'll get no live solr servers
solrClient.setDefaultCollection("collection1");
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
solrClient.add(doc);
solrClient.commit();
}
示例11: toSolrInputDoc
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
private SolrInputDocument toSolrInputDoc()
{
SolrInputDocument doc = new SolrInputDocument();
doc.setField("path", DEFAULT_PATH);
doc.setField("id", id);
doc.setField("uuid", uuid);
// Metadata
if (indexes != null && !indexes.isEmpty())
{
for (MetadataIndex index: indexes)
{
String type = index.getType();
// Only textual information stored in field contents (full-text search)
if ((type == null) || type.isEmpty() || "text/plain".equals(type))
{
doc.addField("contents", index.getValue());
}
MetadataType mt =
ApplicationContextProvider.getBean(MetadataTypeService.class)
.getMetadataTypeByName(itemClass.getOntClass().getURI(), index.getName());
SolrField sf = (mt != null) ? mt.getSolrField() : null;
if (sf != null || index.getQueryable() != null)
{
Boolean is_multivalued = (sf != null) ? sf.isMultiValued() : null;
String field_name = (sf != null) ? sf.getName() : index.getQueryable().toLowerCase();
if (is_multivalued != null && is_multivalued)
{
doc.addField(field_name, index.getValue());
}
else
{
doc.setField(field_name, index.getValue());
}
LOGGER.debug("Added {}: {}", field_name, index.getValue());
}
}
}
else
{
LOGGER.warn("Product '{}' contains no metadata", identifier);
}
return doc;
}
示例12: toInputDocument
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
/**
* Makes a SolrInputDocument from a Product database object.
* The returned document can be indexed as is.
* @param product to convert.
* @return an indexable solr document.
*/
private SolrInputDocument toInputDocument(Product product)
{
SolrInputDocument doc = new SolrInputDocument();
// Metadatas
List<MetadataIndex> indices = product.getIndexes();
if (indices != null && !indices.isEmpty())
{
for (MetadataIndex index : indices)
{
String type = index.getType();
// Only textual information stored in field contents (full-text search)
if ((type == null) || type.isEmpty() || "text/plain".equals(type))
{
doc.addField("contents", index.getValue());
}
// next line is considered bad practice:
//doc.addField("contents", index.getQueryable());
MetadataType mt = metadataTypeService
.getMetadataTypeByName(product.getItemClass(), index.getName());
SolrField sf = (mt != null)? mt.getSolrField(): null;
if (sf != null || index.getQueryable() != null)
{
Boolean is_multivalued = (sf != null)? sf.isMultiValued(): null;
String field_name = (sf != null)? sf.getName(): index.getQueryable().toLowerCase();
if (is_multivalued != null && is_multivalued)
{
doc.addField(field_name, index.getValue());
}
else
{
doc.setField(field_name, index.getValue());
}
//LOGGER.debug("Added " + field_name + ":" + index.getValue());
}
}
}
else
{
LOGGER.warn("Product '" + product.getIdentifier() + "' contains no metadata");
}
// DHuS Attributes
doc.setField("id", product.getId());
doc.setField("uuid", product.getUuid());
doc.setField("path", DEFAULT_PATH);
// Collections
List<Collection> collections = collectionService.getCollectionsOfProduct(product);
if (collections != null && !collections.isEmpty())
{
for (Collection collection : collections)
{
doc.addField("collection", collection.getName());
}
}
return doc;
}
示例13: deskewAlto_handleMissingFilename
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
@Test
public void deskewAlto_handleMissingFilename() throws Exception {
// String filename = "AC04987957_00000124";
String[] filenames = { "00000005.tif", "00225231.png" };
int[] imageWidth = { 4966, 2794 };
MetsIndexer indexer = new MetsIndexer(hotfolder);
File dataFolder = new File("resources/test/alto_deskew");
int i = 0;
for (String filename : filenames) {
String baseFilename = FilenameUtils.getBaseName(filename);
File altoFile = new File(dataFolder, baseFilename + ".xml");
String origAltoString = FileUtils.readFileToString(altoFile);
File outputFolder = new File(dataFolder, "output");
if (outputFolder.isDirectory()) {
FileUtils.deleteDirectory(outputFolder);
}
outputFolder.mkdir();
Map<String, Path> dataFolders = new HashMap<>();
dataFolders.put(DataRepository.PARAM_MEDIA, Paths.get(dataFolder.getAbsolutePath()));
SolrInputDocument doc = new SolrInputDocument();
doc.setField(SolrConstants.ALTO, origAltoString);
doc.setField(SolrConstants.WIDTH, "" + imageWidth[i]);
// doc.setField(SolrConstants.FILENAME, filename);
MetsIndexer.deskewAlto(dataFolders, doc);
String deskewedAltoString = (String) doc.getFieldValue(SolrConstants.ALTO);
AltoDocument deskewedDoc = AltoDocument.getDocumentFromString(deskewedAltoString);
FileUtils.writeStringToFile(new File(outputFolder, filename + ".xml"), deskewedAltoString, false);
Word testWord = (Word) deskewedDoc.getFirstPage().getAllWordsAsList().get(1);
Assert.assertNotNull(testWord);
if (filename.equals("00000005.tif")) {
Assert.assertEquals("Name", testWord.getContent());
// Assert.assertEquals(new Rectangle2D.Float(327, 765, 228, 54), testWord.getRect());
Assert.assertEquals("Tag0", testWord.getAttributeValue("TAGREFS"));
Assert.assertEquals("Tag0", deskewedDoc.getTags().getTags().getChild("NamedEntityTag", null).getAttributeValue("ID"));
}
i++;
}
}
示例14: mergeSolrUInputDoc
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
private SolrInputDocument mergeSolrUInputDoc(SolrInputDocument prev, SolrInputDocument current) {
prev.setField(FIELD_MESSAGE, String.format("%s%n%s", prev.getFieldValue(FIELD_MESSAGE), current.getFieldValue(FIELD_MESSAGE)));
prev.setField(FIELD_VOTE, Integer.parseInt(String.valueOf(prev.getFieldValue(FIELD_VOTE))) + Integer.parseInt(String.valueOf(current.getFieldValue(FIELD_VOTE))));
return prev;
}
示例15: setFloat32Field
import org.apache.solr.common.SolrInputDocument; //导入方法依赖的package包/类
@Override
protected void setFloat32Field(SolrInputDocument result, String fieldName, Float value) {
result.setField(fieldName, value);
}