`
hui_jing_880210
  • 浏览: 42991 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Solr terms使用

    博客分类:
  • solr
阅读更多

这个根据solr提供的terms

实现一:实现商品名称自动联想

 public static List<String> getSearchSuggestHjy(String selectValue,int num){
    	
    	List<String> keyValue = new ArrayList<String>();
    	SolrQuery params = new SolrQuery();
	params.set("qt", "/terms"); 
	params.set("terms.prefix", SolrjQueryValueUtil.escapeQueryChars(selectValue));		
	params.set("terms.fl", "productName");			
	        params.set("terms.mincount", "1");  
	        params.set("terms.maxcount", "100");  
	        params.set("terms.limit", num);  
	params.set("terms.raw", "true");  
	 params.set("terms.sort", "count");  
	params.set("wt","json");
			try {
				QueryResponse response =  server.query(params);
			    if(response != null ){ 
			    	 TermsResponse termsResponse = response.getTermsResponse(); 
			    	 if(termsResponse != null) {  
			                Map<String, List<TermsResponse.Term> > termsMap = termsResponse.getTermMap();  
			                for(Map.Entry<String, List<TermsResponse.Term> > termsEntry : termsMap.entrySet()) {  
			                    List<TermsResponse.Term> termList = termsEntry.getValue();  
			                    for(TermsResponse.Term term : termList) { 
			                    	keyValue.add(term.getTerm().toString());
			                    }  
			                }  
				    }
			    }
			} catch (SolrServerException e) {
				e.printStackTrace();
			}
		return keyValue;
    }

 实现二:TermsComponent数据统计:

首先在solrconfig.xml里面配置

<searchComponent name="terms" class="solr.TermsComponent"/>

  <!-- A request handler for demonstrating the terms component -->
  <requestHandler name="/terms" class="solr.SearchHandler" startup="lazy">
    <lst name="defaults">
        <bool name="terms">true</bool>
        <bool name="distrib">false</bool>
    </lst>
    <arr name="components">
        <str>terms</str>
    </arr>
  </requestHandler>

 通过url连接的方式请求,也可以通过如上的solrj进行查询:

方法1:url方式

http://localhost:8983/solr/test_core/terms?q=*%3A*&wt=json&indent=true&terms.fl=productName

 方式2:

SolrQuery params = new SolrQuery();
	params.set("qt", "/terms"); 	
	params.set("terms.fl", "productName");	
        params.set("index", true);			 
	params.set("wt","json");

 返回结果:默认按结果的出现频率倒序排序。

{
  "responseHeader":{
    "status":0,
    "QTime":31},
  "terms":{
    "field":[
      "新闻图片",4262,
      "专题",4261,
      "设计",3229,
      "凤凰网",2020,
      "凤凰新媒体",1980,
      "创意",1610,
      "艺术",1170,
      "时尚",1128,
      "nba",1025,
      "新闻",940]
    }
}

 

相关参数说明

 

  • erms={true|false} - Turn on the TermsComponent

  • terms.fl={FIELD NAME} - Required. The name of the field to get the terms from. May be specified multiple times as terms.fl=field1&terms.fl=field2...

  • terms.lower={The lower bound term} - Optional. The term to start at. If not specified, the empty string is used, meaning start at the beginning of the field.
  • terms.lower.incl={true|false} - Optional. Include the lower bound term in the result set. Default is true.
  • terms.mincount=<Integer> - Optional. The minimum doc frequency to return in order to be included. Results are inclusive of the mincount (i.e. >= mincount)

  • terms.maxcount=<Integer> - Optional. The maximum doc frequency. Default is -1 to have no upper bound. Results are inclusive of the maxcount (i.e. <= maxcount)

  • terms.prefix={String} - Optional. Restrict matches to terms that start with the prefix.
  • terms.regex={String} - Optional. Restrict matches to terms that match the regular expression. <!> Solr3.1

  • terms.regex.flag={case_insensitive|comments|multiline|literal|dotall|unicode_case|canon_eq|unix_lines} - Optional. Flags to be used when evaluating the regular expression defined in the "terms.regex" parameter (see http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html#compile%28java.lang.String,%20int%29 fore more details). This parameter can be defined multiple times (each time with different flag) <!> Solr3.1

  • terms.limit={integer} - The maximum number of terms to return. The default is 10. If < 0, then include all terms.

  • terms.upper={The upper bound term} - The term to stop at. Either upper or terms.limit must be set.
  • terms.upper.incl={true|false} - Include the upper bound term in the result set. Default is false.
  • terms.raw={true|false} - If true, return the raw characters of the indexed term, regardless of if it is human readable. For instance, the indexed form of numeric numbers is not human readable. The default is false.
  • terms.sort={count|index} - If count, sorts the terms by the term frequency (highest count first). If index, returns the terms in index order. Default is to sort by count.

   terms 详细请参考官方文档:

   http://wiki.apache.org/solr/TermsComponent

分享到:
评论

相关推荐

    apache-solr-ref-guide-7.1.pdf

    最后,“The Terms Component”、“The TermVector Component”、“The Stats Component”、“The Query Elevation Component”等章节,介绍了Solr的高级搜索组件,这些组件增强了Solr的搜索能力,能够处理更复杂、...

    solr千亿检索设计说明.zip

    Lucene的核心概念包括文档(Documents)、字段(Fields)和术语(Terms)。文档是信息的基本单位,字段是文档的组成部分,而术语是经过分析后的关键词。Lucene通过倒排索引(Inverted Index)来加速搜索。 3. **倒...

    Go文本索引库Bleve.zip

    当使用 Java 和 JVM 的时候使用比较多的是 Lucene,Elasticsearch 和 Solr。但是有时候不想要那么多依赖,想要避免外部服务,简单编译部署就可以运行。所以 Couchbase 团队就构建了一个 Go 库,支持大部分 Lucene ...

    ElasticSearch.pdf

    在ES的各种查询中,介绍了term&terms查询、match查询、其他查询方法,以及深分页Scroll和delete-by-query操作。term查询是针对精确关键词的查询,而match查询会根据查询的字段分析文本,将查询文本拆分为多个分词后...

    lucene使用.zip

    4. **术语(Terms)**:是索引的基本单位,是经过分析后的单词或短语。 5. **倒排索引(Inverted Index)**:是 Lucene 的核心数据结构,它将每个术语映射到包含该术语的文档列表,从而实现快速搜索。 **查询处理...

    安装教程总结_Elasticsearch

    searchSourceBuilder.aggregation(AggregationBuilders.terms("top_10_states").field("state").size(10)); SearchRequest searchRequest = new SearchRequest(); searchRequest.indices("social-*"); ...

    Lucene-入门

    开发者也可以利用工具如Solr来简化Lucene的使用。在给定的标签“工具”中,可能是指使用Lucene作为开发搜索引擎的基础工具。 总结,Lucene是构建全文搜索的核心技术,通过理解其基本概念、工作流程和主要组件,...

    Elasticsearch Tutorial

    the terms of the Apache License. Elasticsearch is the most popular enterprise search engine followed by Apache Solr, also based on Lucene. Elasticsearch can be used to search all kinds of documents. ...

    lucene文档,lucene相关文档

    1. 分布式搜索(Solr):Apache Solr基于Lucene,提供分布式、集群化搜索解决方案,适合大型企业级应用。 2. 高亮显示(Highlighting):突出显示搜索结果中匹配的关键词,增强用户体验。 3. 近实时搜索(Near Real-...

    搜索引擎技术教程 网络搜索引擎原理-第7章 Xapian简介 共39页.pptx

    #### 四、Xapian的使用场景 Xapian 适用于多种应用场景,尤其是在需要高性能和复杂搜索需求的情况下: 1. **本地存储大量文本数据**:当系统需要存储并搜索大量的文本数据时,Xapian 是一个理想的选择。 2. **独立...

    Lucene原理与代码分析完整版以及找的一些资料

    用户输入的文本首先经过查询解析器(QueryParser)转化为一系列的查询条款(Query Terms),这些条款可以是单个词汇,也可以是复杂的布尔表达式。然后,这些查询条款与索引中的文档进行匹配,以找到最相关的文档。 ...

    lucene入门指南

    Lucene 可以与其他开源项目结合,如 Solr 提供了 Web 接口和集群支持,Elasticsearch 建立在 Lucene 之上,提供了更高级的分布式搜索和分析功能。 总之,Lucene 是一个强大的搜索引擎框架,通过理解和掌握其核心...

    lucene api

    索引过程中,每个文档会被拆分成单独的术语(Terms),然后这些术语被存储在一个倒排索引(Inverted Index)中,便于快速查找。 2. **Document与Field**:在Lucene中,每个文档(Document)代表一个要索引的信息...

Global site tag (gtag.js) - Google Analytics