本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.addTermsField方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.addTermsField方法的具體用法?Java SolrQuery.addTermsField怎麽用?Java SolrQuery.addTermsField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.addTermsField方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: printStats
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Gibt für das übergebene Indexfeld die drei Indexterme aus, die die größte Document Frequency haben.
* Es werden hierbei aber nur Indexterme betrachtet, die mit einem Buchstaben beginnen.
*
* @param indexFieldName Feldname des Indexfelds
*/
private void printStats(String indexFieldName) {
System.out.println("- - - - - Field Statistics for Index Field " + indexFieldName + " - - - - -");
SolrQuery query = new SolrQuery();
query.setRequestHandler("/terms");
query.setTermsLimit(3);
query.setTermsSortString(TermsParams.TERMS_SORT_COUNT);
query.addTermsField(indexFieldName);
query.setTermsRegex("^[a-zA-Z].*");
QueryRequest request = new QueryRequest(query);
request.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
try {
List<TermsResponse.Term> terms = request.process(solrClient).getTermsResponse().getTerms(indexFieldName);
if (terms != null) {
for (TermsResponse.Term term : terms) {
System.out.println(term.getTerm() + " (df = " + term.getFrequency() + ")");
}
}
} catch (SolrServerException|IOException e) {
System.err.println("Fehler bei der Term-Lookup im Dictionary");
}
}
示例2: complete
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public List<String> complete(String query) {
List<String> results = new ArrayList<>();
SolrServer solrServer = new HttpSolrServer("http://" + systemConfig.getSolrHostColonPort() + "/solr");
SolrQuery solrQuery = new SolrQuery();
solrQuery.setParam("qt", "/terms");
solrQuery.setTermsLower(query);
solrQuery.setTermsPrefix(query);
// dataverses and files use SearchFields.NAME
// solrQuery.addTermsField(SearchFields.NAME);
solrQuery.addTermsField("text");
// long datasetFieldDescription = 33L;
// String solrFieldDatasetFieldDescription = datasetFieldService.find(datasetFieldDescription).getSolrField();
// solrQuery.addTermsField(solrFieldDatasetFieldDescription);
List<Term> items = null;
try {
logger.info("Solr query: " + solrQuery);
QueryResponse qr = solrServer.query(solrQuery);
TermsResponse resp = qr.getTermsResponse();
// items = resp.getTerms(SearchFields.NAME);
items = resp.getTerms("text");
// items = resp.getTerms(solrFieldDatasetFieldDescription);
} catch (SolrServerException e) {
items = null;
}
if (items != null) {
for (Term term : items) {
logger.info("term: " + term.getTerm());
results.add(term.getTerm());
}
} else {
logger.info("no terms found");
}
return results;
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:39,代碼來源:AutoCompleteBean.java
示例3: testTermsResponse
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Test
public void testTermsResponse() throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", 1);
doc.setField("terms_s", "samsung");
getSolrServer().add(doc);
getSolrServer().commit(true, true);
SolrQuery query = new SolrQuery();
query.setRequestHandler("/terms");
query.setTerms(true);
query.setTermsLimit(5);
query.setTermsLower("s");
query.setTermsPrefix("s");
query.addTermsField("terms_s");
query.setTermsMinCount(1);
QueryRequest request = new QueryRequest(query);
List<Term> terms = request.process(getSolrServer()).getTermsResponse().getTerms("terms_s");
Assert.assertNotNull(terms);
Assert.assertEquals(terms.size(), 1);
Term term = terms.get(0);
Assert.assertEquals(term.getTerm(), "samsung");
Assert.assertEquals(term.getFrequency(), 1);
}
示例4: appendTermsFieldToSolrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected void appendTermsFieldToSolrQuery(Field field, SolrQuery solrQuery) {
if (field != null && StringUtils.hasText(field.getName())) {
solrQuery.addTermsField(field.getName());
}
}