Spaces in the search string

Alexander Sicular siculars at basho.com
Wed Sep 7 09:06:43 EDT 2016


Hi Sean, Familiarize yourself with the default schema[0], if that is what
you're using. Also check details around this specific type of search around
the web[1].

Let us know how it shakes out,
-Alexander


[0]
https://raw.githubusercontent.com/basho/yokozuna/develop/priv/default_schema.xml
[1]
http://stackoverflow.com/questions/10023133/solr-wildcard-query-with-whitespace


On Wednesday, September 7, 2016, sean mcevoy <sean.mcevoy at gmail.com> wrote:

> Hi again!
>
> Apologies for the premature post earlier. I thought I had a solution when
> I didn't get the error but when I got around to plugging it into my
> application it's still not doing everything that I need.
> I've narrowed it down to this minimal testcase, first setup the index &
> insert the data:
>
>
> {ok,Pid} = riakc_pb_socket:start("127.0.0.1", 10017).
> ok = riakc_pb_socket:create_search_index(Pid, <<"test_index">>,
> <<"_yz_default">>, []).
> ok = riakc_pb_socket:set_search_index(Pid, <<"test_bucket">>,
> <<"test_index">>).
> RO = riakc_obj:new(<<"test_bucket">>, <<"test_key">>, <<"{\"name_s\":\"my
> test name\",\"age_i\":2}">>, "application/json").
> ok = riakc_pb_socket:put(Pid, RO).
>
>
> Now I can get the hit when search for a partial name with wildcards & no
> escapes or spaces:
> 521>
> 521> riakc_pb_socket:search(Pid, <<"test_index">>, <<"name_s:*test* AND
> age_i:2">>, []).
> {ok,{search_results,[{<<"test_index">>,
>                       [{<<"score">>,<<"1.22776079999999998549e+00">>},
>                        {<<"_yz_rb">>,<<"test_bucket">>},
>                        {<<"_yz_rt">>,<<"default">>},
>                        {<<"_yz_rk">>,<<"test_key">>},
>                        {<<"_yz_id">>,<<"1*default*
> test_bucket*test_key*57">>},
>                        {<<"name_s">>,<<"my test name">>},
>                        {<<"age_i">>,<<"2">>}]}],
>                     1.2277607917785645,1}}
>
>
> And I can get the hit when I search for the full name with spaces & the
> escaped quotes:
> 522>
> 522> riakc_pb_socket:search(Pid, <<"test_index">>, <<"name_s:\"my test
> name\" AND age_i:2">>, []).
> {ok,{search_results,[{<<"test_index">>,
>                       [{<<"score">>,<<"1.00736960000000008719e+00">>},
>                        {<<"_yz_rb">>,<<"test_bucket">>},
>                        {<<"_yz_rt">>,<<"default">>},
>                        {<<"_yz_rk">>,<<"test_key">>},
>                        {<<"_yz_id">>,<<"1*default*
> test_bucket*test_key*58">>},
>                        {<<"name_s">>,<<"my test name">>},
>                        {<<"age_i">>,<<"2">>}]}],
>                     1.0073696374893188,1}}
>
>
> But how can I search for a partial name with spaces:
> 523>
> 523> riakc_pb_socket:search(Pid, <<"test_index">>, <<"name_s:\"*y test
> na*\" AND age_i:2">>, []).
> {ok,{search_results,[],0.0,0}}
> 524>
> 524>
>
>
> I get the feeling that I'm missing something really obvious but can't see
> it. Any more pointers appreciated!
>
> //Sean.
>
>
> On Wed, Sep 7, 2016 at 10:11 AM, sean mcevoy <sean.mcevoy at gmail.com
> <javascript:_e(%7B%7D,'cvml','sean.mcevoy at gmail.com');>> wrote:
>
>> Hi Jason,
>>
>> Thanks for the kick, I just needed to look closer!
>> Yes, had tried escaping but one of my utility functions for dynamically
>> building the search string had been stripping it out again. D'oh!
>>
>> Curiously, just escaping the space doesn't work as in the example in the
>> stackoverflow post.
>> Putting the search term in an inner string and escaping its quotes both
>> feels more natural and does work so I'm going with something more like:
>>
>> 409>
>> 409>
>> 409> riakc_pb_socket:search(Pid, <<"test_index">>, <<"name_s:\"we rt\"
>> AND age_i:0">>, []).
>> {ok,{search_results,[],0.0,0}}
>> 410>
>> 410>
>> 410> riakc_pb_socket:search(Pid, <<"test_index">>, <<"name_s:we\ rt AND
>> age_i:0">>, []).
>> {error,<<"Query unsuccessful check the logs.">>}
>> 411>
>> 411>
>>
>> Cheers,
>> //Sean.
>>
>>
>> On Tue, Sep 6, 2016 at 2:48 PM, Jason Voegele <jvoegele at basho.com
>> <javascript:_e(%7B%7D,'cvml','jvoegele at basho.com');>> wrote:
>>
>>> Hi Sean,
>>>
>>> Have you tried escaping the space in your query?
>>>
>>> http://stackoverflow.com/questions/10023133/solr-wildcard-qu
>>> ery-with-whitespace
>>>
>>>
>>> On Sep 5, 2016, at 6:24 PM, sean mcevoy <sean.mcevoy at gmail.com
>>> <javascript:_e(%7B%7D,'cvml','sean.mcevoy at gmail.com');>> wrote:
>>>
>>> Hi List,
>>>
>>> We have a solr index where we store something like:
>>> <<"{\"key_s\":\"ID\",\"body_s\":\"some test string\"}">>}],
>>>
>>> Then we try to do a riakc_pb_socket:search with the pattern:
>>> <<"body_s:*test str*">>
>>>
>>> The request will fail with an error message telling us to check the logs
>>> and in there we find:
>>>
>>> 2016-09-05 13:37:29.271 [error] <0.12067.10>@yz_pb_search:maybe_process:107
>>> {solr_error,{400,"http://localhost:10014/internal_solr/crm_d
>>> b.campaign_index/select",<<"{\"error\":{\"msg\":\"no field name
>>> specified in query and no default specified via 'df'
>>> param\",\"code\":400}}\n">>}} [{yz_solr,search,3,[{file,"src
>>> /yz_solr.erl"},{line,284}]},{yz_pb_search,maybe_process,3,[{
>>> file,"src/yz_pb_search.erl"},{line,78}]},{riak_api_pb_server
>>> ,process_message,4,[{file,"src/riak_api_pb_server.erl"},{
>>> line,388}]},{riak_api_pb_server,connected,2,[{file,"src/
>>> riak_api_pb_server.erl"},{line,226}]},{riak_api_pb_server,de
>>> code_buffer,2,[{file,"src/riak_api_pb_server.erl"},{line,
>>> 364}]},{gen_fsm,handle_msg,7,[{file,"gen_fsm.erl"},{line,
>>> 505}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]
>>>
>>>
>>> Through experiment I've figured out that it doesn't like the space as it
>>> seems to think the part of the search string after that space is a new key
>>> to search for. Which seems fair enough.
>>>
>>> Anyone know of a work-around? Or am I formatting my request incorrectly?
>>>
>>> Thanks in advance.
>>> //Sean.
>>>
>>> _______________________________________________
>>> riak-users mailing list
>>> riak-users at lists.basho.com
>>> <javascript:_e(%7B%7D,'cvml','riak-users at lists.basho.com');>
>>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> riak-users mailing list
>>> riak-users at lists.basho.com
>>> <javascript:_e(%7B%7D,'cvml','riak-users at lists.basho.com');>
>>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>>>
>>>
>>
>

-- 


Alexander Sicular
Solutions Architect
Basho Technologies
9175130679
@siculars
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20160907/b6858c01/attachment-0002.html>


More information about the riak-users mailing list