绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
riak search
2022-05-24 14:31:22

现在search查询还是空

Simon 11:53:44

这数据库太新,不好把握,还是用成熟一点的比较好吧

建完bucket,附带了precommit属性,才会建索引

之前的数据是查不出的

Simon 11:54:59

索引里面没有

建索引的时候不会遍历老数据

Android郎哲<langxianzhe@163.com> 11:55:30

我发你我创建的过程你看看,哪里不对



Android郎哲<langxianzhe@163.com> 11:57:56



Client:set_bucket(<<"g2">>,[{precommit, [{struct,[{<<"mod">>,<<"riak_search_kv_hook">>},{<<"fun">>,<<"precommit">>}]}]}]).

第二步

f(O0),O0 = riak_object:new(<<"g2">>, <<"mine">>, <<"bread">>).

第三步

(riak@127.0.0.1)108> C:put(O0).

ok



我的理解是以上三步就可以完成了

Android郎哲<langxianzhe@163.com> 11:59:36

以下是执行

search的结果

(riak@127.0.0.1)109> search:search_doc(<<"g2">>, <<"bread">>)

(riak@127.0.0.1)109> .

{1,"0.353553",

[{riak_idx_doc,<<"g2">>,<<"mine">>,

[{<<"value">>,<<"bread">>,[{<<"bread">>,[0]}]}],

[],[],true}]}

(riak@127.0.0.1)110> search:search_doc(<<"g2">>, <<"bre">>)

(riak@127.0.0.1)110> .

{0,"0.0",[]}

(riak@127.0.0.1)111> search:search_doc(<<"g2">>)

(riak@127.0.0.1)111> .

{0,"0.0",[]}

(riak@127.0.0.1)112> search:search(<<"g2">>, <<"bread">>)

(riak@127.0.0.1)112> .

{1,

[{<<"g2">>,<<"mine">>,

[{p,[0]},{score,0.35355339059327373}]}]}

(riak@127.0.0.1)113> search:search(<<"g2">>, "bread")

(riak@127.0.0.1)113> .

{1,

[{<<"g2">>,<<"mine">>,

[{p,[0]},{score,0.35355339059327373}]}]}

(riak@127.0.0.1)114> search:search(<<"g2">>, "bre")

(riak@127.0.0.1)114> .

{0,[]}

(riak@127.0.0.1)115> search:search(<<"g2">>)

(riak@127.0.0.1)115> .

{0,[]}





Android郎哲<langxianzhe@163.com> 12:01:15

为什么 search:search(<<"g2">>)和search:search_doc(<<"g2">>) 返回是空的

Simon 12:01:46

不是已经能查出来了吗

(riak@127.0.0.1)112> search:search(<<"g2">>, <<"bread">>)

(riak@127.0.0.1)112> .

{1,

[{<<"g2">>,<<"mine">>,

[{p,[0]},{score,0.35355339059327373}]}]}



Android郎哲<langxianzhe@163.com> 12:02:44

这个是根据具体的key查出来的,模糊的key还查不出来

Simon 12:03:02

模糊查询?

Android郎哲<langxianzhe@163.com> 12:03:07



这个不是全文检索功能吗

Simon 12:03:45

试试<<"bre*">>

Android郎哲<langxianzhe@163.com> 12:04:54

<<"bre*">>

可以查出

<<"*re*">>查不出



Simon 12:05:26

我想起来了,反向索引就是用bread这个值建了一个key

Android郎哲<langxianzhe@163.com> 12:05:41

什么意思请详解

Simon 12:05:54

然后把值为bread的key当成一个列表存起来

底层原理就是这样

Android郎哲<langxianzhe@163.com> 12:07:48

你是说它把存储的value当做key索引存储了一边

Simon 12:07:58

让我哭的就是,你想查出值为bread的所有记录,他只是返回key列表,你还得根据这个列表挨个找出value

是的

Android郎哲<langxianzhe@163.com> 12:09:05

再根据Key查找value也好,

<<*re*>>

查不出来如何解释

Simon 12:12:32

一个桶的底层存储结构是这样:

key value

{key, <<"g2">>, <<"mine">>} <<"bread">>

{key, <<"g2">>, <<"you">>} <<"bread">>

{index, <<"g2">>, <<"bread">>} [<<"mine">>,<<"you">>]

只是示意一下,实际的你得看key的组成规则

Android郎哲<langxianzhe@163.com> 12:15:10

嗯明白

Android郎哲<langxianzhe@163.com> 12:16:24

search:search(<<"g2">>)查询为什么查询不到索引呢, 现在仍然是空

(riak@127.0.0.1)144> search:search(<<"g2">>).

{0,[]}





-----26> riakc_pb_socket:search(Pid,<<"g2">>, list_to_binary("<<\"orange\">>:<<\"bread\">>"),[],5000).

