Hi.
We have a website, where we use RavenDB to store product information.
The editors of the website can add new languages as they please, so we do not know up front how many languages we need.
Our current approach is to have a single Product collection, that contains all products. The document will then look something like this (simplified)
{
"Sku": "12345",
"CultureName": "en-US",
"Name": "My product"
}
This presents a challenge when we want to get products for a language, and sort them be Name, since different languages have different sorting rules.
The solution I have currently solves the issue, for a predetermined number of languages:
public ProductDocument_FreeTextWithFacets()
{
Map = products =>
products.Select(product => new
{
product.CultureName,
product.Sku,
product.Name,
SortableName_en = product.Name,
SortableName_da = product.Name,
SortableName_ru = product.Name,
});
Indexes.Add(x => x.CultureName, FieldIndexing.NotAnalyzed);
Indexes.Add(x => x.Name, FieldIndexing.NotAnalyzed);
Index("SortableName_en", FieldIndexing.Analyzed);
Sort("SortableName_en", SortOptions.String);
Analyze("SortableName_en", "Raven.Database.Indexing.Collation.Cultures.EnCollationAnalyzer, Raven.Database");
Index("SortableName_da", FieldIndexing.Analyzed);
Sort("SortableName_da", SortOptions.String);
Analyze("SortableName_da", "Raven.Database.Indexing.Collation.Cultures.DaCollationAnalyzer, Raven.Database");
Index("SortableName_ru", FieldIndexing.Analyzed);
Sort("SortableName_ru", SortOptions.String);
Analyze("SortableName_ru", "Raven.Database.Indexing.Collation.Cultures.RuCollationAnalyzer, Raven.Database");
}
When querying, I then specify which sortable field to use:
var cultureInfo = CultureInfo.GetCultureInfo(parameters.CultureName);
switch (cultureInfo.TwoLetterISOLanguageName)
{
case "da":
query = query.AddOrder("SortableName_da", false);
break;
case "ru":
query = query.AddOrder("SortableName_ru", false);
break;
default:
query = query.AddOrder("SortableName_en", false);
break;
}
This defaults the the english collation analyzer, but since we have 30+ languages, I would like if this was more flexible, so I could just add the fields/analyzers needed for whatever language the document was in.
Is there any way to achieve this for a collection of documents with n languages?