本文整理汇总了Java中org.apache.solr.client.solrj.response.TermsResponse类的典型用法代码示例。如果您正苦于以下问题:Java TermsResponse类的具体用法?Java TermsResponse怎么用?Java TermsResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TermsResponse类属于org.apache.solr.client.solrj.response包,在下文中一共展示了TermsResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printStats
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的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: getCountSorted
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
public TermsResponse.Term[] getCountSorted(HashMap<String, TermsResponse.Term> data) {
TermsResponse.Term[] arr = data.values().toArray(new TermsResponse.Term[data.size()]);
Arrays.sort(arr, new Comparator<TermsResponse.Term>() {
@Override
public int compare(TermsResponse.Term o1, TermsResponse.Term o2) {
long freq1 = o1.getFrequency();
long freq2 = o2.getFrequency();
if (freq2 < freq1) {
return -1;
} else if (freq1 < freq2) {
return 1;
} else {
return o1.getTerm().compareTo(o2.getTerm());
}
}
});
return arr;
}
示例3: buildTermsDictionary
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
protected Map<String, List<String>> buildTermsDictionary(SolrClient solr, int termsLimit) throws Exception {
Map<String, List<String>> terms = new HashMap<String, List<String>>();
SolrQuery termsQ = new SolrQuery();
termsQ.setParam("qt", "/terms");
termsQ.add("terms.fl", "text1_txt_en", "text3_txt_en", "string1_s", "string2_s");
termsQ.setParam("terms.limit", String.valueOf(termsLimit));
QueryResponse resp = solr.query(termsQ);
Map<String, List<TermsResponse.Term>> termsMap = resp.getTermsResponse().getTermMap();
for (String field : termsMap.keySet()) {
List<String> fieldTerms = new ArrayList<String>();
terms.put(field, fieldTerms);
for (TermsResponse.Term nextTerm : termsMap.get(field)) {
fieldTerms.add(nextTerm.getTerm());
}
}
String[] textFields = new String[]{"text1_txt_en", "text3_txt_en", "string1_s", "string2_s"};
for (String tf : textFields) {
List<String> termsForField = terms.get(tf);
log.info("Loaded "+(termsForField != null ? termsForField.size()+"" : "NULL")+" terms for "+tf);
}
return terms;
}
示例4: convertTermsQueryResponseToTermsMap
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
static Map<String, List<TermsFieldEntry>> convertTermsQueryResponseToTermsMap(QueryResponse response) {
if (response == null || response.getTermsResponse() == null || response.getTermsResponse().getTermMap() == null) {
return Collections.emptyMap();
}
TermsResponse termsResponse = response.getTermsResponse();
Map<String, List<TermsFieldEntry>> result = new LinkedHashMap<String, List<TermsFieldEntry>>(termsResponse
.getTermMap().size());
for (Map.Entry<String, List<Term>> entry : termsResponse.getTermMap().entrySet()) {
List<TermsFieldEntry> terms = new ArrayList<TermsFieldEntry>(entry.getValue().size());
for (Term term : entry.getValue()) {
SimpleTermsFieldEntry termsEntry = new SimpleTermsFieldEntry(term.getTerm(), term.getFrequency());
termsEntry.setField(entry.getKey());
terms.add(termsEntry);
}
result.put(entry.getKey(), terms);
}
return result;
}
示例5: testConvertTermsQueryResponseReturnsTermsMapCorrectlyWhenOneFieldReturned
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
@Test
public void testConvertTermsQueryResponseReturnsTermsMapCorrectlyWhenOneFieldReturned() {
TermsResponse termsResponse = new TermsResponse(new NamedList<NamedList<Number>>());
termsResponse.getTermMap().put("field_1", Arrays.asList(new Term("term_1", 10), new Term("term_2", 5)));
Mockito.when(response.getTermsResponse()).thenReturn(termsResponse);
Map<String, List<TermsFieldEntry>> result = ResultHelper.convertTermsQueryResponseToTermsMap(response);
Assert.assertEquals(1, result.size());
Assert.assertEquals("term_1", result.get("field_1").get(0).getValue());
Assert.assertEquals(10L, result.get("field_1").get(0).getValueCount());
Assert.assertEquals("field_1", result.get("field_1").get(0).getField().getName());
Assert.assertEquals("term_2", result.get("field_1").get(1).getValue());
Assert.assertEquals(5L, result.get("field_1").get(1).getValueCount());
Assert.assertEquals("field_1", result.get("field_1").get(1).getField().getName());
}
示例6: getInstitutions
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
@Override
public List<String> getInstitutions() {
SolrQuery query = new SolrQuery()
.addTermsField(INSTITUTIONS_SORT_FIELD)
.setRequestHandler("/terms").setTerms(true);
Set<String> institutionsSet = Sets.newTreeSet();
try {
QueryResponse response = solrServer.query(query);
TermsResponse termsResponse = response.getTermsResponse();
List<Term> termList = termsResponse
.getTerms(INSTITUTIONS_SORT_FIELD);
for (Term term : termList) {
institutionsSet.add(term.getTerm());
}
} catch (SolrServerException e) {
logger.error("Error getting Solr institutions list", e);
throw new OgpSolrException("Error getting Solr institutions list",
e);
}
return new ArrayList<String>(institutionsSet);
}
示例7: complete
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的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
示例8: addTerms
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
private void addTerms( NamedList<NamedList<Number>> terms, SynonymMap.Builder fieldBuilder, SynonymMap.Builder termBuilder, ArrayList<String> searchFields ) throws IOException {
TermsResponse termsResponse = new TermsResponse( terms );
for (String fieldName : searchFields ) {
CharsRef fieldChars = new CharsRef( fieldName );
List<TermsResponse.Term> termList = termsResponse.getTerms( fieldName );
if (termList != null) {
for (TermsResponse.Term tc : termList) {
String term = tc.getTerm();
Log.debug( "Add distributed term: " + fieldName + " = " + term );
addTerm( fieldChars, term, fieldBuilder, termBuilder );
}
}
}
}
示例9: init
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
public void init(SolrParams params) {
this.params = params;
String[] fields = params.getParams(TermsParams.TERMS_FIELD);
if (fields != null) {
for (String field : fields) {
// TODO: not sure 128 is the best starting size
// It use it because that is what is used for facets
fieldmap.put(field, new HashMap<String, TermsResponse.Term>(128));
}
}
}
示例10: parse
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
public void parse(NamedList<NamedList<Number>> terms) {
// exit if there is no terms
if (terms == null) {
return;
}
TermsResponse termsResponse = new TermsResponse(terms);
// loop though each field and add each term+freq to map
for (String key : fieldmap.keySet()) {
HashMap<String, TermsResponse.Term> termmap = fieldmap.get(key);
List<TermsResponse.Term> termlist = termsResponse.getTerms(key);
// skip this field if there are no terms
if (termlist == null) {
continue;
}
// loop though each term
for (TermsResponse.Term tc : termlist) {
String term = tc.getTerm();
if (termmap.containsKey(term)) {
TermsResponse.Term oldtc = termmap.get(term);
oldtc.addFrequency(tc.getFrequency());
termmap.put(term, oldtc);
} else {
termmap.put(term, tc);
}
}
}
}
示例11: getLexSorted
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
public TermsResponse.Term[] getLexSorted(HashMap<String, TermsResponse.Term> data) {
TermsResponse.Term[] arr = data.values().toArray(new TermsResponse.Term[data.size()]);
Arrays.sort(arr, new Comparator<TermsResponse.Term>() {
@Override
public int compare(TermsResponse.Term o1, TermsResponse.Term o2) {
return o1.getTerm().compareTo(o2.getTerm());
}
});
return arr;
}
示例12: getTerms
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
private List<TermsResponse.Term> getTerms (String field) throws SolrServerException {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setParam(CommonParams.QT, "/terms");
solrQuery.setParam(TermsParams.TERMS, true);
solrQuery.setParam(TermsParams.TERMS_LIMIT, "100");
solrQuery.setParam(TermsParams.TERMS_FIELD, field);
QueryResponse resp = solr.query(solrQuery);
return resp.getTermsResponse().getTermMap().get(field);
}
示例13: testConvertTermsQueryResponseReturnsTermsMapCorrectlyWhenMultipleFieldsReturned
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
@Test
public void testConvertTermsQueryResponseReturnsTermsMapCorrectlyWhenMultipleFieldsReturned() {
TermsResponse termsResponse = new TermsResponse(new NamedList<NamedList<Number>>());
termsResponse.getTermMap().put("field_1", Arrays.asList(new Term("term_1", 10), new Term("term_2", 5)));
termsResponse.getTermMap().put("field_2", Arrays.asList(new Term("term_2", 2), new Term("term_3", 1)));
Mockito.when(response.getTermsResponse()).thenReturn(termsResponse);
Map<String, List<TermsFieldEntry>> result = ResultHelper.convertTermsQueryResponseToTermsMap(response);
Assert.assertEquals(2, result.size());
Assert.assertEquals("field_1", result.get("field_1").get(0).getField().getName());
Assert.assertEquals("field_2", result.get("field_2").get(0).getField().getName());
}
示例14: testConvertTermsQueryResponseReturnsEmtpyMapWhenTermsMapIsEmpty
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
@Test
public void testConvertTermsQueryResponseReturnsEmtpyMapWhenTermsMapIsEmpty() {
TermsResponse termsResponse = new TermsResponse(new NamedList<NamedList<Number>>());
Mockito.when(response.getTermsResponse()).thenReturn(termsResponse);
Assert.assertThat(ResultHelper.convertTermsQueryResponseToTermsMap(response),
IsEqual.equalTo(Collections.<String, List<TermsFieldEntry>> emptyMap()));
}
示例15: suggestTermByField
import org.apache.solr.client.solrj.response.TermsResponse; //导入依赖的package包/类
/**
* Searches a indexed terms of a field that matched against the prefix parameter.
*
* @param prefix search term
* @param parameter mapped field to be searched
* @param limit of maximum matches
* @return a list of elements that matched against the prefix
*/
public List<String> suggestTermByField(String prefix, OccurrenceSearchParameter parameter, Integer limit) {
try {
String solrField = QUERY_FIELD_MAPPING.get(parameter).getFieldName();
SolrQuery solrQuery = buildTermQuery(parseTermsQueryValue(prefix).toLowerCase(), solrField,
Objects.firstNonNull(limit, DEFAULT_SUGGEST_LIMIT));
final QueryResponse queryResponse = solrClient.query(solrQuery);
final TermsResponse termsResponse = queryResponse.getTermsResponse();
return termsResponse.getTerms(solrField).stream().map(Term::getTerm).collect(Collectors.toList());
} catch (SolrServerException | IOException e) {
LOG.error("Error executing/building the request", e);
throw new SearchException(e);
}
}