(Slor) 자바 의 solr 에 대한 기본 동작

3377 단어 Solr
package cn.solr;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

/**
 *   Solr       
 * 

Title: SolrDao

*

Description:

*

Company:

* @author * @date 2016 1 25 3:44:43 * @version 1.0 */ public class SolrDao { /** * * @throws IOException * @throws SolrServerException */ @Test public void addDoc() throws SolrServerException, IOException{ // // SolrInputDocument document = new SolrInputDocument(); // doc , document.addField("id", "number001"); document.addField("title_ik", " "); document.addField("content_ik", " "); // solr , HttpSolrServer solrClient = new HttpSolrServer("http://localhost:8080/solr"); solrClient.add(document); solrClient.commit(); } /** * id * */ @Test public void deleteDocumentById() throws Exception { HttpSolrServer server = new HttpSolrServer("http://localhost:8080/solr"); // server.deleteById("num001"); // server.commit(); } // @Test public void deleteDocumentByQuery() throws Exception { HttpSolrServer server = new HttpSolrServer("http://localhost:8080/solr"); // //server.deleteByQuery("*:*"); // server.commit(); } /** * * @throws SolrServerException */ @Test public void query() throws SolrServerException{ HttpSolrServer server = new HttpSolrServer("http://localhost:8080/solr"); SolrQuery query = new SolrQuery(); // query //query.set("q", "*:*");// query.set("q"," "); // query query.addFilterQuery("product_price:[0 TO 200]"); // query //query.addFilterQuery("-product_name: "); // query query.set("df", "product_keywords"); // query.setSort("product_price",ORDER.desc); // query.setStart(0); query.setRows(20);// // query.setHighlight(true); // query.addHighlightField("product_name"); // query.setHighlightSimplePre(""); query.setHighlightSimplePost(""); QueryResponse response = server.query(query); // SolrDocumentList solrDocumentList = response.getResults(); System.out.println(" :" + solrDocumentList.getNumFound()); // for (SolrDocument solrDocument : solrDocumentList) { System.out.println(solrDocument.get("id")); System.out.println(solrDocument.get("product_name")); System.out.println(solrDocument.get("product_price")); System.out.println(solrDocument.get("product_catalog_name")); System.out.println(solrDocument.get("product_picture")); } } }

좋은 웹페이지 즐겨찾기