11/18/2023 0 Comments Split and conquer![]() ![]() We can convert the tags string into an array of strings and then lookup the value in the array instead of searching within the whole string. Since the predicate is evaluated to be False, nothing is returned. Let’s try to find something that doesn’t exist. SELECT COUNT(*) boolcountĪNY s in SPLIT("CONCURRENCY,MONGODB,COUCHBASE,INDEX,READ,WRITE,PERFORMANCE,SNAPSHOT,CONSISTENCY", ",") Note: System:dual always has a single document with null in it. Once you have an array, you can query the data based on array predicates. SELECT SPLIT("CONCURRENCY,MONGODB,COUCHBASE,INDEX,READ,WRITE,PERFORMANCE,SNAPSHOT,CONSISTENCY", ",") SPLIT() can take any string and a separator, and return array strings. Let’s first look at the SPLIT() function. Now, let's see how N1QL makes this fast, easy, and efficient. While the predicate "%COUCHBASE%" looks for the word COUCHBASE anywhere in the string, it's usually in there as a separate word, tag or label.Īpplications and users typically search for the whole word. Whether you do a primary scan (table scan) or an index scan, this query is going to be slow on a large data set, as it has to scan the entire data set or the index to correctly evaluate the predicate. You need to use the pattern “%COUCHBASE%” because the string pattern could be anywhere within the tags string. In SQL, you can do the following: SELECT title, url FROM articles WHERE tags LIKE “%COUCHBASE%” Ĭreate an index on tags, you get the following plan: CREATE INDEX idx_articles_tags on articles(tags) ĮXPLAIN SELECT title, url FROM articles WHERE tags LIKE "%COUCHBASE%" How do you search for the COUCHBASE tag within the tags? How do you search for a specific string within this “tags”? It's another thing to search for a tag within the string. "title": "Concurrency Behavior: MongoDB vs. "tags": "CONCURRENCY,MONGODB,COUCHBASE,INDEX,READ,WRITE,PERFORMANCE,SNAPSHOT,CONSISTENCY", For this article, tags are: CONCURRENCY, MONGODB, COUCHBASE, INDEX, READ, WRITE, PERFORMANCE, SNAPSHOT, and CONSISTENCY. The best practice for search is to have tags or labels for each article and then search on those tags. For any application, indexing and supporting searching within the full text is a big task. Consider my DZone article: Concurrency Behavior: MongoDB vs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |