How do I search products with arabic language via api?
Developer forum
E-mail notifications
Product Search with Arabic Language by using API
Replies
On the database or the lucene index?
In lucene, first create a field type using the arabic analyzer:
The add a new field to the index using this field type and map e.g. product name or product description to fields of this custom type using the arabic analyzer.
The create a query on that field using a parameter.
Coding against the index:
using Dynamicweb.Core;
using Dynamicweb.Indexing.Querying;
using Dynamicweb.Indexing.Querying.Expressions;
// Resolve the query service
var queryService = ServiceLocator.Current.GetInstance<IQueryService>();
// Load the saved query from the repository (repository name, query item name)
var query = queryService.LoadQuery("productrepository", "myproducts.query");
if (query is null)
throw new InvalidOperationException("Query 'myproducts.query' was not found in 'productrepository'.");
// Add a "ProductNameArabic contains 'sometext'" condition.
// Expression factory: Field(...) is the left side, Term(...) the searched value.
var arabicContains = Expression.Contains(
Expression.Field("ProductNameArabic", source: null),
Expression.Term("sometext"));
// Combine with any existing expression on the query (AND), or just set it if none exists.
query.Expression = query.Expression is null
? arabicContains
: Expression.And([query.Expression, arabicContains]);
// Settings: paging, sort, etc.
var settings = new QuerySettings
{
Skip = 0,
Take = 50
};
// Execute against the productindex
IQueryResult? result = queryService.Query(query, settings);
if (result is not null)
{
foreach (var document in result.QueryResult)
{
// each item is an index document
}
var totalHits = result.TotalCount;
}
This is field type.
This is new field
This is parameter
And this is how i used in query
I called via api end point dwapi/ecommerce/products?RepositoryName=SwiftProducts&QueryName=Products&arabic=وشبابًا
But it gives me
"detail": "The given key 'ArabicFieldType' was not present in the dictionary."
Then I change back the parameter's Type to system.string. it give me 204.
The record is there in products table
You must be logged in to post in the forum