org.apache.solr.client.solrj.impl.HttpSolrServer Java Examples
The following examples show how to use
org.apache.solr.client.solrj.impl.HttpSolrServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientSolrj.java From solr-indexing-book with Apache License 2.0 | 6 votes |
private static void runRemoteExample() { SolrServer solr = new HttpSolrServer("http://localhost:8983/solr/solrj"); listCollectionContent(solr, "Running in remote mode"); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "email3"); doc.addField("addr_from", "[email protected]"); doc.addField("addr_to","[email protected]"); doc.addField("addr_to","[email protected]"); doc.addField("subject","Re: Updating vacancy description"); try { solr.add(doc); solr.commit(); } catch (Exception e) { //Catch and ignore over-generic exception. Do NOT do this in production e.printStackTrace(); } listCollectionContent(solr, "Added record in remote mode"); solr.shutdown(); }
Example #2
Source File: SolrServersITCase.java From apache-solr-essentials with Apache License 2.0 | 6 votes |
/** * Uses the {@link HttpSolrServer} to index some data to Solr. * * @throws Exception in case of I/O or index failure. */ @Test public void httpSolrServer() throws Exception { // 1. Create a new instance of HttpSolrServer solr = new HttpSolrServer(SOLR_URI); // 2. Create some data final List<SolrInputDocument> albums = sampleData(); // 3. Add those data solr.add(albums); // 4. Commit solr.commit(); // 5. Verify verify(); }
Example #3
Source File: ConfigAction.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
public String test() { try { if (StringUtils.isNotBlank(this.getProviderUrl())) { SolrServer httpSolrServer = new HttpSolrServer(this.getProviderUrl()); SolrPingResponse ping = httpSolrServer.ping(); String time = String.valueOf(ping.getElapsedTime()); String[] args = {time}; this.addActionMessage(this.getText("note.provider.success", args)); } } catch (SolrServerException slr) { _logger.error("error in test", slr); this.addActionError(this.getText("error.connection")); return SUCCESS; } catch (Throwable t) { _logger.error("error in test", t); return FAILURE; } return SUCCESS; }
Example #4
Source File: Searcher.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
protected List<String> executeQuery(SolrQuery solrQuery) throws ApsSystemException { List<String> contentsId = new ArrayList<String>(); try { HttpClient httpClient = new DefaultHttpClient(); SolrServer solr = new HttpSolrServer(this.getSolrUrl(), httpClient, new XMLResponseParser()); QueryResponse rsp = solr.query(solrQuery); SolrDocumentList solrDocumentList = rsp.getResults(); for (SolrDocument doc : solrDocumentList) { String id = (String) doc.getFieldValue(CmsSearchEngineManager.CONTENT_ID_FIELD_NAME); //id is the uniqueKey field contentsId.add(id); } } catch (SolrServerException e) { throw new ApsSystemException("Error on solr server", e); } catch (Throwable t) { throw new ApsSystemException("Error extracting response", t); } return contentsId; }
Example #5
Source File: TestSolr.java From DistributedCrawler with Apache License 2.0 | 6 votes |
@Test public void testSearch() throws SolrServerException{ String url = "http://localhost:8888/solr"; SolrServer server = new HttpSolrServer(url); SolrQuery query = new SolrQuery("火箭"); query.setStart(0); query.setRows(100); QueryResponse response = server.query(query); SolrDocumentList docs = response.getResults(); System.out.println("文档个数:" + docs.getNumFound()); System.out.println("查询时间:" + response.getQTime()); for (SolrDocument doc : docs) { System.out.println("id: " + doc.getFieldValue("id")); System.out.println("title: " + doc.getFieldValue("title")); System.out.println("contect: "+doc.getFieldValue("content")); } }
Example #6
Source File: ShrinkerJob.java From thoth with BSD 3-Clause Clear License | 6 votes |
public void createDocumentShrinkers() throws SolrServerException, InterruptedException, ExecutionException { ExecutorService service = Executors.newFixedThreadPool(threadPoolSize); CompletionService<String> completionService = new ExecutorCompletionService<String>(service); HttpSolrServer thothServer = new HttpSolrServer(thothIndexUrl + realTimeCore); HttpSolrServer thothShrankServer = new HttpSolrServer(thothIndexUrl + shrankCore); ArrayList<ServerDetail> listOfServers = new ThothServers().getList(thothServer); for (ServerDetail serverDetail: listOfServers){ LOG.info("Shrinking docs for server("+serverDetail.getName()+"):("+serverDetail.getPort()+") "); completionService.submit(new DocumentShrinker(serverDetail, nowMinusTimeToShrink, thothServer, thothShrankServer)); } // Wait for all the executors to finish for(int i = 0; i < listOfServers.size(); i++){ completionService.take().get(); } LOG.info("Done Shrinking."); }
Example #7
Source File: SolrTarget04.java From datacollector with Apache License 2.0 | 6 votes |
private SolrServer getSolrClient() throws MalformedURLException { if(kerberosAuth) { // set kerberos before create SolrClient addSecurityProperties(); } if (SolrInstanceAPIType.SINGLE_NODE.toString().equals(this.instanceType)) { HttpSolrServer httpSolrServer = new HttpSolrServer(this.solrURI); httpSolrServer.setConnectionTimeout(connectionTimeout); httpSolrServer.setSoTimeout(socketTimeout); return httpSolrServer; } else { CloudSolrServer cloudSolrClient = new CloudSolrServer(this.zookeeperConnect); cloudSolrClient.setDefaultCollection(this.defaultCollection); return cloudSolrClient; } }
Example #8
Source File: SolrIndexBuilder.java From wandora with GNU General Public License v3.0 | 5 votes |
protected void makeSolrIndexFor(TopicMap tm, HttpSolrServer solr) throws TopicMapException, SolrServerException, IOException { if(tm != null) { int totalCount = tm.getNumTopics(); setProgressMax(totalCount); final Iterator<Topic> topics=tm.getTopics(); Iterator<SolrInputDocument> solrInputIterator = new Iterator<SolrInputDocument>() { int count = 0; @Override public boolean hasNext() { return (topics.hasNext() && !forceStop()); } @Override public SolrInputDocument next() { setProgress(count++); SolrInputDocument topicDocument = null; try { Topic t = topics.next(); topicDocument = makeSolrInputDocumentFor(t); } catch(Exception e) { e.printStackTrace(); } return topicDocument; } @Override public void remove() { } }; solr.add(solrInputIterator); solr.commit(); } }
Example #9
Source File: DocumentShrinker.java From thoth with BSD 3-Clause Clear License | 5 votes |
public DocumentShrinker(ServerDetail serverDetail, DateTime nowMinusTimeToShrink, HttpSolrServer thothServer, HttpSolrServer thothShrankServer) { this.shrankServer = thothShrankServer; this.realTimeServer = thothServer; this.nowMinusTimeToShrink = nowMinusTimeToShrink; this.serverDetail = serverDetail; }
Example #10
Source File: Solr04ServerUtil.java From datacollector with Apache License 2.0 | 5 votes |
public Solr04ServerUtil(String url) throws Exception { try { solrClient = new HttpSolrServer(url); } catch (Exception ex) { throw new RuntimeException(ex); } }
Example #11
Source File: Indexer.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
public synchronized void delete(String id) throws ApsSystemException { try { HttpSolrServer server = new HttpSolrServer(this.getSolrUrl()); server.deleteById(id); server.commit(); } catch (Throwable e) { throw new ApsSystemException("Errore nella cancellazione di un indice", e); } }
Example #12
Source File: Indexer.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
public synchronized void addSolrDocument(SolrInputDocument document) throws ApsSystemException { try { HttpSolrServer server = new HttpSolrServer(this.getSolrUrl()); server.add(document); server.commit(); } catch (Throwable t) { _logger.error("Error adding document", t); throw new ApsSystemException("Error adding document", t); } }
Example #13
Source File: SolrTarget04.java From datacollector with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void add(List<Map<String, Object>> fieldMaps) throws StageException { List<SolrInputDocument> documents = new ArrayList(); for(Map<String, Object> fieldMap : fieldMaps) { SolrInputDocument document = createDocument(fieldMap); documents.add(document); } try { this.solrClient.add(documents); } catch (SolrServerException | IOException | HttpSolrServer.RemoteSolrException ex) { throw new StageException(Errors.SOLR_04, ex.toString(), ex); } }
Example #14
Source File: TestSolr.java From DistributedCrawler with Apache License 2.0 | 5 votes |
@Test public void test() throws SolrServerException, IOException { String url = "http://localhost:8888/solr"; SolrServer server = new HttpSolrServer(url); SolrInputDocument doc1 = new SolrInputDocument(); doc1.addField("id", "1"); doc1.addField("title", "习近平亲民广获赞誉 美媒称领导中共魅力攻势"); doc1.addField("content", "最近一段时间,国家主席习近平排队吃包子、办公室发表新年贺词引起了广泛关注。人们发现,国家最高领导人吃的是寻常百姓饭,办公室里摆的也是家人照片。"); server.add(doc1); server.commit(); }
Example #15
Source File: SearchITCase.java From apache-solr-essentials with Apache License 2.0 | 5 votes |
/** * Indexes a set of sample documents. * * @throws SolrServerException in case of Solr internal failure, * @throws IOException in case of I/O failure. */ @BeforeClass public static void indexData() throws SolrServerException, IOException { // 1. Create a proxy indexer INDEXER = new ConcurrentUpdateSolrServer(SOLR_URI, 2, 1); // 2. Index sample data INDEXER.add(sampleData()); // 3. Commit changes INDEXER.commit(); // 4. Create a proxy searcher SEARCHER = new HttpSolrServer(SOLR_URI); }
Example #16
Source File: SolrDocumentSearch.java From BioSolr with Apache License 2.0 | 4 votes |
public SolrDocumentSearch(SolrConfiguration config) { this.config = config; this.server = new HttpSolrServer(config.getDocumentUrl()); }
Example #17
Source File: SearchContext.java From spring-data-solr-showcase with Apache License 2.0 | 4 votes |
@Bean public SolrServer solrServer(@Value("${solr.host}") String solrHost) { return new HttpSolrServer(solrHost); }
Example #18
Source File: Application.java From Spring-data-solr-example with Apache License 2.0 | 4 votes |
@Bean public SolrServer solrServer() { return new HttpSolrServer("http://localhost:8983/solr"); }
Example #19
Source File: HttpSolrServerConnector.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
@Override public void connect() { solrServer = new HttpSolrServer(solrServerURL); }
Example #20
Source File: SolrOntologySearch.java From BioSolr with Apache License 2.0 | 4 votes |
public SolrOntologySearch(SolrConfiguration config) { this.config = config; this.server = new HttpSolrServer(config.getOntologyUrl()); }
Example #21
Source File: FirstQueryITCase.java From apache-solr-essentials with Apache License 2.0 | 4 votes |
/** * Setup things for this test case. */ @Before public void setUp() { client = new HttpSolrServer("http://127.0.0.1:8983/solr/biblo"); }
Example #22
Source File: ThothServers.java From thoth with BSD 3-Clause Clear License | 4 votes |
public static void main(String[] args) throws SolrServerException { ThothServers thothServers = new ThothServers(); ArrayList<ServerDetail> serverDetails = thothServers.getList(new HttpSolrServer("http://thoth.sv2.trulia.com:8983/solr/collection1")); System.out.println(serverDetails.size()); }
Example #23
Source File: ThothConnection.java From thoth with BSD 3-Clause Clear License | 4 votes |
public void init() { server = new HttpSolrServer(thothIndexURL); }
Example #24
Source File: SolrConnector.java From TagRec with GNU Affero General Public License v3.0 | 4 votes |
public SolrConnector(String solrUrl, String core) { this.server = new HttpSolrServer(solrUrl + "/solr/" + core); }
Example #25
Source File: SolrJSupport.java From brooklyn-library with Apache License 2.0 | 4 votes |
public SolrJSupport(String hostname, int solrPort, String core) { server = new HttpSolrServer(String.format("http://%s:%d/solr/%s", hostname, solrPort, core)); server.setMaxRetries(1); server.setConnectionTimeout(5000); server.setSoTimeout(5000); }