npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-search-multilingual

v1.0.12

Published

Simple strapi 4 multilingual search

Downloads

695

Readme

Strapi Search Multilingual 🌍🔍

npm version
License
Downloads

Strapi Search Multilingual is a powerful plugin designed to bring multilingual full-text search capabilities to your Strapi application. 🗂️🌐 Whether you're managing a multilingual blog, e-commerce store, or any global content, this plugin simplifies search implementation across multiple languages.

Simple search plugin for strapi 4, which searches in components and dynamic zones also if needed. These components and dynamic zones field can be put in the populate in the entities search config. Also it provides a way to search for page titles using the Auto-complete api.


Features ✨

  • Multilingual Search: Support for searching across multiple languages effortlessly.
  • Full-Text Search: Provides robust full-text search capabilities powered by MongoDB or other Strapi-supported databases.
  • Autocomplete Feature: Search the titles for any entry in any collection using the autocomplete api. Specify the Title field for the collection in the config file and that field will be searched while using the autocomplete api.
  • Customizable: Fine-tune search fields, language preferences, and filters for your unique needs.
  • Easy Integration: Seamlessly integrates into your existing Strapi application with minimal setup.
  • Optimized Performance: Efficient querying for large datasets and multilingual content.

Installation 🚀

You can install this plugin using npm:

npm install strapi-search-multilingual

Or with Yarn:

yarn add strapi-search-multilingual

Usage 🛠️

  1. Setup Configuration:
    After installation, add the plugin to your Strapi configuration. Configure the search fields and language preferences in your plugin settings.

  2. Run Your Strapi Application:
    Start your Strapi server to initialize the plugin:

    npm run develop
  3. Use the Search API:
    Query your multilingual content using the search endpoint provided by the plugin.

  4. Use the Auto complete API:
    Query your multilingual Title field to get auto completed titles.


Configuration Options ⚙️

Here’s an example configuration file:

{
  search_filters: true,
    entities: [
      { 
        name: "api::news-and-publication.news-and-publication",
        fields: ["PageTitle", "Type","PageSlug"],
        title: "PageTitle",
        match_filters: { Type: "News" },
        frontend_entity: "api::news.news"
      },
      { 
        name: "api::news-and-publication.news-and-publication",
        fields: ["PageTitle","Type"],
        title: "PageTitle",
        match_filters: { Type: "Publication" },
        frontend_entity: "api::publication.publication",
        repeated :1
      },
      {
        name:  "api::initiative.initiative",
        fields: ["PageTitle", "ShortDescription"],
        title: "PageTitle"
      },
    ],
    map: {
      others: [ 
        "api::publication.publication",
        "api::api::news.news",
        "api::initiative.initiative"
      ], 
      map_entity: [
        {
          passed: "api::news.news",
          original_entity: "api::news-and-publication.news-and-publication",
          filters: { Type: "News" },
        },
        {
          passed: "api::publication.publication",
          original_entity: "api::news-and-publication.news-and-publication",
          filters: { Type: "Publication" },
        },
      ],
      final_count: { 
        all: 0,
        "api::initiative.initiative":0,
        "api::news.news":0,
        "api::publication.publication":0
      },
    },
    default_populate: {
      PageSlug: true,
      Image: true,
      ParentPage: true,
    },
    custom_populate:[
      {
        name: "api::news.news",
        populate: {
          news_categories :true
        }
      }
    ],
    auto_complete:{
      search_by: 'startswith' //contains or startswith , default is startswith
    }
}
  1. Main Configurations:
  • search_filters: has to set to true to use the below keys.
  • entities: has all the entities that need to be searched.
  • name: is the collection that is present in strapi.
  • fields: all the fields that need to be searched in the strapi collection.
  • title: is used to specify the field that will be search for auto complete feature.
  • match_filters: this is used to filter if the same collection has two different entities that need to be shown as different tabs on the search page.
  • frontend_entity: this is the entity name that is used on the frontend tabs to differentiate.
  1. Other Configurations:
  • map.others: this is used to set the list of filters that need to be filtered in the search results.
  • map.map_entity: this is used to fetch the details of the entity if original_entity is set for the result entries.
  • map.final_count: this is used to set all the counts that you want to use in the frontend result.
  • default_populate: this is the default populate when fetching each entries details.
  • custom_populate: this is for custom populating when fetching each entries details for the specified collection.
  1. Search inside component configurations:
