Actually, i have an entry in my db of title "You’re Accepted to College, Now What: Deciding Upon...".
So when user types "you'are accepted...." it doesn't match with the above because of the special character ’.
What should be done for such type of characters.
Thanks in advance. :)
So in the case that you do have the apostrophe within your database in all places, so that there is no record that has a quote instead, I'd just correct the queries via gsub so that they contain the correct quote.
The true, nice and elegant solution would be to add a collation to your database server. The collation is what makes the database return 1 for SELECT 'ä' LIKE 'a'. Unfortunately, neither utf8_general_ci nor utf8_unicode_ci (which are built-in collations to MySQL) fold the apostrophe together with the quote. This is why you would have to add a new one. How this is accomplished in MySQL, you may find here: http://dev.mysql.com/doc/refman/5.0/en/adding-collation.html
Related
I am using:
c.customerName =~ '(?i).*$q.*'
in order to find insensitive case any kind of customername and this is working absolutely fine for all standard character. In German unfortunately there are special chars e.g. like Ä,Ö,Ü. In this cases the cypher statement is case sensitive, e.g. if we have two customer names like Ötest and ötest it will find only one of them depending if you type a lower or an upper Ö.
Anyone has a hint what I can do to expand the insensitive case search also on such special chars?
EDIT: The problem exists also when you have a name including e.g. a '&' - you'll find e.g. the company D&A Construction when you type 'D&' - the moment you add a thrid character 'D&A' the search fails and no result is shown. Any idea?
You need to add a 'u' in your regex to transform it in a case-insensitive unicode regex. Like this:
c.customerName =~ '(?ui).*$q.*'
Works here:
From this StackOverflow question.
Is there an option in neo4j to write a select query with where clause, that ignores non-latin characters ?
MATCH (places:Place)
WHERE (places.name =~ '.*(?ui)Fabergé.*')
RETURN places
I have place with Fabergé name in graph and i want to find it when user type Fabergé or Faberge without this special character.
I'm not aware of an easy way to do this directly with a regex match in Cypher.
One possible workaround is to store the string in question in a normalized form in a second property e.g. place.name_normalized and then compare it with the normalized search string. Of course normalization needs to be done on client side, see another SO question on how to achive this: Remove diacritical marks (ń ǹ ň ñ ṅ ņ ṇ ṋ ṉ ̈ ɲ ƞ ᶇ ɳ ȵ) from Unicode chars
I have a Rails app with a table: "clients". the clients table has a field: phone. phone data type is string. I'm using postgresql. I would like to write a query which selects all clients which have a phone value containing more than 10 digits. phone does not have a specific format:
+1 781-658-2687
+1 (207) 846-3332
2067891111
(345)222-777
123.234.3443
etc.
I've been trying variations of the following:
Client.where("LENGTH(REGEXP_REPLACE(phone,'[^\d]', '')) > 10")
Any help would be great.
You almost have it but you're missing the 'g' option to regexp_replace, from the fine manual:
The regexp_replace function provides substitution of new text for substrings that match POSIX regular expression patterns. [...] The flags parameter is an optional text string containing zero or more single-letter flags that change the function's behavior. Flag i specifies case-insensitive matching, while flag g specifies replacement of each matching substring rather than only the first one.
So regexp_replace(string, pattern, replacement) behaves like Ruby's String#sub whereas regexp_replace(string, pattern, replacement, 'g') behaves like Ruby's String#gsub.
You'll also need to get a \d through your double-quoted Ruby string all the way down to PostgreSQL so you'll need to say \\d in your Ruby. Things tend to get messy when everyone wants to use the same escape character.
This should do what you want:
Client.where("LENGTH(REGEXP_REPLACE(phone, '[^\\d]', '', 'g')) > 10")
# --------------------------------------------^^---------^^^
Try this:
phone_number.gsub(/[^\d]/, '').length
I am working on a legacy system developed with Advantage Database 8.1, I need to run SQL, like:
"SELECT CODETEST.DESC FROM CODETEST"
This SQL won't run at .NET due to the "CODETEST.DESC" name which is belong to SQL reserved keyword "DESC", I think to quote the "CODETEST.DESC", for example, in MySQL, we can use 'CODETEST'.'DESC' (I changed ` to ' here) to avoid that.
I read Advantage Database Help but can't find how to do so, it's a legacy system, and the database structure won't be changed. So is there any way to quote the table and field name in Advantage SQL?
Found the answer, here Use of Non-Standard Characters in Names, its simple by [CODETEST].[DESC]
Double quotes and [] (brackets) are used to delimit identifiers that
contain non-alphanumeric characters or that start with numbers. For
example, if a database contains a table name or column name that
starts with a number, contains spaces, or that has non-alphanumeric
characters, the application must enclose the name in double quotes or
[] (brackets) (e.g., "3D", "Contact Date", "l/c", [Full Name]). Also,
full path names or table names that include extensions must be
enclosed in double quotes or [] (brackets) (e.g., "x:\pathname\table",
"\server\volume\path\table", "table.abc", "..\otherdir\table").
I have a database with names of cities that uses all different kinds of characters, from åäö to vietnamese signs. The place names are all in a capitalized format e.g. "New York" and "Aix En Provence".
My problem now is to try to search for these city names in Heroku which uses postgresql.
p = Place.where("upper(name) LIKE '%" + place_name_searched.to_s.upcase.tr('åäöüñï','ÅÄÖÜÑÏ') + "%'").first
This is the best I have come up with but it is only but a fix for åäö etc and doesn't catch all the 100+ different characters there is out there, e.g. "é". The solution is not to fill out that string any further.
A general problem is that upper(name) seems to translate everything fine but upcase can only handle english letters. So the correspoding search will be .where("TÄBY like 'TäBY') if place_name_searched = 'täby'.
So, how can I match postgresql entries such as "Täby" and "Jidd Ḩafş" to corresponding strings in downcase, entered by the user ("täby", "jidd hafs")?
It all works fine in my Mysql-version of the application but once I upload to Heroku it all fails.
Postgres has an extension called "ILIKE" for case insensitive pattern matching.
p = Place.where("upper(name) ILIKE '%" + place_name_searched.to_s.upcase.tr('åäöüñï','ÅÄÖÜÑÏ') + "%'").first
But please note this only works with Postgres, so you need to check which environment you are running on to decide if you would use this one instead of the regular one.