--- /dev/null
+<samba:parameter name="elasticsearch:force substring search"
+ context="G"
+ type="boolean"
+ xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+ <description>
+ <para>
+ Force string searches in string attributes likes paths to be prefix
+ searches by prefixing a *. Example: a Spotlight search for '*=="samba*"'
+ would be mapped to "'query': '(*samba*)'" instead of "'query':
+ '(samba*)'".
+ </para>
+ </description>
+
+ <value type="default">no</value>
+ <value type="example">yes</value>
+</samba:parameter>
import logging
import json
from http.server import HTTPServer, BaseHTTPRequestHandler
+import samba
from samba.dcerpc import mdssvc
from samba.tests import RpcInterfaceTestCase
from samba.samba3 import mdscli
def setUp(self):
super().setUp()
+ # Build the global inject file path
+ server_conf = samba.tests.env_get_var_value("SERVERCONFFILE")
+ server_conf_dir = os.path.dirname(server_conf)
+ self.global_inject = os.path.join(server_conf_dir, "global_inject.conf")
+
self.pipe = mdssvc.mdssvc('ncacn_np:fileserver[/pipe/mdssvc]', self.get_loadparm())
self.server = HTTPServer(('10.53.57.35', 8080),
r"x\x",
]
self.run_test(sl_query, exp_results, exp_json_query, fake_json_response)
+
+ def test_mdscli_search_force_substring(self):
+ with open(self.global_inject, 'w') as f:
+ f.write("elasticsearch:force substring search = yes\n")
+ os.system("killall -SIGHUP rpcd_mdssvc")
+
+ exp_json_query = r'''{
+ "from": 0, "size": 50, "_source": ["path.real"],
+ "query": {
+ "query_string": {
+ "query": "(*samba*) AND path.real.fulltext:\"%BASEPATH%\""
+ }
+ }
+ }'''
+ fake_json_response = '''{
+ "hits" : {
+ "total" : { "value" : 2},
+ "hits" : [
+ {"_source" : {"path" : {"real" : "%BASEPATH%/foo"}}},
+ {"_source" : {"path" : {"real" : "%BASEPATH%/bar"}}}
+ ]
+ }
+ }'''
+ exp_results = ["foo", "bar"]
+ self.run_test('*=="samba*"', exp_results, exp_json_query, fake_json_response)
+
+ os.remove(self.global_inject)
+ os.system("killall -SIGHUP rpcd_mdssvc")
json_t *mime_map;
bool ignore_unknown_attribute;
bool ignore_unknown_type;
+ bool force_substring_search;
bool type_error;
YY_BUFFER_STATE s;
const char *result;
struct es_parser_state *s = global_es_parser_state;
const char *not = NULL;
const char *end = NULL;
+ const char *force_substring = "";
char *esval = NULL;
char *es = NULL;
DBG_ERR("Mapping fts [%s] unexpected op [%c]\n", val, op);
return NULL;
}
+
+ if (s->force_substring_search) {
+ force_substring = "*";
+ }
+
es = talloc_asprintf(s->frame,
- "%s%s%s",
+ "%s%s%s%s",
not,
+ force_substring,
esval,
end);
if (es == NULL) {
struct es_parser_state *s = global_es_parser_state;
char *esval = NULL;
char *es = NULL;
+ const char *force_substring = "";
const char *not = NULL;
const char *end = NULL;
return NULL;
}
+ if (s->force_substring_search) {
+ force_substring = "*";
+ }
+
es = talloc_asprintf(s->frame,
- "%s%s:%s%s",
+ "%s%s:%s%s%s",
not,
attr->name,
+ force_substring,
esval,
end);
if (es == NULL) {
"elasticsearch",
"ignore unknown type",
false);
+ s.force_substring_search = lp_parm_bool(GLOBAL_SECTION_SNUM,
+ "elasticsearch",
+ "force substring search",
+ false);
global_es_parser_state = &s;
result = mdsyylparse();