-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicode collation #1162
Comments
If what you need is to make text searches "accent-insensitive" (or any weird character-insensitive... like allow german users to search indifferently for "große" or "grosse"), I have done it in my custom version of sqlite-net (this feature is not available in my github repository.. it is currently in the private repository of my company). what I did is to use Unidecode.NET (see my version published here https://github.com/csm101/Unidecode.NET/tree/array_instead_of_dictionary.. this one fixes the two open issues in the official repository and has a 3X performance improvement... I have issued a pull request but I haven't received any feedback yet) I used this library to implement a custom sqlite Unidecode function, so to implement accent insensitive searches i do this: conn.Query<MyRecord>("select * from mytable where Unidecode(germanfield) like '%'||?||'%'", "große".Unidecode()) (in my customized sqlite-net there is a mechanism for registering sqlite functions implemented in c#) If there is some interest about this, I could try to extract the relevant code from my private repository and issue a pull request... |
@csm101
This is obviously hugely inefficient so it would be great if the database could perform this operation. |
I have no knowledge about chinese: my target languages were only european languages and cirillyc, have a look at this translation table here (from my version of unicode): Does this conversion map address mandarin (I have no idea)? Anyway you could still implement your own "MandarinLike()" sql function in c#... I made it pretty simple to do in my sqlite version: this is how, for example I added a "GPSDistance(lat1,long2, lat2, long2)" function that calculates the distance in meters between two gps coordinates: public class SQLiteGPSDistanceFunction : SQLiteFunction
{
public SQLiteGPSDistanceFunction(SQLiteConnection connection)
: base(connection, FunctionName: "GPSDistance", ArgumentCount: 4, Deterministic: true)
{
}
public override void Execute(SqliteFunctionRunContext ctx)
{
if ( ctx.IsNull(0) || ctx.IsNull(1) || ctx.IsNull(2)|| ctx.IsNull(3))
{
ctx.SetNullResult();
return;
}
var latit1 = ctx.DoubleParam(0);
var longit1 = ctx.DoubleParam(1);
var latit2 = ctx.DoubleParam(2);
var longit2 = ctx.DoubleParam(3);
double distance = CoordinatesFunctions.Distance(latit1, longit1, latit2, longit2);
ctx.SetResult(distance);
}
} and I also added a static global event handler to register these functions whenever a sqlite connection connects to any database: SQLiteConnection.AfterLogon +=
(connection, args) =>
{
_ = new SQLiteUnidecodeFunction(connection);
_ = new SQLiteGPSDistanceFunction(connection);
}; I addressed only simple functions, but sqlite apis would allow me to implement also custom aggregate functions (like count(), max) or even custom analytic functions (select count(*) over (partition by field1, field2, order by ...) ) |
and... since I managed to get the attention of an author of the project.. would you mind reviewing my pull request for cancellable queries? #1176 Actually I needed to be able to cancel long running queries for the same implementation I needed this Unidecode function, that is: to implement this kind of search dialog in android: |
Sorry I'm not an author on the project, when I said I would be happy to review your pull request, I mean I can read it, but I don't think I'm able to approve it into the repo. |
My bad, I tought you had write access to the repository and you could approve pull requests, return await _database.Query("select * from sentences s where MandarinEquals(s.Mandarin, ?) = true")); |
When specifying the SQLite.CollationAttribute on columns, we only have the options BINARY, NOCASE and RTRIM. There is no Unicode collation option. Is it possible to create a custom collation or any other way to make WHERE queries work on unicode values?
The text was updated successfully, but these errors were encountered: