-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2016-03-31-db-text-search.html.markdown.erb
More file actions
45 lines (39 loc) · 2.18 KB
/
Copy path2016-03-31-db-text-search.html.markdown.erb
File metadata and controls
45 lines (39 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
title: Database-agnostic case-insensitive equality, full text search
date: "2016-03-31 03:00 CET"
tags: ruby, databases
published: true
---
Different relational databases treat text search very differently.
The new [DbTextSearch gem][dbts] provides a unified interface on top of ActiveRecord for SQLite, MySQL, and
PostgreSQL to do:
* Case-insensitive string-in-set querying, and CI index creation.
* Basic full-text search for a list of terms, and FTS index creation.
[DbTextSearch][dbts] does all the heavy lifting under the hood, hiding the complexity of handling each
database differently away, which is great for gem authors, when migrating an application from one database to another,
or writing code that must support multiple databases.
READMORE
Here is how [db_text_search][dbts] handles different types of columns in different databases for case-insensitive comparisons:
<div class="table-responsive">
<table style="font-size: 16px; border: 0" class="table table-striped table-sm table-center-cells table-bordered">
<caption><a href="https://github.com/thredded/db_text_search">DbTextSearch</a> case-insensitive string matching methods</caption>
<thead>
<tr><th style="vertical-align: bottom" rowspan="2">Column type</th><th colspan="2">SQLite</th><th colspan="2">MySQL</th><th colspan="2">PostgreSQL</th></tr>
<tr><th>Detected types</th><th>Search / index</th><th>Detected types</th><th>Search / index</th><th>Detected types</th><th>Search / index</th></tr>
</thead>
<tbody style="text-align: center">
<tr><th>Case-insensitive</th>
<td rowspan="2">always treated as case-sensitive</td> <td rowspan="2"><code>COLLATE NOCASE</code></td>
<td><i>default</i></td> <td><i>default</i></td>
<td><code>CITEXT</code></td> <td><i>default</i></td>
</tr>
<tr><th>Case-sensitive</th>
<td>non-<code>ci</code> collations</td> <td><code>LOWER</code><br><b>no index</b></td>
<td><i>default</i></td> <td><code>LOWER</code></td>
</tr>
</tbody>
</table>
</div>
Full-text search is even more gnarly. Great that you don't have to worry about that if you use this gem!
Check it out and learn more on [github.com/thredded/db_text_search][dbts].
[dbts]: https://github.com/thredded/db_text_search