solrj

Testing Solr via Embedded Server

半腔热情 提交于 2019-12-03 05:04:51
问题 I'm coding some tests for my solr-indexer application. Following testing best practices, I want to write code self-dependant, just loading the schema.xml and solrconfig.xml and creating a temporary data tree for the indexing-searching tests. As the application is most written in java, I'm dealing with SolrJ library, but I'm getting problems (well, I'm lost in the universe of corecontainers-coredescriptor-coreconfig-solrcore ...) Anyone can place here some code to create an Embedded Server

Solr/Solrj: How can I determine the total number of documents in an index?

爷,独闯天下 提交于 2019-12-03 04:14:10
How can I determine the total number of documents in a Solr index using Solrj? After hours of searching on my own, I actually have an answer (given below); I'm only posting this question so others can find the solution more easily. Here's what I'm using. Is this canonical? Is there a better way? SolrQuery q = new SolrQuery("*:*"); q.setRows(0); // don't actually request any data return server.query(q).getResults().getNumFound(); Your answer of sending the query : is probably the best, most general solution. Especially if you are using SolrCloud. However, there is an alternate solution, the

SolrJ addFile keeps documents open

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've already submitted a similar question, but I've broken down the problem to its simplest form, so I'm gonna post it again: The problem is, that SolrJ seems to keep file handles open, if I add the same file more than once. I use the following method to submit a document to Solr: public boolean addDocument( File doc ) throws IOException, SolrServerException { ContentStreamUpdateRequest csur = new ContentStreamUpdateRequest( "/update/extract" ); csur.addFile( doc ); csur.setParam( "literal.id", Utils.getAbsolutePath( doc ) ); csur.setAction(

Solrj Authentication Fails On Write Operation

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Just password protected solr on Jetty server. I am able to read/access data from solr using solrj :-> HttpSolrServer solr = new HttpSolrServer("http://111.111.111:8983/solr/mysolr"); HttpClientUtil.setBasicAuth((DefaultHttpClient) solr.getHttpClient(), "admin", "akshaybhatt"); but it gives me I/O Exception as below. There are other examples on SO about authentication but I have no idea how do I use authentication in Solrj. The below error comes only when I try to update a record (and possibly add a record, not tested yet) org.apache.solr

solrj “org.apache.solr.common.util.SimpleOrderedMap cannot be cast to java.util.Map” exception when using “/suggest” handler

匿名 (未验证) 提交于 2019-12-03 01:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I get the class cast exception when trying to run the solrj program using /suggest handler. I am able to get the suggestion response from Solr Admin UI, but when the same is being tried from solrj client the above exception arises. The solr-config.xml entries are as follows : <searchComponent name="suggest" class="solr.SuggestComponent"> <lst name="suggester"> <str name="name">mySuggester</str> <str name="lookupImpl">FuzzyLookupFactory</str> <str name="dictionaryImpl">DocumentDictionaryFactory</str> <str name="field">suggestfield</str> <str

Solr JAVA客户端SolrJ 4.9使用示例教程

徘徊边缘 提交于 2019-12-03 01:20:43
简介 SolrJ是操作Solr的JAVA客户端,它提供了增加、修改、删除、查询Solr索引的JAVA接口。SolrJ针对 Solr提供了Rest 的HTTP接口进行了封装, SolrJ底层是通过使用httpClient中的方法来完成Solr的操作。 SolrJ/Solr 跨版本兼容性 SolrJ通常向后保持兼容性,可以使用新版本的SolrJ访问较旧的Solr,反之亦然。建议使用同Solr server同版本的SolrJ, 详见 http://wiki.apache.org/solr/Solrj 中关于兼容性的描述。 示例代码 采用 SolrInputDocument对象 增加、删除索引 import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.apache.solr.common.SolrInputDocument; public class AddDocsDemo { public static final String SOLR_URL = "http://172.168.63.233:8983/solr"; public static

Missing mandatory unique key field error in SolrJ

喜夏-厌秋 提交于 2019-12-02 21:04:50
问题 I've this issue in my project. I read my .xlsx excel file using Apache Poi and I want to index them in my Solr core. I use SolrInputDocument to index reading file. Here is my java codes package org.solr; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import java.io.File; import java.io

solrj 7.x Expected mime type application/octet-stream but got text/html.

匿名 (未验证) 提交于 2019-12-02 20:37:20
出现这种情况是因为baseurl填写错误,最开始的时候我写的是用tomcat启动后浏览器中访问solr的地址 结果就出现了如题的异常,当然提示的是404,还有可能提示405,Method not allowed,method post is not supported等等 查看源码后发现给出的实例是这种格式 http://ip:port/solr/+core , 修改后重新测试正常 solrj 7.x Expected mime type application/octet-stream but got text/html. 原文:https://www.cnblogs.com/tele-share/p/9226783.html

SolrJ addFile keeps documents open

℡╲_俬逩灬. 提交于 2019-12-02 19:03:11
问题 I've already submitted a similar question, but I've broken down the problem to its simplest form, so I'm gonna post it again: The problem is, that SolrJ seems to keep file handles open, if I add the same file more than once. I use the following method to submit a document to Solr: public boolean addDocument( File doc ) throws IOException, SolrServerException { ContentStreamUpdateRequest csur = new ContentStreamUpdateRequest( "/update/extract" ); csur.addFile( doc ); csur.setParam( "literal.id

SolrJ: Disable Autocommit

南笙酒味 提交于 2019-12-02 17:49:19
问题 We have an instance of Solr, where we've found that turning on autoCommit in the solrconfig.xml actually may serve our needs well. However there are some instances and some batch operations where we want to temporarily disable autocommit. I have not been able to find anything, but I'm wondering if anyone knew if via SolrJ you could disable autocommit for a certain process, and then re-enable it? 回答1: You can't disable and enable autocommit as it's configured in solrconfig.xml. However, you