搜索引擎(Solr-搜索詳解)
阿新 • • 發佈:2019-02-27
arch 參與 extend values this none config min 排序 /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:不返回.
學習目標
1.掌握SOLR的搜索工作流程;
2.掌握solr搜索的表示語法及查詢解析器
3.熟悉solr搜索的JSON格式 API
Solr搜索流程介紹
回顧,使用 lucene進行搜索的步驟:
Solr搜索的工作流程
查看內核的solrconfig.xml文件,了解搜索的請求處理器配置
對比看_default、sample_techproducts_configs兩種配置集的內核配置。
配置中的參數元素介紹見下一頁。
仔細查看techproducts 內核的solrconfig.xml的
/select
/query
前面流程圖中的各項工作都在哪裏完成?
在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:不返回.
搜索引擎(Solr-搜索詳解)