Could you please explain what will be problem.
Example: LOWER(fname) present in the ARRAY return results.
WHERE type = “P” AND LOWER(fname) IN [“abc”,“bdd”]
If you want supply search value as array you need to use different index because array index doesn’t match because of two any clauses one of the any has search value IN [“a%”,“b%”] .
You never posted complete query. Post complete query and Couchbase version and will recommend best index.
Other option is separate search elements separate instead of array. Is LIKE “a%”, wildcard only on trailing or do you need “%a%”
then i have some words or characters
example
[“owner”,“d”]
its my index query maybe its doesnt work
CREATE INDEX idx_fname_suffix1
ON db(DISTINCT ARRAY s FOR s IN SUFFIXES(LOWER(fname)) OR SUFFIXES(LOWER(lname)) END)
WHERE type = “P”;
and this is my search query
SELECT DISTINCT db.* FROM db USE INDEX(idx_fname_suffix1) WHERE type = “P” AND ANY z IN [LOWER(fname),LOWER(lname)] SATISFIES (ANY v IN [“owner%”,“d%”] SATISFIES z LIKE v END) END;
i want to search on some area (“fname”,“lname”) with like method also i want query can easy developable (maybe i use wrong word) because in future i have to include “more area” for search or more search word([“owner%”,“d%”,"%st%"])
thats my question im sorry for bad language
if there are any easier way or other methods have,please tell me.
thanks @vsr1
Based on the input you passed requirement the following index and query is right one.
CRATE INDEX ix10 ON db(type,LOWER(fname),LOWER(lname));
SELECT db.* FROM (SELECT RAW META().id FROM db USE INDEX(ix10) WHERE type = "P" AND ANY z IN [LOWER(fname),LOWER(lname)] SATISFIES (ANY v IN ["owner%","d%"] SATISFIES z LIKE v END) END) AS q JOIN db ON KEYS q;
SELECT db.*, (ANY v IN ["owner%","d%"] SATISFIES LOWER(db.fname) LIKE v END) AS fname_matched, (ANY v IN ["owner%","d%"] SATISFIES LOWER(db.fname) LIKE v END) AS lname_matched FROM (SELECT RAW META().id FROM db USE INDEX(ix10) WHERE type = "P" AND ANY z IN [LOWER(fname),LOWER(lname)] SATISFIES (ANY v IN ["owner%","d%"] SATISFIES z LIKE v END) END) AS q JOIN db ON KEYS q;
i read pdf all of night
if i need use like %?% can i use same index or need create suffixes index (i seen it pdf example so i m confused)
sorry about a lot question but im tryinng understand it
thank you
Based on your requirements. Only type = “P” can be pushed indexer and all other predicates applied later. above index will work for your case.
FYI: In N1QL Percent (%) matches any string of zero or more characters; underscore (_) matches any single
character. The wildcards can be escaped by preceding them with a backslash (). Backslash itself can also
be escaped by preceding it with another backslash.
To match any name any where in the document . Try WITHIN.
INSERT INTO default VALUES("001", { "fname":"owner", "main":{ "ls":{ "name":"name", "enddate":"2018" }, "uns":[ { "name":"name1","enddate":"2015" }, {"name":"name2", "enddate":"2019" } ] } });
SELECT META(d).id FROM default d WHERE ANY v WITHIN d SATISFIES v.name = "name1" END;
@vsr1
as you know, I use the query you gave above
so when i use with within , it still doesnt work
here you query
SELECT db.*, (ANY v IN [“owner%”,“d%”] SATISFIES LOWER(db.fname) LIKE v END) AS fname_matched, (ANY v IN [“owner%”,“d%”] SATISFIES LOWER(db.fname) LIKE v END) AS lname_matched FROM (SELECT RAW META().id FROM db USE INDEX(ix10) WHERE type = “P” AND ANY z IN [LOWER(fname),LOWER(lname)] SATISFIES (ANY v IN [“owner%”,“d%”] SATISFIES z LIKE v END) END) AS q JOIN db ON KEYS q;
new verision
SELECT db.* FROM (SELECT RAW META().id FROM db USE INDEX(ix10) WHERE type = “P” AND ANY z WITHIN [LOWER(fname),LOWER(lname),LOWER(name)] SATISFIES (ANY v IN [“owner%”,“d%”] SATISFIES z LIKE v END) END) AS q JOIN db ON KEYS q;
also i tried using LOWER(main) ,LOWER(main.ls.name) instead of LOWER(name)