WPSolr logo
Search
Close this search box.

Table of contents :

Managing Multilingual WooCommerce Stores with Weaviate

Weaviate

Table of contents :

Introduction

In today’s globalized world, businesses are expanding their reach beyond borders, catering to customers from different linguistic backgrounds. This has created a need for multilingual support in e-commerce platforms like WooCommerce. Managing a multilingual WooCommerce store can be a complex task, but with the help of powerful tools like Weaviate, it becomes much easier. Weaviate is an open-source knowledge graph that can be used to build intelligent applications. In this post, we will explore how to manage multilingual WooCommerce stores using Weaviate and provide some example code using the PHP client.

 

Managing Multilingual WooCommerce Stores with Weaviate

1. Setting up Weaviate:
The first step is to set up Weaviate on your server. You can follow the official documentation to install and configure Weaviate based on your operating system. Once Weaviate is up and running, you can proceed with the next steps.

2. Define the schema:
To manage multilingual data in Weaviate, you need to define a schema that supports multiple languages. For example, if you have a product entity, you can add properties like “name” and “description” in multiple languages. This allows you to store and retrieve data in different languages.

3. Importing data:
Next, you need to import your WooCommerce store data into Weaviate. This can be done using the Weaviate API or by writing a script that extracts data from your WooCommerce database and inserts it into Weaviate. For the purpose of this example, let’s assume you have a PHP script that retrieves product data from WooCommerce.



// Assuming you have already connected to your WooCommerce database

// Retrieve product data
$query = "SELECT * FROM wp_posts WHERE post_type = 'product'";
$result = mysqli_query($connection, $query);

// Iterate over the products
while ($row = mysqli_fetch_assoc($result)) {
 $product = [
 'name' => [
 'en' => $row['post_title'], // English name
 'fr' => $row['post_title_fr'], // French name
 // Add more language translations as needed
 ],
 'description' => [
 'en' => $row['post_content'], // English description
 'fr' => $row['post_content_fr'], // French description
 // Add more language translations as needed
 ],
// Add more properties as needed
];

// Send the product data to Weaviate API for indexing
$curl = curl_init('https://localhost:8080/v1/batch');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([$product]));
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_exec($curl);
curl_close($curl);


// Close the database connection
mysqli_close($connection);

In this code snippet, we retrieve the product data from the WooCommerce database and transform it into the desired multilingual format. Then, we make a POST request to the Weaviate API to index the products.

 

4. Searching for multilingual data:
Now that your data is stored in Weaviate, you can easily search for multilingual products. Weaviate provides powerful search capabilities that allow you to query data based on language-specific criteria. For example, you can search for products with a specific name in a particular language.



// Assuming you have already connected to Weaviate API

// Search for products with a specific name in English
$searchQuery = [
 'language' => 'en',
 'q' => 'blue shirt',
 'filters' => [
  'concept' =>
   [
    'name' => 'Product',
   ],
 ],
];

$curl = curl_init('https://localhost:8080/v1/graphql');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($searchQuery));
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($curl);
curl_close($curl);

// Process the search results
$results = json_decode($response, true);
// Handle the search results as needed

In this code snippet, we construct a search query to find products with the name “blue shirt” in English. The query is sent to the Weaviate GraphQL API, and the response is processed accordingly.

 

Multilingual Analyzers in Weaviate

When dealing with multilingual data in Weaviate, it is essential to consider how text analysis is performed on different languages. Weaviate provides a feature called multilingual analyzers, which allows you to configure specific analyzers for each language. This ensures that text processing, such as tokenization and stemming, is optimized for the characteristics of each language. Let’s explore how multilingual analyzers work in Weaviate.

1. Configuring Multilingual Analyzers:
Weaviate supports various analyzers for different languages, including built-in and custom analyzers. The first step is to define the analyzers in the Weaviate schema. Each analyzer is associated with a specific language. For example, you can define an analyzer for English, another for French, and so on.

2. Tokenization and Stemming:
Tokenization is the process of breaking text into individual units, such as words or phrases. Stemming, on the other hand, reduces words to their base or root form. These processes are language-specific, and using the appropriate analyzer ensures accurate tokenization and stemming for each language.

3. Language-specific Stopwords:
Stopwords are common words like “and,” “the,” or “is” that are often removed during text analysis. However, stopwords vary across languages. For instance, the word “the” might be a common stopword in English, but it may have different counterparts in other languages. By using multilingual analyzers, you can handle language-specific stopwords effectively.

4. Example Configuration:
Let’s assume you want to configure Weaviate with multilingual analyzers for English and French. Here’s an example configuration in the Weaviate schema:


{
 "classes": [
 {
  "class": "Product",
  "properties": [
    {
     "name": "name",
     "dataType": ["text"],
     "indexInverted": true,
     "fullText": true,
     "multilingual": {
      "analyzers": {
       "en": "standard",
       "fr": "french"
      },
     "stopwords": {
      "en": ["the", "and", "is"],
      "fr": ["le", "et", "est"]
      }
     }
    }
   ]
  }
 ]
}

In this example, the “name” property of the “Product” class is configured as multilingual. The “en” analyzer uses the standard analyzer, while the “fr” analyzer uses the French-specific analyzer. Language-specific stopwords are also defined.

 

How WPSOLR Can Help with Multilingual WooCommerce Stores

WPSOLR is a powerful WordPress plugin that integrates with Weaviate and provides advanced search capabilities for WooCommerce stores. It offers seamless integration with popular multilingual plugins like WPML and Polylang, making it an ideal solution for managing multilingual WooCommerce stores. Let’s explore how WPSOLR can assist in handling multilingual aspects.

1. Integration with Multilingual Plugins:
WPML and Polylang are widely used WordPress plugins for managing multilingual websites. WPSOLR integrates seamlessly with these plugins, allowing you to index and search multilingual content without any hassle. It automatically syncs your WooCommerce products, categories, and other content across different languages.

2. Language-specific Search:
WPSOLR enables language-specific search functionality, ensuring that users can find products in their preferred language. When a user performs a search, WPSOLR filters the search results based on the user’s selected language, providing a localized search experience.

3. Language-specific Indexing:
With WPSOLR, you can configure language-specific indexing for your WooCommerce store. Each language can have its own index in Weaviate, enabling more accurate and efficient searching. This ensures that search queries in different languages are handled appropriately, improving the relevancy of search results.

4. Faceted Search for Multiple Languages:
Faceted search is a powerful feature that allows users to refine their search results based on various attributes or filters. WPSOLR supports faceted search for multiple languages, enabling users to filter products based on language-specific attributes such as color, size, or price.

In conclusion, managing multilingual WooCommerce stores can be simplified with the help of tools like WPSOLR. By leveraging its integration with multilingual plugins like WPML and Polylang, you can seamlessly handle language-specific indexing, search, and faceted search. Combined with the multilingual analyzers in Weaviate, WPSOLR empowers you to create a user-friendly and localized shopping experience for customers from different linguistic backgrounds.

 

Conclusion

Managing multilingual WooCommerce stores can be challenging, but with the help of tools like Weaviate, it becomes much easier. By leveraging Weaviate’s multilingual capabilities, you can store and search for data in different languages, providing a seamless experience for your global customers. In this post, we explored the process of setting up Weaviate, defining a schema, importing data from WooCommerce, and searching for multilingual products. The provided PHP code snippets demonstrate how to interact with Weaviate using its PHP client. With Weaviate and the power of multilingual support, you can take your WooCommerce store to the next level in serving a diverse customer base.

Related posts ... not powered by WPSOLR 😊