use of org.apache.solr.client.solrj.SolrServerException in project e3mall by colg-cloud.
the class TbItemServiceImpl method importAllItems.
@Override
public E3Result importAllItems() {
try {
// 查询所有商品列表
List<TbItemSerach> list = tbItemMapper.getItemList();
// 遍历商品列表
for (TbItemSerach serach : list) {
// 创建文档对象
SolrInputDocument doc = new SolrInputDocument();
// 向文档对象中添加域
doc.addField("id", serach.getId());
doc.addField("item_title", serach.getTitle());
doc.addField("item_sell_point", serach.getSellPoint());
doc.addField("item_price", serach.getPrice());
doc.addField("item_image", serach.getImage());
doc.addField("item_category_name", serach.getCategoryName());
// 把文档对象写入索引库
solrServer.add(doc);
}
// 提交
solrServer.commit();
// 返回导入成功
return E3Result.ok();
} catch (SolrServerException e) {
e.printStackTrace();
return E3Result.fail(500, "SolrServer 通信/解析异常!");
} catch (IOException e) {
e.printStackTrace();
return E3Result.fail(500, "SolrServer I/O异常!");
}
}
use of org.apache.solr.client.solrj.SolrServerException in project e3mall by colg-cloud.
the class TbItemServiceImpl method addDocument.
@Override
public E3Result addDocument(Long id) {
// 根据商品id查询商品信息
TbItemSerach serach = tbItemMapper.getItemById(id);
if (serach != null) {
// 创建一个文档对象
SolrInputDocument doc = new SolrInputDocument();
// 向文档对象中添加域
doc.addField("id", serach.getId());
doc.addField("item_title", serach.getTitle());
doc.addField("item_sell_point", serach.getSellPoint());
doc.addField("item_price", serach.getPrice());
doc.addField("item_image", serach.getImage());
doc.addField("item_category_name", serach.getCategoryName());
// 把文档写入索引库
try {
solrServer.add(doc);
// 提交
solrServer.commit();
} catch (SolrServerException e) {
e.printStackTrace();
return E3Result.fail(500, "SolrServer 通信/解析异常!");
} catch (IOException e) {
e.printStackTrace();
return E3Result.fail(500, "SolrServer I/O异常!");
}
}
return E3Result.ok();
}
use of org.apache.solr.client.solrj.SolrServerException in project qi4j-sdk by Qi4j.
the class SolrEntityQueryMixin method findEntities.
@Override
public Iterable<EntityReference> findEntities(Class<?> resultType, @Optional Specification<Composite> whereClause, @Optional OrderBy[] orderBySegments, @Optional Integer firstResult, @Optional Integer maxResults, Map<String, Object> variables) throws EntityFinderException {
try {
QuerySpecification expr = (QuerySpecification) whereClause;
SolrServer server = solr.solrServer();
NamedList<Object> list = new NamedList<Object>();
list.add("q", expr.query());
list.add("rows", maxResults != 0 ? maxResults : 10000);
list.add("start", firstResult);
if (orderBySegments != null && orderBySegments.length > 0) {
for (OrderBy orderBySegment : orderBySegments) {
String propName = ((Member) orderBySegment.property().accessor()).getName() + "_for_sort";
String order = orderBySegment.order() == OrderBy.Order.ASCENDING ? "asc" : "desc";
list.add("sort", propName + " " + order);
}
}
SolrParams solrParams = SolrParams.toSolrParams(list);
logger.debug("Search:" + list.toString());
QueryResponse query = server.query(solrParams);
SolrDocumentList results = query.getResults();
List<EntityReference> references = new ArrayList<EntityReference>(results.size());
for (SolrDocument result : results) {
references.add(EntityReference.parseEntityReference(result.getFirstValue("id").toString()));
}
return references;
} catch (SolrServerException e) {
throw new EntityFinderException(e);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project beam by apache.
the class SolrIOTest method testDefaultRetryPredicate.
/**
* Tests predicate performs as documented.
*/
@Test
public void testDefaultRetryPredicate() {
assertTrue(DEFAULT_RETRY_PREDICATE.test(new IOException("test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrServerException("test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.CONFLICT, "test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.SERVER_ERROR, "test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.INVALID_STATE, "test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.UNKNOWN, "test")));
assertTrue(DEFAULT_RETRY_PREDICATE.test(new HttpSolrClient.RemoteSolrException("localhost", SolrException.ErrorCode.SERVICE_UNAVAILABLE.code, "test", new Exception())));
assertFalse(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.BAD_REQUEST, "test")));
assertFalse(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.FORBIDDEN, "test")));
assertFalse(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.NOT_FOUND, "test")));
assertFalse(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.UNAUTHORIZED, "test")));
assertFalse(DEFAULT_RETRY_PREDICATE.test(new SolrException(SolrException.ErrorCode.UNSUPPORTED_MEDIA_TYPE, "test")));
}
use of org.apache.solr.client.solrj.SolrServerException in project beam by apache.
the class SolrIOTestUtils method commitAndGetCurrentNumDocs.
/**
* Forces a commit of the given collection to make recently inserted documents available for
* search.
*
* @return The number of docs in the index
*/
static long commitAndGetCurrentNumDocs(String collection, AuthorizedSolrClient client) throws IOException {
SolrQuery solrQuery = new SolrQuery("*:*");
solrQuery.setRows(0);
try {
UpdateRequest update = new UpdateRequest();
update.setAction(UpdateRequest.ACTION.COMMIT, true, true);
client.process(collection, update);
return client.query(collection, new SolrQuery("*:*")).getResults().getNumFound();
} catch (SolrServerException e) {
throw new IOException(e);
}
}
Aggregations