本文整理汇总了Java中org.apache.solr.client.solrj.impl.HttpSolrClient.query方法的典型用法代码示例。如果您正苦于以下问题:Java HttpSolrClient.query方法的具体用法?Java HttpSolrClient.query怎么用?Java HttpSolrClient.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.impl.HttpSolrClient
的用法示例。
在下文中一共展示了HttpSolrClient.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: categoriesAvailable
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入方法依赖的package包/类
public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId,
String facetPrefix, boolean displayproducts, int viewIndex, int viewSize, List<String> queryFilters, Boolean excludeVariants, String core) {
// create the data model
Map<String, Object> result = new HashMap<>();
HttpSolrClient client = null;
QueryResponse returnMap = new QueryResponse();
try {
// do the basic query
client = SolrUtil.getHttpSolrClient(core);
// create Query Object
String query = "inStock[1 TO *]";
if (categoryId != null)
query += " +cat:"+ SolrExprUtil.escapeTermFull(categoryId);
else if (productId != null)
query += " +productId:" + SolrExprUtil.escapeTermFull(productId);
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(query);
if (catalogId != null)
solrQuery.addFilterQuery("+catalog:" + SolrExprUtil.escapeTermFull(catalogId));
if (excludeVariants == null) excludeVariants = SolrProductSearch.excludeVariantsDefault;
if (excludeVariants)
SolrProductUtil.addExcludeVariantsFilter(solrQuery);
if (displayproducts) {
if (viewSize > -1) {
solrQuery.setRows(viewSize);
} else
solrQuery.setRows(50000);
if (viewIndex > -1) {
// 2016-04-01: This must be calculated
//solrQuery.setStart(viewIndex);
if (viewSize > 0) {
solrQuery.setStart(viewSize * viewIndex);
}
}
} else {
solrQuery.setFields("cat");
solrQuery.setRows(0);
}
if(UtilValidate.isNotEmpty(facetPrefix)){
solrQuery.setFacetPrefix(facetPrefix);
}
solrQuery.setFacetMinCount(0);
solrQuery.setFacet(true);
solrQuery.addFacetField("cat");
solrQuery.setFacetLimit(-1);
if (Debug.verboseOn()) Debug.logVerbose("solr: solrQuery: " + solrQuery, module);
returnMap = client.query(solrQuery,METHOD.POST);
result.put("rows", returnMap);
result.put("numFound", returnMap.getResults().getNumFound());
} catch (Exception e) {
Debug.logError(e.getMessage(), module);
}
return result;
}
示例2: findSolrGeoEntities
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入方法依赖的package包/类
private Collection<String> findSolrGeoEntities(List<String> labels) throws SolrServerException, IOException
{
if (!GeoprismProperties.getSolrLookup())
{
return new LinkedList<String>();
}
List<String> conditions = new LinkedList<String>();
Universal uni = null;
for (int i = 0; i < attributes.size(); i++)
{
UniversalAttribute attribute = attributes.get(i);
String label = labels.get(i);
if (label != null && label.length() > 0)
{
Universal universal = attribute.getUniversal();
conditions.add(universal.getId() + "%%%" + label);
uni = universal;
}
}
Collections.reverse(conditions);
String qText = SolrOntolgyStrategy.QUALIFIER + ":(" + uni.getId() + ")";
for (int i = 0; i < conditions.size(); i++)
{
String condition = conditions.get(i);
qText += " AND " + SolrOntolgyStrategy.RELATIONSHIPS + ":(" + ClientUtils.escapeQueryChars(condition) + ")";
}
HttpSolrClient client = new HttpSolrClient.Builder(SolrProperties.getUrl()).build();
try
{
SolrQuery query = new SolrQuery();
query.setQuery(qText);
query.setFields(SolrOntolgyStrategy.ENTITY);
// query.setRows(0);
QueryResponse response = client.query(query);
SolrDocumentList list = response.getResults();
Iterator<SolrDocument> iterator = list.iterator();
Set<String> ids = new TreeSet<String>();
while (iterator.hasNext())
{
SolrDocument document = iterator.next();
String entityId = (String) document.getFieldValue(SolrOntolgyStrategy.ENTITY);
ids.add(entityId);
}
return ids;
}
finally
{
client.close();
}
}
示例3: test0
import org.apache.solr.client.solrj.impl.HttpSolrClient; //导入方法依赖的package包/类
@Test
public void test0() throws SolrServerException, IOException {
String solrUrl = "http://localhost:8983/solr/";
String coreName = "test12";
HttpSolrClient client = new HttpSolrClient(solrUrl);
// ConcurrentUpdateSolrServer solrServer = new ConcurrentUpdateSolrServer(solrUrl, 1,2);
// CoreAdminResponse foo = CoreAdminRequest.createCore(coreName, "test1", client, ""
// );
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet("data_driven_schema_configs");
creator.process(client);
String baseURL = client.getBaseURL();
System.out.println("base url:"+ baseURL);
client.setBaseURL(solrUrl+ coreName);
Collection<SolrInputDocument> docs = new ArrayList<>();
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField("id", 12 );
doc1.addField("n", "XXBC");
doc1.addField("r", "HGNC:MK1");
doc1.addField("r", "MK1");
doc1.addField("a", "MKX");
doc1.addField("a", "MK2");
docs.add(doc1);
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField("id", 22 );
doc2.addField("n", "protein");
doc2.addField("r", "UniProt:Q6FGS5");
doc2.addField("r", "Q6FGS5");
doc2.addField("a", "Ensembl:ENSP00000254661");
doc2.addField("a", "ENSP00000254661");
doc2.addField("a", "HGNC Symbol:RAMP1");
doc2.addField("a", "RAMP1");
docs.add(doc2);
client.add(docs);
client.commit();
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("protein").setFields("id");
QueryResponse rsp = client.query(solrQuery);
SolrDocumentList dds = rsp.getResults();
for ( SolrDocument d : dds) {
System.out.println(d.get("id"));
}
client.setBaseURL(baseURL);
// foo = CoreAdminRequest.unloadCore(coreName, client);
// System.out.println(foo);
}