本文整理汇总了Java中org.apache.solr.client.solrj.response.TermsResponse.Term方法的典型用法代码示例。如果您正苦于以下问题:Java TermsResponse.Term方法的具体用法?Java TermsResponse.Term怎么用?Java TermsResponse.Term使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.response.TermsResponse
的用法示例。
在下文中一共展示了TermsResponse.Term方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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 );
}
}
}
}
示例4: 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);
}
}
}
}
示例5: 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;
}
示例6: 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);
}
示例7: run
import org.apache.solr.client.solrj.response.TermsResponse; //导入方法依赖的package包/类
public void run( ) {
try {
SolrClient solrClient = getSolrClient( );
if (solrClient == null) {
LOG.error( "Cant't get SolrClient for " + solrHost );
return;
}
if (suggestProcessor == null) {
LOG.error( "Suggest Processor is NULL!" );
return;
}
ModifiableSolrParams params = new ModifiableSolrParams( );
params.set( TermsParams.TERMS_LIMIT, -1);
params.set( TermsParams.TERMS_SORT, TermsParams.TERMS_SORT_INDEX);
String[] fields = termFields.toArray( new String[ termFields.size( )] );
params.set( TermsParams.TERMS_FIELD, fields );
params.set( CommonParams.QT, termsHandler );
params.set( TermsParams.TERMS, "true" );
QueryResponse rsp = solrClient.query( collection, params );
TermsResponse termsResponse = rsp.getTermsResponse( );
for (String fieldName : termFields ) {
List<TermsResponse.Term> termList = termsResponse.getTerms( fieldName );
if (termList != null) {
for (TermsResponse.Term tc : termList) {
String term = tc.getTerm();
HashMap<String,Object> meta = new HashMap<String,Object>( );
meta.put( "collection", collection );
meta.put( "collector", "TermVectorQueryCollector" );
meta.put( "field", fieldName );
QuerySuggestion qSuggestion = new QuerySuggestion( term, meta, null );
suggestProcessor.addSuggestion( qSuggestion );
}
}
}
}
catch ( Exception e ) {
}
finally {
suggestProcessor.collectorDone( this );
}
}
示例8: buildResponse
import org.apache.solr.client.solrj.response.TermsResponse; //导入方法依赖的package包/类
public NamedList buildResponse() {
NamedList<Object> response = new SimpleOrderedMap<>();
// determine if we are going index or count sort
boolean sort = !TermsParams.TERMS_SORT_INDEX.equals(params.get(
TermsParams.TERMS_SORT, TermsParams.TERMS_SORT_COUNT));
// init minimum frequency
long freqmin = 1;
String s = params.get(TermsParams.TERMS_MINCOUNT);
if (s != null) freqmin = Long.parseLong(s);
// init maximum frequency, default to max int
long freqmax = -1;
s = params.get(TermsParams.TERMS_MAXCOUNT);
if (s != null) freqmax = Long.parseLong(s);
if (freqmax < 0) {
freqmax = Long.MAX_VALUE;
}
// init limit, default to max int
long limit = 10;
s = params.get(TermsParams.TERMS_LIMIT);
if (s != null) limit = Long.parseLong(s);
if (limit < 0) {
limit = Long.MAX_VALUE;
}
// loop though each field we want terms from
for (String key : fieldmap.keySet()) {
NamedList<Number> fieldterms = new SimpleOrderedMap<>();
TermsResponse.Term[] data = null;
if (sort) {
data = getCountSorted(fieldmap.get(key));
} else {
data = getLexSorted(fieldmap.get(key));
}
// loop though each term until we hit limit
int cnt = 0;
for (TermsResponse.Term tc : data) {
if (tc.getFrequency() >= freqmin && tc.getFrequency() <= freqmax) {
fieldterms.add(tc.getTerm(), num(tc.getFrequency()));
cnt++;
}
if (cnt >= limit) {
break;
}
}
response.add(key, fieldterms);
}
return response;
}
示例9: TermsHelper
import org.apache.solr.client.solrj.response.TermsResponse; //导入方法依赖的package包/类
public TermsHelper() {
fieldmap = new HashMap<String, HashMap<String, TermsResponse.Term>>(5);
}
示例10: buildResponse
import org.apache.solr.client.solrj.response.TermsResponse; //导入方法依赖的package包/类
public NamedList buildResponse() {
NamedList<Object> response = new SimpleOrderedMap<Object>();
// determine if we are going index or count sort
boolean sort = !TermsParams.TERMS_SORT_INDEX.equals(params.get(
TermsParams.TERMS_SORT, TermsParams.TERMS_SORT_COUNT));
// init minimum frequency
long freqmin = 1;
String s = params.get(TermsParams.TERMS_MINCOUNT);
if (s != null) freqmin = Long.parseLong(s);
// init maximum frequency, default to max int
long freqmax = -1;
s = params.get(TermsParams.TERMS_MAXCOUNT);
if (s != null) freqmax = Long.parseLong(s);
if (freqmax < 0) {
freqmax = Long.MAX_VALUE;
}
// init limit, default to max int
long limit = 10;
s = params.get(TermsParams.TERMS_LIMIT);
if (s != null) limit = Long.parseLong(s);
if (limit < 0) {
limit = Long.MAX_VALUE;
}
// loop though each field we want terms from
for (String key : fieldmap.keySet()) {
NamedList<Number> fieldterms = new SimpleOrderedMap<Number>();
TermsResponse.Term[] data = null;
if (sort) {
data = getCountSorted(fieldmap.get(key));
} else {
data = getLexSorted(fieldmap.get(key));
}
// loop though each term until we hit limit
int cnt = 0;
for (TermsResponse.Term tc : data) {
if (tc.getFrequency() >= freqmin && tc.getFrequency() <= freqmax) {
fieldterms.add(tc.getTerm(), num(tc.getFrequency()));
cnt++;
}
if (cnt >= limit) {
break;
}
}
response.add(key, fieldterms);
}
return response;
}