iOS - 如何使用 SQLite.swift 进行变音符号不敏感搜索?
<p><p>我正在使用 SQLite.swift。
有什么方法可以在 SQLite 中执行不区分变音符号的 LIKE 查询?例如,这个查询:</p>
<pre><code>SELECT * FROM users WHERE name LIKE "thu%"
</code></pre>
<p>会返回:</p>
<pre><code>thử
thu
thư
etc.
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>来自 <a href="https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#custom-collations" rel="noreferrer noopener nofollow">the documentation</a> :</p>
<blockquote>
<p>We can create custom collating sequences by calling <code>createCollation</code> on a database connection.</p>
<pre><code>try db.createCollation("NODIACRITIC") { lhs, rhs in
return lhs.compare(rhs, options: .DiacriticInsensitiveSearch)
}
</code></pre>
<p>We can reference a custom collation using the <code>Custom</code> member of the <code>Collation</code> enumeration.</p>
<pre><code>restaurants.order(collate(.Custom("NODIACRITIC"), name))
// SELECT * FROM "restaurants" ORDER BY "name" COLLATE "NODIACRITIC"
</code></pre>
</blockquote>
<p>在您的情况下,您可以在之后执行以下查询:</p>
<pre><code>SELECT * FROM users WHERE name COLLATE NODIACRITIC LIKE 'thu%'
</code></pre></p>
<p style="font-size: 20px;">关于iOS - 如何使用 SQLite.swift 进行变音符号不敏感搜索?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34051832/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34051832/
</a>
</p>
页:
[1]