/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
apache-libraries/src/main/java/com/baeldung/apache/solrjava/SolrJavaIntegration.java
56 строк
2 KB
Gaetano Piazzolla
[JAVA-38868] Move apache-lib (#17447)
28 авг 2024, 20:25
Не верифицирован
28 авг 2024, 20:25
a6ce976
Код
Авторство
О чём код?
package com.baeldung.apache.solrjava; import java.io.IOException; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.impl.XMLResponseParser; import org.apache.solr.common.SolrInputDocument; public class SolrJavaIntegration { private HttpSolrClient solrClient; public SolrJavaIntegration(String clientUrl) { solrClient = new HttpSolrClient.Builder(clientUrl).build(); solrClient.setParser(new XMLResponseParser()); } public void addProductBean(ProductBean pBean) throws IOException, SolrServerException { solrClient.addBean(pBean); solrClient.commit(); } public void addSolrDocument(String documentId, String itemName, String itemPrice) throws SolrServerException, IOException { SolrInputDocument document = new SolrInputDocument(); document.addField("id", documentId); document.addField("name", itemName); document.addField("price", itemPrice); solrClient.add(document); solrClient.commit(); } public void deleteSolrDocumentById(String documentId) throws SolrServerException, IOException { solrClient.deleteById(documentId); solrClient.commit(); } public void deleteSolrDocumentByQuery(String query) throws SolrServerException, IOException { solrClient.deleteByQuery(query); solrClient.commit(); } protected HttpSolrClient getSolrClient() { return solrClient; } protected void setSolrClient(HttpSolrClient solrClient) { this.solrClient = solrClient; } }