当前位置: 首页>>代码示例>>Java>>正文


Java TermsResponse.Term方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:29,代码来源:Autocompletion.java

示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:TermsComponent.java

示例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 );
      }
    }
  }
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:15,代码来源:QueryAutoFilteringComponent.java

示例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);
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:TermsComponent.java

示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:TermsComponent.java

示例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);
}
 
开发者ID:safarijv,项目名称:ifpress-solr-plugin,代码行数:10,代码来源:FieldMergingProcessorTest.java

示例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 );
    }
  }
 
开发者ID:detnavillus,项目名称:multifield_suggester_code,代码行数:51,代码来源:TermVectorQueryCollector.java

示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:57,代码来源:TermsComponent.java

示例9: TermsHelper

import org.apache.solr.client.solrj.response.TermsResponse; //导入方法依赖的package包/类
public TermsHelper() {
  fieldmap = new HashMap<String, HashMap<String, TermsResponse.Term>>(5);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:4,代码来源:TermsComponent.java

示例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;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:57,代码来源:TermsComponent.java


注:本文中的org.apache.solr.client.solrj.response.TermsResponse.Term方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。