-
Notifications
You must be signed in to change notification settings - Fork 3
nd791899/sphinxapi
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Lua SPHINX client driver for ngx_lua based on the cosocket API
USE:
with openresty
location /sphinxtest {
default_type "text/plain";
content_by_lua '
local args = ngx.req.get_uri_args()
if args["key"] == nil then
return
end
local sphinx = require "resty.sphinxapi"
query=args["key"]
local client, err = sphinx.new()
if not client then
ngx.say(err)
return
end
ok,err = client:set_server("192.168.40.29",9312)
if not ok then
ngx.say("connect faile!!",err)
return
end
client:set_match_mode( 6 )
client:set_field_weights( 2, {"title","content"}, {500,1} )
res=client:query(query,"*","")
--ngx.say(string.format("Query %s retrieved %d of %d matches.",query, res.total, res.total_found))
--ngx.say ( "Query stats:" )
--for i=1,res.num_words do
-- ngx.say ( string.format("\t %s found %d times in %d documents",
-- res.words[i].word, res.words[i].hits, res.words[i].docs) )
--end
--ngx.say ( "Matches:" )
--for i=1, res.num_matches do
-- ngx.say("")
-- ngx.say ( string.format("%d. doc_id=%d, weight=%d", i,res.matches[i].doc,res.matches[i].weight) )
-- ngx.say ( "attrs:" );
-- for j=1,res.num_attrs do
-- ngx.say(res.attr_names[j],"=",res.matches[i].attr[j].value)
-- end
--end
local cjson = require "cjson"
ngx.say( cjson.encode(res))
';
}
RESULT:
http://192.168.131.132/sphinxtest?key=Opera
{
words: [
{
word: "opera",
hits: 2,
docs: 1
}
],
matches: [
{
attr: [
{
value: 3
},
{
value: 1270094460
}
],
weight: 499966,
doc: 3
}
],
status: 0,
attr_names: [
"group_id",
"date_added"
],
num_matches: 1,
attr_types: [
1,
2
],
num_words: 1,
fields: { },
num_attrs: 2,
time_msec: 2,
total_found: 1,
num_fields: 2,
total: 1
}
http://192.168.131.132/sphinxtest?key=%E6%8B%AD%E7%9B%AE%E4%BB%A5%E5%BE%85
{
words: [
{
word: "拭目以待",
hits: 1,
docs: 1
}
],
matches: [
{
attr: [
{
value: 2
},
{
value: 1270131607
}
],
weight: 499053,
doc: 1
}
],
status: 0,
attr_names: [
"group_id",
"date_added"
],
num_matches: 1,
attr_types: [
1,
2
],
num_words: 1,
fields: { },
num_attrs: 2,
time_msec: 4,
total_found: 1,
num_fields: 2,
total: 1
}About
sphinx client driver for ngx_lua based on the cosocket API
Resources
Stars
Watchers
Forks
Releases
No releases published