entities: [
    { 
        name: "api::initiative.initiative",
        fields: ["PageTitle", "ShortDescription"],
        title: "PageTitle"
        populate: { 
          componentname: {    
            populate: {
              Description: true
            }        
          }
        }
    }
    ]
  • populate: this key is used to search in the component for specific field, add this in entities under the specific collection. Here we want to search in the Description field inside the componentname
  1. Search inside dynamic zone configurations:
entities: [
    { 
        name: "api::initiative.initiative",
        fields: ["PageTitle", "ShortDescription"],
        title: "PageTitle"
        populate: { 
          dynamiczone: {
            on: {
              'blocks.content-block': { 
                populate: {
                  Description: true
                } 
              }
            }
          }
        }
    }
    ]
  • populate: this key can also be used to search inside a dynamic zone 'blocks', add this in entities under the specific collection. Here we want to search in the Description field inside the component 'content-block'

Example API Call 🖥️

1. Search All collections for a search term

  GET /strapi-search-multilingual/search/?locale=en&type=api::initiative.initiative&term=a&pagination[page]=2&pagination[pageSize]=10

| Parameter | Type | Description | | :-------- | :------- | :------------------------- | | term | string | text to be searched| | locale | string | locale for searching, default is 'en' | | type | string | filter by collection uid, eg: api::initiative.initiative | | pagination[page] | string | page number to return in results , default is page 1| | pagination[pageSize] | string | page result size|

Response:

{
    "data": [
        {
            "id": 4,
            "PageTitle": "Test Initiative",
            "PageSlug": "test-initiative",
            "ShortDescription": "Short description goes here",
            "createdAt": "2024-11-08T07:08:59.058Z",
            "updatedAt": "2024-12-09T09:59:17.023Z",
            "publishedAt": "2024-11-29T07:21:27.335Z",
            "locale": "en",
            "PublishedDate": null,
            "PageUid": "test-initiative",
            "Thumbnail": {
                "id": 20,
                "name": "Test_initiative_thumbnail.jpg",
                "alternativeText": null,
                "caption": null,
                "width": 1330,
                "height": 1060,
                "formats": {
                   
                },
                "hash": "Test_initiative_thumbnail_324ed44e96",
                "ext": ".jpg",
                "mime": "image/jpeg",
                "size": 161.2,
                "url": "/uploads/Test_initiative_thumbnail_324ed44e96.jpg",
                "previewUrl": null,
                "provider": "local",
                "provider_metadata": null,
                "folderPath": "/5",
                "createdAt": "2024-11-08T07:06:55.652Z",
                "updatedAt": "2024-11-08T07:06:55.652Z"
            },
            "entity": "api::initiative.initiative"
        }
    ],
    "meta": {
        "pagination": {
            "page": 1,
            "pageSize": 10,
            "pageCount": 1,
            "total": 1,
            "allCounts": {
                "all": 1,
                "api::program.program": 0,
                "api::resource.resource": 0,
                "api::initiative.initiative": 1,
                "api::news.news": 0,
                "api::publication.publication": 0
            }
        }
    }
}

2. Search Title (Autocomplete)

  GET /strapi-search-multilingual/search/autocomplete?locale=en&term=te

| Parameter | Type | Description | | :-------- | :------- | :------------------------- | | term | string | text to be searched in title and return autocompleted results| | locale | string | locale for searching, default is 'en' |

Response:

{
    "data": [
        "Test Initiative 1",
        "Test Initiative 2"
    ]
}

Compatibility 🤝

This plugin is compatible with Strapi v4.


License 📜

This project is licensed under the MIT License.


Links and Resources 🔗


Future Development

  • Sync All function is not up to date - needs to be updated