Sort query results with German umlaut

Is it possible to sort the results of a cypher query, including German umlaut, for example, Γ€, ΓΆ, ΓΌ? At the moment, I get the list in alphabetical order, and nodes starting with umlaut are placed at the end of the list. Usually they should be on the list, for example. "Γ–" must be equal to "OE".

Any ideas are welcome, thanks.

+4
source share
2 answers

Since you asked specifically about Cypher, the following query is an example of how to sort umlaut characters as if they were their ligature equivalents (for example, treating β€œΓœβ€ as if it were β€œUE”).

WITH ['Dorfer', 'DΓΆrfener'] AS names
UNWIND names AS name
RETURN name
ORDER BY
  REDUCE(s = name, x IN [
    ['Γ€', 'ae'], ['Γ„', 'AE'],
    ['ΓΆ', 'oe'], ['Γ–', 'OE'],
    ['ü', 'ue'], ['Ü', 'UE']] |
    REPLACE(s, x[0], x[1]));

"DΓΆrfener", "Dorfer" - .

, REPLACE name. Java, names .

+3

, localeCompare Intl. Collator :

// Our original array
// Outputs ["u", "x", "ΓΌ", "ΓΌ", "ΓΌ"]
const input1 = ['ΓΌ','u','ΓΌ','x','ΓΌ'];
const output1 = input1.sort();
console.log(output1);

// Intl.Collator
// Outputs ["u", "ΓΌ", "ΓΌ", "ΓΌ", "x"]
const input2 = ['ΓΌ','u','ΓΌ','x','ΓΌ'];
const output2 = input2.sort(Intl.Collator().compare);
console.log(output2)

// localeCompare
// Outputs ["u", "ΓΌ", "ΓΌ", "ΓΌ", "x"]
const input3 = ['ΓΌ','u','ΓΌ','x','ΓΌ'];
const output3 = input3.sort(function (a, b) {
    return a.localeCompare(b);
});
console.log(output3)
+1

Source: https://habr.com/ru/post/1682383/


All Articles