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


Java Term类代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.response.TermsResponse.Term的典型用法代码示例。如果您正苦于以下问题:Java Term类的具体用法?Java Term怎么用?Java Term使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Term类属于org.apache.solr.client.solrj.response.TermsResponse包,在下文中一共展示了Term类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertTermsQueryResponseToTermsMap

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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 (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;
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:22,代码来源:ResultHelper.java

示例2: convertTermsQueryResponseToTermsMap

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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;
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:22,代码来源:ResultHelper.java

示例3: testConvertTermsQueryResponseReturnsTermsMapCorrectlyWhenOneFieldReturned

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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());
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:19,代码来源:ResultHelperTests.java

示例4: getInstitutions

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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);
}
 
开发者ID:OpenGeoportal,项目名称:ogpHarvester,代码行数:24,代码来源:SolrJClient.java

示例5: complete

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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

示例6: testTermsResponse

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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

示例7: testConvertTermsQueryResponseReturnsTermsMapCorrectlyWhenMultipleFieldsReturned

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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());
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:15,代码来源:ResultHelperTests.java

示例8: suggestTermByField

import org.apache.solr.client.solrj.response.TermsResponse.Term; //导入依赖的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);
  }
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:22,代码来源:OccurrenceSearchImpl.java


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