当前位置: 首页>>代码示例>>Java>>正文


Java SolrInputDocument类代码示例

本文整理汇总了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();
}
 
开发者ID:dimensoft,项目名称:improved-journey,代码行数:18,代码来源:SolrCloudSolrjPopulator.java

示例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!");
  }
}
 
开发者ID:sematext,项目名称:solr-autocomplete,代码行数:23,代码来源:AutocompleteUpdateRequestProcessor.java

示例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;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:21,代码来源:DatabaseProduct.java

示例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);
        }
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:20,代码来源:MySolrJConverter.java

示例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"));
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:25,代码来源:TestServerTest.java

示例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);
    }
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:17,代码来源:SolrSearchServer.java

示例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());
    }
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:21,代码来源:MarcSolrClient.java

示例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());
    }
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:21,代码来源:MarcSolrClient.java

示例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();
	} 
}
 
开发者ID:agazzarini,项目名称:as-full-text-search-server,代码行数:27,代码来源:SampleIndexer.java

示例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;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:23,代码来源:SolrHelper.java

示例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;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:32,代码来源:SolrHelper.java

示例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]);
            }
        }
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:22,代码来源:AbstractIndexer.java

示例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;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:24,代码来源:SerializingSolrWriteStrategy.java

示例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);
    }
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:41,代码来源:SerializingSolrWriteStrategy.java


注:本文中的org.apache.solr.common.SolrInputDocument类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。