{ok,{search_results,[{<<"g2">>,

[{<<"id">>,<<"mine">>},{<<"value">>,<<"bread">>}]},

{<<"g2">>,

[{<<"id">>,<<"your">>},{<<"value">>,<<"orange">>}]}],

0.07724899798631668,2}}

27>

27> riakc_pb_socket:search(Pid,<<"g2">>, list_to_binary("<<\"orange\">><<\"bread\">>"),[],5000).

{ok,{search_results,[{<<"g2">>,

[{<<"id">>,<<"mine">>},{<<"value">>,<<"bread">>}]},

{<<"g2">>,

[{<<"id">>,<<"your">>},{<<"value">>,<<"orange">>}]}],

0.07724899798631668,2}}





* 2: syntax error before: '.'

35> riakc_pb_socket:search(Pid,<<"g2">>, list_to_binary("orangebread"),[],5000).

{ok,{search_results,[],0.0,0}}

36> riakc_pb_socket:search(Pid,<<"g2">>, list_to_binary("orange\"\"bread"),[],5000).

{ok,{search_results,[{<<"g2">>,

[{<<"id">>,<<"mine">>},{<<"value">>,<<"bread">>}]},

{<<"g2">>,

[{<<"id">>,<<"your">>},{<<"value">>,<<"orange">>}]}],

0.2959290146827698,2}}





53> riakc_pb_socket:search(Pid,<<"g2">>, "br*\"\"or*").

{ok,{search_results,[{<<"g2">>,

[{<<"id">>,<<"mine">>},{<<"value">>,<<"bread">>}]},

{<<"g2">>,

[{<<"id">>,<<"your">>},{<<"value">>,<<"orange">>}]}],

0.0,2}}

54>





73> riakc_pb_socket:search(Pid,<<"g2">>, HerBin).

{ok,{search_results,[{<<"g2">>,

[{<<"id">>,<<"her">>},

{<<"value">>,

<<131,108,0,0,0,2,104,2,107,0,4,110,97,109,101,107,0,

2,...>>}]}],

0.35355299711227417,1}}

74> HerBin.

<<131,108,0,0,0,2,104,2,107,0,4,110,97,109,101,107,0,2,

120,119,104,2,107,0,1,115,107,0,1,...>>

75> binary_to_term(HerBin).

[{"name","xw"},{"s","d"}]

76> riakc_pb_socket:search(Pid,<<"g2">>, HerBin).

{ok,{search_results,[{<<"g2">>,

[{<<"id">>,<<"her">>},

{<<"value">>,

<<131,108,0,0,0,2,104,2,107,0,4,110,97,109,101,107,0,

2,...>>}]}],

0.35355299711227417,1}}

77>



--------------------------------

(riak@127.0.0.1)43> lucene_scan:string("name:jason").

{ok,[{string,1,"name"},{scope,1,":"},{string,1,"jason"}],1}

(riak@127.0.0.1)45> lucene_scan:string("namejason*").

{ok,[{wildcard_glob,1,"namejason*"}],1}



[{'query',[{wildcard_glob,1,"namejason*"}]}, {'filter', []}];

[{'query', QueryOps}, {'filter', FilterOps}];







-----------------------------9> riakc_pb_socket:put(Pid,O).

ok

50> riakc_pb_socket:list_buckets(Pid).

{ok,[<<"user">>]}

51> riakc_pb_socket:set_bucket(Pid, <<"user">>, [{precommit, [{struct,[{<<"mod">>,<<"riak_search_kv_hook">>},{<<"fun">>,<<"precommit">>}]}]}]).

ok

52> riakc_pb_socket:list_buckets(Pid).

{ok,[<<"user">>]}

53> f(O),O=riakc_obj:new(<<"user">>, <<"jason">>, list_to_binary("[{\"name\":\"jason\"},{\"sex\":\"male\"}]"), "application/json").

{riakc_obj,<<"user">>,<<"jason">>,undefined,[],

{dict,1,16,16,8,80,48,

{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},

{{[],[],[],[],[],[],[],[],[],[],[[<<...>>|...]],[],[],...}}},

<<"[{\"name\":\"jason\"},{\"sex\":\"male\"}]">>}

54> riakc_pb_socket:put(Pid,O).

ok

55> riakc_pb_socket:list_buckets(Pid).

{ok,[<<"user">>]}

56> riakc_pb_socket:set_bucket(Pid, <<"user">>, [{precommit, [{struct,[{<<"mod">>,<<"riak_search_kv_hook">>},{<<"fun">>,<<"precommit">>}]}]}]).

ok

57> riakc_pb_socket:set_bucket(Pid, <<"users">>, [{precommit, [{struct,[{<<"mod">>,<<"riak_search_kv_hook">>},{<<"fun">>,<<"precommit">>}]}]}]).

ok

58> f(O),O=riakc_obj:new(<<"users">>, <<"jason">>, list_to_binary("[{\"name\":\"jason\"},{\"sex\":\"male\"}]"), "application/json").

{riakc_obj,<<"users">>,<<"jason">>,undefined,[],

{dict,1,16,16,8,80,48,

{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},

{{[],[],[],[],[],[],[],[],[],[],[[<<...>>|...]],[],[],...}}},

<<"[{\"name\":\"jason\"},{\"sex\":\"male\"}]">>}

59> riakc_pb_socket:put(Pid,O).

ok

60> f(O),O=riakc_obj:new(<<"user2">>, <<"jason">>, list_to_binary("[{\"name\":\"jason\"},{\"sex\":\"male\"}]"), "application/json").

{riakc_obj,<<"user2">>,<<"jason">>,undefined,[],

{dict,1,16,16,8,80,48,

{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},

{{[],[],[],[],[],[],[],[],[],[],[[<<...>>|...]],[],[],...}}},

<<"[{\"name\":\"jason\"},{\"sex\":\"male\"}]">>}

61> riakc_pb_socket:put(Pid,O).

ok

62> riakc_pb_socket:search(Pid, <<"users">>, "sdf").

{ok,{search_results,[],0.0,0}}

63> riakc_pb_socket:search(Pid, <<"users">>, "name:jason").

{ok,{search_results,[],0.0,0}}

64> riakc_pb_socket:search(Pid, <<"users">>, <<"name:jason">>).

{ok,{search_results,[],0.0,0}}

65> riakc_pb_socket:search(Pid, <<"users">>, "\"name\":\"jason\"").

{ok,{search_results,[],0.0,0}}

66> riakc_pb_socket:search(Pid, <<"users">>, list_to_binary("\"name\":\"jason\"")).

{ok,{search_results,[],0.0,0}}

67> riakc_pb_socket:search(Pid, <<"user3">>, list_to_binary("\"name\":\"jason\"")).

{ok,{search_results,[],0.0,0}}

68> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("\"name\":\"jason\"")).

{ok,{search_results,[{<<"user2">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.35355299711227417,1}}

69> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("\"sex\":\"male\"")).

{ok,{search_results,[{<<"user2">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.35355299711227417,1}}

70> riakc_pb_socket:search(Pid, <<"users">>, "\"name\":\"jason\"").

{ok,{search_results,[],0.0,0}}

71> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("\"name\":\"jason\"")).

{ok,{search_results,[{<<"user2">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.35355299711227417,1}}

72> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("\"sex\":\"male\"")).

{ok,{search_results,[{<<"user2">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.35355299711227417,1}}

73> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("\"sex\":\"mal*\"")).

{ok,{search_results,[],0.0,0}}

74> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("\"sex\":\"male\"")).

{ok,{search_results,[{<<"user2">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.35355299711227417,1}}

sss

-----------------------------------------------模糊匹配查询-------------------------------------------



(ejabberd@meta)56> riakc_pb_socket:search(Pid, <<"user1">>, list_to_binary("\"name\":\"jaso*\"")).

{ok,{search_results,[],0.0,0}}

(ejabberd@meta)57> riakc_pb_socket:search(Pid, <<"user1">>, list_to_binary("\"name\":jason*")).

{ok,{search_results,[{<<"user1">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.0,1}}

(ejabberd@meta)58> riakc_pb_socket:search(Pid, <<"user1">>, list_to_binary("\"name\":ja*")).

{ok,{search_results,[{<<"user1">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.0,1}}

(ejabberd@meta)59> riakc_pb_socket:search(Pid, <<"user1">>, list_to_binary("\"name\":*")).

{ok,{search_results,[],0.0,0}}

(ejabberd@meta)60> riakc_pb_socket:search(Pid, <<"user1">>, list_to_binary("\"name\":j*")).

{ok,{search_results,[],0.0,0}}

(ejabberd@meta)61> riakc_pb_socket:search(Pid, <<"user1">>, list_to_binary("\"name\":ja*")).

{ok,{search_results,[{<<"user1">>,

[{<<"id">>,<<"jason">>},

{<<"name">>,<<"jason">>},

{<<"sex">>,<<"male">>}]}],

0.0,1}}

(ejabberd@meta)62>

---------------------------------------

riak search 查询中文问题,查了好多资料也没有解决,后我不得不把所有字段用base64来编码,查询也是把条件编码完在查询的
————————————————
版权声明:本文为CSDN博主「langxianwu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/langxianwu/article/details/84298759

分享好友

分享这个小栈给你的朋友们,一起进步吧。

Riak KV
创建时间:2022-04-19 09:50:17
Riak KV
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • 飘絮絮絮丶
    专家
戳我,来吐槽~