搜索引擎(Solr-搜索详解)

  学习目标
  
  1.掌握SOLR的搜索工作流程;
  
  2.掌握solr搜索的表示语法及查询解析器
  
  3.熟悉solr搜索的JSON格式 API
  
  Solr搜索流程介绍
  
  回顾,使用 lucene进行搜索的步骤:
  
  Solr搜索的工作流程
  
  查看内核的solrconfig.xml文件,了解搜索的请求处理器配置
  
  对比看_default、sample_techproducts_configs两种配置集的内核配置。
  
  配置中的参数元素介绍见下一页。
  
  仔细查看techproducts 内核的solrconfig.xml的
  
  /select
  
  /query
  
  /browse
  
  前面流程图中的各项工作都在哪里完成?
  
  在SearchHandler
  
  它是如何完成的?
  
  参数元素说明
  
  SearchHandler介绍
  
  查询请求在SearcheHandler这个request handler中完成,各个步骤的工作由SearchHandler中组合的组件来完成了(可自定义,在该查询的requesthandler配置元素内配置)。示例,自定义组件组合:
  
  <arr name="components">
  
  <str>query</str>
  
  <str>facet</str>
  
  <str>mlt</str>
  
  <str>highlight</str>
  
  <str>debug</str>
  
  <str>someothercomponent</str>
  
  </arr>
  
  "query" (usually QueryComponent)
  
  "facet" (usually FacetComponent)
  
  "mlt" (usually MoreLikeThisComponent)
  
  "highlight" (usually HighlightComponent)
  
  "stats" (usually StatsComponent)
  
  "debug" (usually DebugComponent)
  
  还可在主组件组合前、后加入组件:
  
  <arr name="first-components">
  
  <str>mycomponent</str>
  
  </arr>
  
  <arr name="last-components">
  
  <str>myothercomponent</str>
  
  </arr>
  
  详细了解: https://wiki.apache.org/solr/SearchHandler
  
  问:SearchHandler中配置的 default是做什么用的?
  
  默认参数设置,如果你有这样的默认查询参数需要,可这样配置。
  
  查询语法及解析器详解
  
  通用查询参数详解
  
  1.defType
  
  defType用来选择解析参数q指定的主查询串的查询解析器,如未给定默认使用solr的标准查询解析器(defType=lucene)。
  
  Solr中提供了三种解析器供选择:
  
  lucene:   solr的Standard Query Parser  标准查询解析器
  
  dismax:   DisMax Query Parser
  
  edismax: Extended DisMax Query Parser (eDismax)
  
  2.sort
  
  指定如何对搜索结果进行排序,asc 表示圣墟,desc 降序。Solr可根据如下部分对结果文档进行排序:
  
  文档相关性得分
  
  函数计算的结果
  
  设置了docValues="true"的基本数据类型字段(numerics, string, boolean, dates, etc.)
  
  存储了docValues的可排序分词索引字段(SortableTextFields)。
  
  单值不分词索引的字段。
  
  对于基本数据类型和SortableTextFields ,如果是多值的,排序规则:
  
  升序:取最小值参与排序;
  
  降序:取最大值进行排序;
  
  如要指定用什么值:则在传参时用sort=field(name,max) or sort=field(name,min) 方式传参。
  
  3.start
  
  分页查询的起始行号(从0开始),没传默认为0。
  
  4.rows
  
  查询返回多少行,默认10(可配置)。
  
  5.fq
  
  Filter Query 用来在主查询的结果上进行过滤,不影响相关性评分。Fq对于提速复杂的查询非常有用。因为fq指定的过滤查询结果是独立于主查询被缓存起来的。对于下次查询,如果用到了该过滤查询,则直接从缓存中取出结果进行对主查询的结果进行过滤即可。
  
  fq的传参说明:
  
  可以一次传传多个fq:
  
  fq=popularity:[10 TO *]&fq=section:0
  
  也可将多个过滤条件组合在一个fq:
  
  fq=+popularity:[10 TO *] +section:0
  
  说明:几个fq就缓存几个过滤结果集
  
  6.fl
  
  fl(field list),指定结果中返回哪些字段,指定的字段必须是 stored="true" or docValues="true" 的。多个字段用空格或英文逗号间隔。需要评分时通过 score 指定。如果传人的值为*,则stored="true" or docValues="true" and useDocValuesAsStored="true"的字段都会返回。
  
  7.debug
  
  debug参数用于指定在结果中返回调试信息。
  
  8.explainOther
  
  在一个查询中附带解释另一个查询的评分,在结果中返回它的得分解释。这可以让我们在topN查询时理解为什么某个文档没有返回。
  
  示例:
  
  q=supervillians&debugQuery=on&explainOther=id:juggernaut
  
  9.timeAllowed
  
  限定查询在多少毫秒内返回,如果到时间了还未执行完成,则直接返回部分结果。
  
  10.omitHeader
  
  true/false ,如设为true,在则响应体中忽略表示查询执行状态信息(如耗时)的头。
  
  11.wt
  
  指定响应的内容格式:json、xml、csv……  SearchHandler根据它选择ResponseWriter。
  
  12.cache
  
  设置是否对查询结果、过滤查询的结果进行缓存。默认是都会被缓存的。如果不需要缓存明确设置 cache=false。
  
  13.logParamsList
  
  solr默认会日志记录所有的请求参数,如果不需要记录所有,则通过此参数指定要记录的参数名,如:
  
  logParamsList=q,fq
  
  describe('Array', function() {
  
  before(function() {
  
  // ...
  
  });
  
  describe('#indexOf()', function() {
  
  context('when not present', function() {
  
  it('should not throw an error', function() {
  
  (function() {
  
  [1, 2, 3].indexOf(4);
  
  }.should.not.throw(www.baohuayule.net/));
  
  });
  
  it('should www.fengshen157.com/ return -1', function() {
  
  [1, 2, 3].indexOf(4).should.equal(www.jiahuayulpt.com -1);
  
  });
  
  });
  
  context('when present', function() {
  
  it('should return the index www.zhongyiyuL.cn where the element first appears in the array', function() {
  
  [1, 2, 3].indexOf(3).should.equal(2);
  
  });
  
  });
  
  });
  
  });
  
  TDD
  
  提供的接口有: suite(www.tiaotiaoylzc.com), test(www.yongshiyule178.com), suiteSetup(), suiteTeardown(), setup(), and teardown():
  
  suite('Array', function() {
  
  setup(function() {
  
  // ...
  
  });
  
  suite('#indexOf()', function() {
  
  test('should return -1 when not present', function() {
  
  assert.equal(-1, [1, 2, 3].indexOf(4));
  
  });
  
  });
  
  });
  
  QUNIT
  
  和TDD类似,使用suite()和test()标记测试永烈,包含的接口有:before(), after(), beforeEach(), and afterEach()。
  
  function ok(expr, msg) {
  
  if (!expr) throw new Error(msg);
  
  }
  
  suite('Array');
  
  test('#length', function() {
  
  var arr = [1, 2, 3];
  
  ok(arr.length == 3);
  
  });
  
  test('#indexOf()', function() {
  
  var arr = [1, 2, 3];
  
  ok(arr.indexOf(1) == 0);
  
  ok(arr.indexOf(2) == 1);
  
  ok(arr.indexOf(3) == 2);
  
  });
  
  suite('String'www.yongshi123.cn);
  
  test('#length', function() {
  
  ok('foo'.length =dasheng178.com= www.baohuayule.com 3);
  
  });
  
  如果都不记录:传入: logParamsList=
  
  14.echoParams
  
  指定在响应体的内容的头部中返回哪些查询参数,可选值:
  
  explicit: 默认,返回显示传入的参数+
  
  all: 应用到查询的所有参数.
  
  none:不返回.

猜你喜欢

转载自blog.csdn.net/li123128/article/details/87990133
今日推荐