當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrQuery.addTermsField方法代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:saschaszott,項目名稱:suma-tech,代碼行數:29,代碼來源:Autocompletion.java

示例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);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:28,代碼來源:TermsResponseTest.java

示例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());
	}
}
 
開發者ID:yiduwangkai,項目名稱:dubbox-solr,代碼行數:6,代碼來源:TermsQueryParser.java


注:本文中的org.apache.solr.client.solrj.SolrQuery.addTermsField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。