本文整理汇总了Java中org.apache.solr.common.SolrInputDocument类的典型用法代码示例。如果您正苦于以下问题:Java SolrInputDocument类的具体用法?Java SolrInputDocument怎么用?Java SolrInputDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SolrInputDocument类属于org.apache.solr.common包,在下文中一共展示了SolrInputDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
public static void main(String[] args) throws IOException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer server = new CloudSolrServer(zkHost);
server.setDefaultCollection(defaultCollection);
for (int i = 0; i < 1000; ++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("cat", "book");
doc.addField("id", "book-" + i);
doc.addField("name", "The Legend of Po part " + i);
server.add(doc);
if (i % 100 == 0)
server.commit(); // periodically flush
}
server.commit();
}
示例2: persistToSolr
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
private void persistToSolr(Collection<SolrInputDocument> docs) throws SolrServerException, IOException {
if (docs.isEmpty()) {
/**
* @todo Throw an exception here? "DvObject id 9999 does not exist."
*/
logger.info("nothing to persist");
return;
}
logger.fine("persisting to Solr...");
SolrServer solrServer = new HttpSolrServer("http://" + systemConfig.getSolrHostColonPort() + "/solr");
/**
* @todo Do something with these responses from Solr.
*/
UpdateResponse addResponse = solrServer.add(docs);
UpdateResponse commitResponse = solrServer.commit();
}
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:SolrIndexServiceBean.java
示例3: fetchExistingOrCreateNewSolrDoc
import org.apache.solr.common.SolrInputDocument; //导入依赖的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!");
}
}
示例4: getImpl
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
@Override
public <T> T getImpl(Class<? extends T> cl)
{
if (!hasImpl(cl))
{
return null;
}
if (cl.equals(Product.class))
{
return (T) toProduct();
}
if (cl.equals(SolrInputDocument.class))
{
return (T) toSolrInputDoc();
}
return null;
}
示例5: write
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
@Override
public void write(Object source, Map sink) {
if (source == null) {
return;
}
SolrInputDocument convertedDocument = convert(source, SolrInputDocument.class);
sink.putAll(convertedDocument);
if (sink instanceof SolrInputDocument) {
SolrInputDocument parent = (SolrInputDocument) sink;
List<SolrInputDocument> childDocuments = convertedDocument.getChildDocuments();
if (childDocuments != null) {
parent.addChildDocuments(childDocuments);
}
}
}
示例6: 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"));
}
示例7: indexMultipleDocuments
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
private void indexMultipleDocuments(List<Document> docs) {
final List<SolrInputDocument> solrDocs = docs.parallelStream()
.map(doc -> createInputDocument(doc))
.collect(Collectors.toList());
try {
if (solrClientLogger.isTraceEnabled()) {
solrClientLogger.debug(">>> add({})", solrDocs);
} else {
solrClientLogger.debug(">>> add({})", solrDocs);
}
this.solrClient.add(solrDocs);
} catch (SolrServerException | IOException e) {
log.error("Cannot index documents {}", solrDocs, e);
throw new SearchServerException("Cannot index documents", e);
}
}
示例8: indexMap
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
public void indexMap(String id, Map<String, List<String>> objectMap)
throws IOException, SolrServerException {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", id);
for (String key : objectMap.keySet()) {
Object value = objectMap.get(key);
if (value != null) {
// System.err.printf("%s: class: %s\n", key, value.getClass());
document.addField(key + "_ss", value);
}
}
try {
UpdateResponse response = solr.add(document);
// solr.commit();
} catch (HttpSolrClient.RemoteSolrException ex) {
System.err.printf("document: %s", document);
System.err.printf("Commit exception: %s\n", ex.getMessage());
}
}
示例9: indexDuplumKey
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
public void indexDuplumKey(String id, Map<String, Object> objectMap)
throws IOException, SolrServerException {
SolrInputDocument document = new SolrInputDocument();
document.addField("id", id);
for (String key : objectMap.keySet()) {
Object value = objectMap.get(key);
if (value != null) {
// System.err.printf("%s: class: %s\n", key, value.getClass());
document.addField(key + "_ss", value);
}
}
try {
UpdateResponse response = solr.add(document);
// solr.commit();
} catch (HttpSolrClient.RemoteSolrException ex) {
System.err.printf("document: %s", document);
System.err.printf("Commit exception: %s\n", ex.getMessage());
}
}
示例10: main
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
/**
* Main entry point.
*
* @param args the command line arguments.
* @throws IOException in case of I/O failure.
*/
public static void main(String[] args) throws IOException, SolrServerException {
// This is the list of documents we will send to Solr
List<SolrInputDocument> books = new ArrayList<SolrInputDocument>();
// Populate the list
books.add(newBook("1", "Apache Solr Essentials", "Andrea Gazzarini"));
books.add(newBook("2", "Apache Solr FullText Search Server", "John White"));
books.add(newBook("3", "Enterprise Search with Apache Solr", "Martin Green"));
// Creates the Solr remote proxy
try (SolrClient client = new HttpSolrClient.Builder("http://127.0.0.1:8983/solr/ex1").build()) {
// Indexes data
client.add(books);
// Commits
client.commit();
}
}
示例11: createDocument
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
/**
* Creates a Solr input document from the given list of name:value pairs.
*
* @param luceneFields
* @return {@link SolrInputDocument}
*/
public static SolrInputDocument createDocument(List<LuceneField> luceneFields) {
SolrInputDocument doc = new SolrInputDocument();
if (luceneFields != null) {
for (LuceneField luceneField : luceneFields) {
if (luceneField.getValue() != null) {
// doc.addField(luceneField.getField(), luceneField.getValue(), 0);
// Do not pass a boost value because starting with Solr 3.6, adding an index-time boost to primitive field types will cause the commit to fail
doc.addField(luceneField.getField(), luceneField.getValue());
}
}
return doc;
}
return null;
}
示例12: updateDoc
import org.apache.solr.common.SolrInputDocument; //导入依赖的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;
}
示例13: addNamedEntitiesFields
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
/**
* Adds named entity fields from the given list to the given SolrInputDocument.
*
* @param altoData
* @param doc
*/
@SuppressWarnings("unchecked")
protected void addNamedEntitiesFields(Map<String, Object> altoData, SolrInputDocument doc) {
List<String> neList = (List<String>) altoData.get("NAMEDENTITIES");
if (neList != null && !neList.isEmpty()) {
for (String ne : neList) {
String[] splitString = ne.split("_", 2);
if (splitString[1] != null) {
splitString[1] = cleanUpNamedEntityValue(splitString[1]);
String fieldName = new StringBuilder("NE_").append(splitString[0]).toString();
doc.addField(fieldName, splitString[1]);
doc.addField(new StringBuilder(fieldName).append(SolrConstants._UNTOKENIZED).toString(), splitString[1]);
}
}
}
}
示例14: getPageDocsForPhysIdList
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
/**
* Returns all SolrInputDocuments mapped to the given list of PHYSIDs. Fields that are serialized separately (FULLTEXT, ALTO) are not returned!
*
* @throws FatalIndexerException
*
* @see de.intranda.digiverso.presentation.solr.model.writestrategy.ISolrWriteStrategy#getPageDocsForPhysIdList(java.util.List)
* @should return all docs for the given physIdList
*/
@Override
public List<SolrInputDocument> getPageDocsForPhysIdList(List<String> physIdList) throws FatalIndexerException {
List<SolrInputDocument> ret = new ArrayList<>();
for (String physId : physIdList) {
if (pageDocPhysIdIddocMap.get(physId) != null) {
SolrInputDocument doc = load(pageDocPhysIdIddocMap.get(physId));
if (doc != null) {
ret.add(doc);
}
}
}
return ret;
}
示例15: writePageDoc
import org.apache.solr.common.SolrInputDocument; //导入依赖的package包/类
/**
*
* @param order
* @param rootDoc
* @param aggregateRecords
* @throws FatalIndexerException
*/
private void writePageDoc(int order, SolrInputDocument rootDoc, boolean aggregateRecords) throws FatalIndexerException {
String iddoc = pageDocOrderIddocMap.get(order);
SolrInputDocument doc = load(iddoc);
if (doc != null) {
// doc.setField(SolrConstants.ORDER, newOrder); // make sure order starts at 1 in the end
{
Path xmlFile = Paths.get(tempFolder.toAbsolutePath().toString(), new StringBuilder().append(iddoc).append("_").append(
SolrConstants.FULLTEXT).toString());
if (Files.isRegularFile(xmlFile)) {
try {
String xml = FileUtils.readFileToString(xmlFile.toFile(), "UTF8");
doc.addField(SolrConstants.FULLTEXT, xml);
// Add the child doc's FULLTEXT values to the SUPERFULLTEXT value of the root doc
if (aggregateRecords) {
// sbSuperDefault.append('\n').append(doc.getFieldValue(SolrConstants.FULLTEXT));
rootDoc.addField(SolrConstants.SUPERFULLTEXT, (doc.getFieldValue(SolrConstants.FULLTEXT)));
}
logger.debug("Found FULLTEXT for: {}", iddoc);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
checkAndAddAccessCondition(doc);
if (!solrHelper.writeToIndex(doc)) {
logger.error(doc.toString());
}
// newOrder++;
} else {
logger.error("Could not find serialized document for IDDOC: {}", iddoc);
}
}