diff --git a/docs.json b/docs.json index b4bb2d6950..fcf3c5be5b 100644 --- a/docs.json +++ b/docs.json @@ -155,6 +155,62 @@ { "version": "latest", "tabs": [ + { + "tab": "Getting started", + "groups": [ + { + "group": "Introduction", + "pages": [ + "getting_started/overview", + "getting_started/features" + ] + }, + { + "group": "Back-end SDKs", + "pages": [ + "getting_started/sdks/javascript", + "getting_started/sdks/python", + "getting_started/sdks/php", + "getting_started/sdks/ruby", + "getting_started/sdks/go", + "getting_started/sdks/rust", + "getting_started/sdks/java", + "getting_started/sdks/dotnet", + "getting_started/sdks/swift", + "getting_started/sdks/dart" + ] + }, + { + "group": "Instant-meilisearch", + "pages": [ + "getting_started/instant_meilisearch/javascript", + "getting_started/instant_meilisearch/react", + "getting_started/instant_meilisearch/vue", + "getting_started/instant_meilisearch/docsearch" + ] + }, + { + "group": "Framework integrations", + "pages": [ + "getting_started/frameworks/laravel", + "getting_started/frameworks/strapi", + "getting_started/frameworks/rails", + "getting_started/frameworks/symfony" + ] + }, + { + "group": "Integrations", + "pages": [ + "getting_started/integrations/firebase", + "getting_started/integrations/gatsby", + "getting_started/integrations/vercel", + "getting_started/integrations/postman", + "getting_started/integrations/meilisearch_importer", + "getting_started/integrations/meilisync" + ] + } + ] + }, { "tab": "Learn", "groups": [ @@ -757,19 +813,9 @@ "group": "Front end", "pages": [ "guides/front_end/front_end_integration", - "guides/front_end/react_quick_start", - "guides/front_end/vue_quick_start", "guides/front_end/pagination" ] }, - { - "group": "Back end", - "pages": [ - "guides/laravel_scout", - "guides/strapi_v4", - "guides/ruby_on_rails_quick_start" - ] - }, { "group": "Artificial intelligence", "pages": [ @@ -814,12 +860,6 @@ "guides/running_production" ] }, - { - "group": "Integrations", - "pages": [ - "guides/vercel" - ] - }, { "group": "Miscellaneous", "pages": [ @@ -1060,7 +1100,7 @@ }, { "source": "/learn/cookbooks/laravel_scout", - "destination": "/guides/back_end/laravel_scout" + "destination": "/getting_started/frameworks/laravel" }, { "source": "/learn/cookbooks/large_documents", @@ -1096,11 +1136,11 @@ }, { "source": "/learn/cookbooks/strapi_v4", - "destination": "/guides/back_end/strapi_v4" + "destination": "/getting_started/frameworks/strapi" }, { "source": "/learn/cookbooks/vercel", - "destination": "/guides/integrations/vercel" + "destination": "/getting_started/integrations/vercel" }, { "source": "/learn/core_concepts/documents", @@ -1188,7 +1228,7 @@ }, { "source": "/learn/front_end/react_instantsearch", - "destination": "/guides/front_end/react_quick_start" + "destination": "/getting_started/instant_meilisearch/react" }, { "source": "/learn/getting_started/a", @@ -1424,7 +1464,7 @@ }, { "source": "/reference/api/multi_search", - "destination": "/reference/api/search/perform-a-multi-search" + "destination": "/reference/api/multi-search/perform-a-multi-search" }, { "source": "/reference/api/network", @@ -1680,7 +1720,7 @@ }, { "source": "/guides/back_end/laravel_scout", - "destination": "/guides/laravel_scout" + "destination": "/getting_started/frameworks/laravel" }, { "source": "/guides/database/meilisync_mysql", @@ -1696,7 +1736,7 @@ }, { "source": "/guides/front_end/react_instantsearch", - "destination": "/guides/front_end/react_quick_start" + "destination": "/getting_started/instant_meilisearch/react" }, { "source": "/guides/front_end/search_bar_for_docs", @@ -1704,7 +1744,7 @@ }, { "source": "/guides/integrations/vercel", - "destination": "/guides/vercel" + "destination": "/getting_started/integrations/vercel" }, { "source": "/guides/performance/indexing_best_practices", @@ -1853,6 +1893,30 @@ { "source": "/reference/api/chats/update-chat", "destination": "/reference/api/chats/update-settings-of-a-chat-workspace" + }, + { + "source": "/guides/laravel_scout", + "destination": "/getting_started/frameworks/laravel" + }, + { + "source": "/guides/strapi_v4", + "destination": "/getting_started/frameworks/strapi" + }, + { + "source": "/guides/ruby_on_rails_quick_start", + "destination": "/getting_started/frameworks/rails" + }, + { + "source": "/guides/front_end/react_quick_start", + "destination": "/getting_started/instant_meilisearch/react" + }, + { + "source": "/guides/front_end/vue_quick_start", + "destination": "/getting_started/instant_meilisearch/vue" + }, + { + "source": "/guides/vercel", + "destination": "/getting_started/integrations/vercel" } ] } diff --git a/getting_started/features.mdx b/getting_started/features.mdx new file mode 100644 index 0000000000..8ae2b0b9ef --- /dev/null +++ b/getting_started/features.mdx @@ -0,0 +1,209 @@ +--- +title: Features +sidebarTitle: Features +description: Explore all Meilisearch capabilities - from full-text search to AI-powered semantic search. +--- + +Meilisearch provides a comprehensive set of search features designed to deliver fast, relevant results for any use case. + +## Search capabilities + +### Full-text search + +Lightning-fast keyword search with typo tolerance and customizable relevancy. + +| Feature | Description | +|---------|-------------| +| Sub-50ms responses | Fast search regardless of dataset size | +| [Typo tolerance](/learn/relevancy/typo_tolerance_settings) | Get relevant results even with spelling mistakes | +| [Ranking rules](/learn/relevancy/ranking_rules) | 6 default rules plus custom ranking | +| [Ranking score](/learn/relevancy/ranking_score) | Relevancy scores with optional detailed breakdown | +| [Synonyms](/learn/relevancy/synonyms) | Define equivalent terms for better recall | +| [Stop words](/reference/api/settings/get-stopwords) | Ignore common words like "the" or "and" | +| [Distinct attribute](/learn/relevancy/distinct_attribute) | Deduplicate results by a specific field | +| [Prefix search](/learn/engine/prefix) | Results update as users type | +| [Matching strategy](/reference/api/search/search-with-post#body-matching-strategy) | Control how query terms are matched: `last`, `all`, or `frequency` | +| [Phrase search](/reference/api/search/search-with-post) | Use double quotes to search for an exact phrase | +| [Negative search](/reference/api/search/search-with-post) | Exclude terms from results using the minus operator | +| [Placeholder search](/reference/api/search/search-with-post) | Return all results when the query is empty | + +### Querying and result formatting + +| Feature | Description | +|---------|-------------| +| [Highlighting](/reference/api/search/search-with-post#highlight-tags) | Emphasize query matches in results with customizable tags | +| [Cropping](/reference/api/search/search-with-post#body-attributes-to-crop) | Return only the relevant portion of long text fields | +| [Matches position](/reference/api/search/search-with-post#body-show-matches-position) | Get byte positions and lengths of matched terms | +| [Search cutoff](/reference/api/settings/get-searchcutoffms) | Set a maximum time limit for search queries | +| [Tokenization](/learn/indexing/tokenization) | Customize how queries are broken into tokens, with custom separators and dictionaries | + +### AI-powered search + +Semantic and hybrid search using vector embeddings for meaning-based results. + +| Feature | Description | +|---------|-------------| +| [Hybrid search](/learn/ai_powered_search/getting_started_with_ai_search) | Combine keyword and semantic search | +| [Embedders](/learn/ai_powered_search/choose_an_embedder) | OpenAI, Hugging Face, Cohere, Mistral, Voyage, Gemini, Cloudflare, Ollama, and custom REST | +| [Similar documents](/learn/ai_powered_search/retrieve_related_search_results) | Find related content automatically | +| [Image search](/learn/ai_powered_search/image_search_with_multimodal_embeddings) | Search images with multimodal embeddings | +| [Multi-embedder](/reference/api/settings/get-embedders) | Multiple embedding models on the same document | +| [User-provided vectors](/learn/ai_powered_search/search_with_user_provided_embeddings) | Bring your own pre-generated embeddings | + +### Conversational search + +Build chat interfaces powered by your search data with LLM integration. + +| Feature | Description | +|---------|-------------| +| [Chat completions](/learn/chat/getting_started_with_chat) | RAG-powered conversational search | +| [LLM providers](/learn/chat/chat_tooling_reference) | OpenAI, Azure OpenAI, Mistral, Google Gemini, vLLM, and custom providers | +| [Streaming responses](/reference/api/chats/chat-completions) | Stream chat responses in real time | +| [Chat workspaces](/reference/api/chats/get-chat-settings) | Configure chat settings per index | + +### Personalization + +| Feature | Description | +|---------|-------------| +| [User preference ranking](/reference/api/search/search-with-post#body-personalize-one-of-1) | Re-rank results based on individual user preferences using AI embeddings | +| Real-time adaptation | Adjust results as user preferences evolve | + +### Filtering and faceting + +Refine search results with powerful filters and build faceted navigation. + +| Feature | Description | +|---------|-------------| +| [Filters](/learn/filtering_and_sorting/filter_search_results) | Filter by any attribute with complex expressions (AND/OR) | +| [Facets](/learn/filtering_and_sorting/search_with_facet_filters) | Build faceted navigation interfaces | +| [Facet types](/learn/filtering_and_sorting/facet_types) | AND/OR operators, numeric, boolean, and date facets | +| [Sorting](/learn/filtering_and_sorting/sort_search_results) | Sort results by any field | +| [Geo search](/learn/filtering_and_sorting/geosearch) | Geo radius, bounding box, geo sorting, and distance calculation | + +### Multi-search and federation + +Query multiple indexes in a single request for complex search scenarios. + +| Feature | Description | +|---------|-------------| +| [Multi-search](/learn/multi_search/multi_search_vs_federated_search) | Query multiple indexes at once | +| [Federated search](/learn/multi_search/performing_federated_search) | Merge results from multiple sources with configurable weights | + +## Scaling + +Scale Meilisearch horizontally across multiple instances or optimize resource usage on a single node. + +| Feature | Description | +|---------|-------------| +| [Sharding](/learn/multi_search/implement_sharding) | Distribute documents across multiple instances for horizontal scaling | +| [Replication](/reference/api/experimental-features/get-network-topology) | Replicate data across multiple instances for high availability | +| [Remote federation](/reference/api/experimental-features/get-network-topology) | Federate search across multiple Meilisearch instances | +| Memory mapping | Efficient memory usage through memory-mapped storage | + +## Database + +### Document database + +| Feature | Description | +|---------|-------------| +| [Schemaless](/learn/getting_started/documents) | Index documents without a predefined schema | +| [Documents](/learn/getting_started/documents) | Add, replace, update, and delete documents | +| [Delete by filter](/reference/api/documents/delete-documents-by-filter) | Delete documents matching a filter expression | +| [Update by function](/reference/api/documents/edit-documents-by-function) | Partial updates to documents using functions | +| [Searchable attributes](/learn/relevancy/displayed_searchable_attributes) | Configure which fields are searchable and their priority | +| [Displayed attributes](/learn/relevancy/displayed_searchable_attributes) | Control which fields are returned in results | +| [Filterable attributes](/learn/filtering_and_sorting/filter_search_results) | Define which fields can be used in filters | +| [Sortable attributes](/learn/filtering_and_sorting/sort_search_results) | Define which fields can be used for sorting | +| [Index swap](/reference/api/indexes/swap-indexes) | Swap indexes to perform updates without downtime | + +### Vector database + +| Feature | Description | +|---------|-------------| +| [Similar documents](/learn/ai_powered_search/retrieve_related_search_results) | Find semantically similar documents using vector embeddings | +| [Binary quantization](/reference/api/settings/get-embedders) | Compress vectors to save storage | +| DiskANN | Disk-based approximate nearest neighbors for large datasets | +| [Auto embedding](/reference/api/settings/get-embedders) | Automatically generate embeddings without manual input | + +## Platform features + +### Security + +Protect your data with API keys and multi-tenant access control. + +| Feature | Description | +|---------|-------------| +| [API keys](/learn/security/basic_security) | Admin, search, and chat key types for different access levels | +| [Tenant tokens](/learn/security/multitenancy_tenant_tokens) | Secure multi-tenant applications with document-level access control | +| [Search rules](/learn/security/tenant_token_reference) | Restrict which documents users can access | + +### Tasks and monitoring + +Monitor indexing operations and receive notifications. + +| Feature | Description | +|---------|-------------| +| [Task management](/learn/async/working_with_tasks) | Track and manage async operations | +| [Batches](/learn/async/asynchronous_operations#task-batches) | Automatic task batching for efficient processing | +| [Webhooks](/learn/async/task_webhook) | Get notified when tasks complete | +| Diff indexing | Only index differences between datasets | + +### Analytics (Cloud) + +Track search behavior and optimize relevancy with built-in analytics. + +| Feature | Description | +|---------|-------------| +| [Search analytics](/learn/analytics/configure_analytics_events) | Monitor search patterns, no-result rates, and top queries | +| [Click tracking](/learn/analytics/bind_events_user) | Track which results users engage with | +| [Metrics reference](/learn/analytics/analytics_metrics_reference) | Click-through rate, conversion rate, average click position | +| Monitoring | Search latency, indexing latency, bandwidth, and API health | + +### Pagination + +| Feature | Description | +|---------|-------------| +| [Pagination](/guides/front_end/pagination) | Offset/limit and cursor-based pagination | + +## Language support + +Meilisearch provides optimized support for many languages: + +- **Latin-based languages**: English, French, Spanish, German, Italian, Portuguese, etc. +- **CJK**: Chinese, Japanese, Korean with specialized tokenization +- **RTL languages**: Hebrew, Arabic +- **Others**: Thai, Greek, and more + +[See full language support →](/learn/resources/language) + +## Cloud features + +These features are available exclusively on Meilisearch Cloud. + +| Feature | Description | +|---------|-------------| +| Crawler | Crawl web pages with JS rendering, DocSearch mode, and schema extraction | +| [Search preview](/learn/getting_started/search_preview) | Visual search interface with filtering, sorting, and document CRUD | +| [Teams](/learn/teams/teams) | Organize projects and members into team workspaces | +| [Enterprise SSO/SCIM](/learn/self_hosted/enterprise_edition) | SAML 2.0 SSO and automated user provisioning | +| Autoscale disk | Automatically scale storage as data grows | +| Automatic backups | Scheduled backups for data safety | +| One-click upgrade | Upgrade Meilisearch version with a single click | +| Up to 99.999% SLA | Industry-leading service level agreement | + +## Self-hosting + +| Feature | Description | +|---------|-------------| +| [Configuration](/learn/self_hosted/configure_meilisearch_at_launch) | CLI flags and environment variables | +| [Snapshots](/learn/data_backup/snapshots) | Full binary copies for fast restoration | +| [Dumps](/learn/data_backup/dumps) | Portable JSON exports for migration | +| [Master key](/learn/security/basic_security) | Secure your instance with a master key | + +## Integration options + +| Option | Description | +|--------|-------------| +| [REST API](/reference/api/openapi) | Direct HTTP integration | +| [Official SDKs](/learn/resources/sdks) | 10+ language SDKs | +| [Frameworks](/learn/resources/sdks#framework-integrations) | Laravel, Rails, Strapi, Symfony | diff --git a/guides/laravel_scout.mdx b/getting_started/frameworks/laravel.mdx similarity index 95% rename from guides/laravel_scout.mdx rename to getting_started/frameworks/laravel.mdx index 14af52d782..47c36a3cdc 100644 --- a/guides/laravel_scout.mdx +++ b/getting_started/frameworks/laravel.mdx @@ -1,5 +1,6 @@ --- title: Laravel Scout guide +sidebarTitle: Laravel Scout description: Learn how to use Meilisearch with Laravel Scout. sidebarDepth: 3 --- @@ -67,11 +68,9 @@ Check out Docker [Bridge network driver](https://docs.docker.com/network/drivers For production use cases, we recommend using a managed Meilisearch via [Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=laravel&utm_source=docs&utm_medium=laravel-scout-guide). On Meilisearch Cloud, you can find your host URL in your project settings. -Read the [Meilisearch Cloud quick start](/learn/getting_started/cloud_quick_start). +Read the [Meilisearch Cloud quick start](/getting_started/overview). -If you prefer to self-host, read our guide for [running Meilisearch in production](/guides/running_production). - ## Making Eloquent models searchable With Scout installed and configured, add the `Laravel\Scout\Searchable` trait to your Eloquent models to make them searchable. This trait will use Laravel’s model observers to keep the data in your model in sync with Meilisearch. @@ -184,7 +183,7 @@ You built an example application to demonstrate how to use Meilisearch with Lara This demo application uses the following features: -- [Multi-search](/reference/api/search/perform-a-multi-search) (search across multiple indexes) +- [Multi-search](/reference/api/multi-search/perform-a-multi-search) (search across multiple indexes) - [Multi-tenancy](/learn/security/multitenancy_tenant_tokens) - [Filtering](/learn/filtering_and_sorting/filter_search_results) - [Sorting](/learn/filtering_and_sorting/sort_search_results) diff --git a/guides/ruby_on_rails_quick_start.mdx b/getting_started/frameworks/rails.mdx similarity index 90% rename from guides/ruby_on_rails_quick_start.mdx rename to getting_started/frameworks/rails.mdx index 72b613b084..fbf78f7918 100644 --- a/guides/ruby_on_rails_quick_start.mdx +++ b/getting_started/frameworks/rails.mdx @@ -1,5 +1,6 @@ --- title: Ruby on Rails quick start +sidebarTitle: Ruby on Rails description: Integrate Meilisearch into your Ruby on Rails app. --- @@ -7,9 +8,9 @@ Integrate Meilisearch into your Ruby on Rails app. ## 1. Create a Meilisearch project -[Create a project](https://cloud.meilisearch.com) in the Meilisearch Cloud dashboard. Check out our [getting started guide](/learn/getting_started/cloud_quick_start) for step-by-step instructions. +[Create a project](https://cloud.meilisearch.com) in the Meilisearch Cloud dashboard. Check out our [getting started guide](/getting_started/overview) for step-by-step instructions. -If you prefer to use the self-hosted version of Meilisearch, you can follow the [quick start](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch) tutorial. +If you prefer to use the self-hosted version of Meilisearch, you can follow the [quick start](/learn/self_hosted/getting_started_with_self_hosted_meilisearch) tutorial. ## 2. Create a Rails app @@ -114,11 +115,11 @@ We strongly recommend using the frontend search to enjoy the swift and responsiv ### Frontend search -For testing purposes, you can explore the records using our built-in [search preview](/learn/getting_started/search_preview). +For testing purposes, you can explore the records using our built-in [search preview](/getting_started/overview). ![Searching through Rails table data with Meilisearch search preview UI](/assets/images/rails_quick_start/rails-qs-search-preview.gif) -We also provide resources to help you quickly build your own [frontend interface](/guides/front_end/front_end_integration). +We also provide resources to help you quickly build your own [frontend interface](/getting_started/instant_meilisearch/javascript). ## Next steps diff --git a/guides/strapi_v4.mdx b/getting_started/frameworks/strapi.mdx similarity index 94% rename from guides/strapi_v4.mdx rename to getting_started/frameworks/strapi.mdx index 8062f6a202..eaba99fb81 100644 --- a/guides/strapi_v4.mdx +++ b/getting_started/frameworks/strapi.mdx @@ -1,5 +1,6 @@ --- title: Strapi v4 guide +sidebarTitle: Strapi description: Learn how to use Meilisearch with Strapi v4. --- @@ -9,7 +10,7 @@ This tutorial will show you how to integrate Meilisearch with [Strapi](https://s - [Node.js](https://nodejs.org/): active LTS or maintenance LTS versions, currently Node.js >=18.0.0 \<=20.x.x - npm >=6.0.0 (installed with Node.js) -- A running instance of Meilisearch (v >= 1.x). If you need help with this part, you can consult the [Installation section](/learn/self_hosted/install_meilisearch_locally). +- A running instance of Meilisearch (v >= 1.x). If you need help with this part, you can consult the [Installation section](/learn/self_hosted/getting_started_with_self_hosted_meilisearch). ## Create a back end using Strapi @@ -60,7 +61,7 @@ Add the following three restaurants, one by one. For each restaurant, you need t Next, add the `French food` category on the bottom right corner of the page. - Strapi dashboard: create an entry form, arrow indicating the location of the categorie's location in the right side menu + Strapi dashboard: create an entry form, arrow indicating the category's location in the right side menu - Name: `The Slimy Snail` @@ -116,7 +117,7 @@ By clicking on the checkbox next to `restaurant`, the content-type is automatica The word “Hooked” appears when you click on the `restaurant`'s checkbox in the `Collections` tab. This means that each time you add, update or delete an entry in your restaurant content-types, Meilisearch is automatically updated. -Once the indexing finishes, your restaurants are in Meilisearch. Access the [search preview](/learn/getting_started/search_preview) confirm everything is working correctly by searching for “butter”. +Once the indexing finishes, your restaurants are in Meilisearch. Access the [search preview](/getting_started/overview) confirm everything is working correctly by searching for “butter”. GIF showing the word 'butter' being typed in the search bar and search results appearing instantly @@ -124,8 +125,8 @@ Once the indexing finishes, your restaurants are in Meilisearch. Access the [sea Your Strapi entries are sent to Meilisearch as is. You can modify the data before sending it to Meilisearch, for instance by removing a field. Check out all the customization options on the [strapi-plugin-meilisearch page](https://github.com/meilisearch/strapi-plugin-meilisearch/#-customization). -## What's next +## Next steps This tutorial showed you how to add your Strapi collections to Meilisearch. -In most real-life scenarios, you'll typically build a custom search interface and fetch results using Meilisearch's API. To learn how to quickly build a front-end interface of your own, check out the [Front-end integration page](/guides/front_end/front_end_integration) guide. +In most real-life scenarios, you'll typically build a custom search interface and fetch results using Meilisearch's API. To learn how to quickly build a front-end interface of your own, check out the [Front-end integration page](/getting_started/instant_meilisearch/javascript) guide. diff --git a/getting_started/frameworks/symfony.mdx b/getting_started/frameworks/symfony.mdx new file mode 100644 index 0000000000..13c103771d --- /dev/null +++ b/getting_started/frameworks/symfony.mdx @@ -0,0 +1,213 @@ +--- +title: Symfony +sidebarTitle: Symfony +description: Integrate Meilisearch with Symfony using the official bundle. +--- + +The official [meilisearch-symfony](https://github.com/meilisearch/meilisearch-symfony) bundle provides seamless integration between Meilisearch and Symfony applications with Doctrine ORM support. + +## Prerequisites + +- PHP 7.4 or higher +- Symfony 5.4 or higher +- Doctrine ORM (optional, for automatic entity indexing) +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the bundle + +```bash +composer require meilisearch/search-bundle +``` + +## 2. Configure the bundle + +Create or update `config/packages/meilisearch.yaml`: + +```yaml +meilisearch: + url: '%env(MEILISEARCH_URL)%' + api_key: '%env(MEILISEARCH_API_KEY)%' +``` + +Add to your `.env` file: + +```bash +MEILISEARCH_URL=https://your-instance.meilisearch.io +MEILISEARCH_API_KEY=your_api_key +``` + + +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Configure an entity for indexing + +Add the `Searchable` attribute to your Doctrine entity: + +```php + $this->id, + 'title' => $this->title, + 'year' => $this->year, + 'genres' => $this->genres, + ]; + } +} +``` + +## 4. Index your data + +Import existing entities to Meilisearch: + +```bash +php bin/console meilisearch:import +``` + +New entities are automatically indexed when created or updated via Doctrine. + +## 5. Search + +Use the `SearchService` to search your indexed entities: + +```php +search( + Movie::class, + 'matrix' + ); + + return $this->render('search/results.html.twig', [ + 'movies' => $results, + ]); + } +} +``` + +## 6. Search with filters + +First, configure filterable attributes in `config/packages/meilisearch.yaml`: + +```yaml +meilisearch: + url: '%env(MEILISEARCH_URL)%' + api_key: '%env(MEILISEARCH_API_KEY)%' + indices: + - name: movies + class: App\Entity\Movie + settings: + filterableAttributes: ['genres', 'year'] + sortableAttributes: ['year'] +``` + +Update the index settings: + +```bash +php bin/console meilisearch:create +``` + +Then search with filters: + +```php +$results = $searchService->search( + Movie::class, + 'action', + [ + 'filter' => 'year > 2000', + 'sort' => ['year:desc'], + ] +); +``` + +## Available commands + +| Command | Description | +|---------|-------------| +| `meilisearch:import` | Import all entities to Meilisearch | +| `meilisearch:clear` | Clear all indexed data | +| `meilisearch:create` | Create indexes with configured settings | +| `meilisearch:delete` | Delete indexes | + +## Raw client access + +For advanced operations, access the Meilisearch client directly: + +```php +use Meilisearch\Client; + +class MyService +{ + public function __construct(private Client $client) {} + + public function customOperation(): void + { + $index = $this->client->index('movies'); + $stats = $index->getStats(); + } +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-symfony on GitHub](https://github.com/meilisearch/meilisearch-symfony) +- [Bundle documentation](https://github.com/meilisearch/meilisearch-symfony/wiki) diff --git a/getting_started/instant_meilisearch/docsearch.mdx b/getting_started/instant_meilisearch/docsearch.mdx new file mode 100644 index 0000000000..926784a474 --- /dev/null +++ b/getting_started/instant_meilisearch/docsearch.mdx @@ -0,0 +1,218 @@ +--- +title: Integrate a relevant search bar to your documentation +sidebarTitle: Docsearch +description: Use Meilisearch to index content in a text-heavy website. Covers installing Meilisearch, configuring a text scraper, and creating a simple front end. +--- + +This tutorial will guide you through the steps of building a relevant and powerful search bar for your documentation 🚀 + +- [Run a Meilisearch instance](#run-a-meilisearch-instance) +- [Scrape your content](#scrape-your-content) + - [Configuration file](#configuration-file) + - [Run the scraper](#run-the-scraper) +- [Integrate the search bar](#integrate-the-search-bar) + - [For VuePress documentation sites](#for-vuepress-documentation-sites) + - [For all kinds of documentation](#for-all-kinds-of-documentation) +- [What's next?](#whats-next) + +## Run a Meilisearch instance + +First, create a new Meilisearch project on Meilisearch Cloud. You can also [install and run Meilisearch locally or in another cloud service](/learn/self_hosted/getting_started_with_self_hosted_meilisearch#setup-and-installation). + + +The host URL and the API key you will provide in the next steps correspond to the credentials of this Meilisearch instance. + + +## Scrape your content + +The Meilisearch team provides and maintains a [scraper tool](https://github.com/meilisearch/docs-scraper) to automatically read the content of your website and store it into an index in Meilisearch. + +### Configuration file + +The scraper tool needs a configuration file to know what content you want to scrape. This is done by providing selectors (for example, the `html` tag). + +Here is an example of a basic configuration file: + +```json +{ + "index_uid": "docs", + "start_urls": [ + "https://www.example.com/doc/" + ], + "sitemap_urls": [ + "https://www.example.com/sitemap.xml" + ], + "stop_urls": [], + "selectors": { + "lvl0": { + "selector": ".docs-lvl0", + "global": true, + "default_value": "Documentation" + }, + "lvl1": { + "selector": ".docs-lvl1", + "global": true, + "default_value": "Chapter" + }, + "lvl2": ".docs-content .docs-lvl2", + "lvl3": ".docs-content .docs-lvl3", + "lvl4": ".docs-content .docs-lvl4", + "lvl5": ".docs-content .docs-lvl5", + "lvl6": ".docs-content .docs-lvl6", + "text": ".docs-content p, .docs-content li" + } +} +``` + +The `index_uid` field is the index identifier in your Meilisearch instance in which your website content is stored. The scraping tool will create a new index if it does not exist. + +The `docs-content` class is the main container of the textual content in this example. Most of the time, this tag is a `
` or an `
` HTML element. + +`lvlX` selectors should use the standard title tags like `h1`, `h2`, `h3`, etc. You can also use static classes. Set a unique `id` or `name` attribute to these elements. + +All searchable `lvl` elements outside this main documentation container (for instance, in a sidebar) must be `global` selectors. They will be globally picked up and injected to every document built from your page. + +If you use VuePress for your documentation, you can check out the [configuration file](https://github.com/meilisearch/documentation/blob/main/docs-scraper.config.json) we use in production. +In our case, the main container is `theme-default-content` and the selector titles and subtitles are `h1`, `h2`... + + +More [optional fields are available](https://github.com/meilisearch/docs-scraper#all-the-config-file-settings) to fit your needs. + + +### Run the scraper + +You can run the scraper with Docker. With our local Meilisearch instance set up at [the first step](#run-a-meilisearch-instance), we run: + +```bash +docker run -t --rm \ + --network=host \ + -e MEILISEARCH_HOST_URL='MEILISEARCH_URL' \ + -e MEILISEARCH_API_KEY='MASTER_KEY' \ + -v :/docs-scraper/config.json \ + getmeili/docs-scraper:latest pipenv run ./docs_scraper config.json +``` + + +If you don't want to use Docker, here are [other ways to run the scraper](https://github.com/meilisearch/docs-scraper#installation-and-usage). + + +`` should be the **absolute** path of your configuration file defined at [the previous step](#configuration-file). + +The API key should have the permissions to add documents into your Meilisearch instance. In a production environment, we recommend providing the `Default Admin API Key` as it has enough permissions to perform such requests. +_More about [Meilisearch security](/learn/security/basic_security)._ + + +We recommend running the scraper at each new deployment of your documentation, [as we do for the Meilisearch's one](https://github.com/meilisearch/documentation/blob/main/.github/workflows/scraper.yml). + + +## Integrate the search bar + +If your documentation is not a VuePress application, you can directly go to [this section](#for-all-kinds-of-documentation). + +### For VuePress documentation sites + +If you use VuePress for your documentation, we provide a [Vuepress plugin](https://github.com/meilisearch/vuepress-plugin-meilisearch). This plugin is used in production in the Meilisearch documentation. + +In your VuePress project: + + + + +```bash +yarn add vuepress-plugin-meilisearch +``` + + + + + +```bash +npm install vuepress-plugin-meilisearch +``` + + + + +In your `config.js` file: + +```js +module.exports = { + plugins: [ + [ + "vuepress-plugin-meilisearch", + { + "hostUrl": "", + "apiKey": "", + "indexUid": "docs" + } + ], + ], +} +``` + +The `hostUrl` and the `apiKey` fields are the credentials of the Meilisearch instance. Following on from this tutorial, they are respectively `MEILISEARCH_URL` and `MASTER_KEY`. + +`indexUid` is the index identifier in your Meilisearch instance in which your website content is stored. It has been defined in the [config file](#configuration-file). + +These three fields are mandatory, but more [optional fields are available](https://github.com/meilisearch/vuepress-plugin-meilisearch#customization) to customize your search bar. + + +Since the configuration file is public, we strongly recommend providing a key that can only access [the search endpoint](/reference/api/search/search-with-post) , such as the `Default Search API Key`, in a production environment. +Read more about [Meilisearch security](/learn/security/basic_security). + + +### For all kinds of documentation + +If you don't use VuePress for your documentation, we provide a [front-end SDK](https://github.com/meilisearch/docs-searchbar.js) to integrate a powerful and relevant search bar to any documentation website. + +![Docxtemplater search bar updating results for "HTML"](/assets/images/tuto-searchbar-for-docs/docxtemplater-searchbar-demo.gif) +_[Docxtemplater](https://docxtemplater.com/) search bar demo_ + +```html + + + + + + + + + + + + +``` + + +Replace `{version}` in the CDN URLs above with the actual docs-searchbar.js version number, for example `2.0.5`. Check the [docs-searchbar.js releases page](https://github.com/meilisearch/docs-searchbar.js/releases) for the latest version. + + +The `hostUrl` and the `apiKey` fields are the credentials of the Meilisearch instance. Following on from this tutorial, they are respectively `MEILISEARCH_URL` and `MASTER_KEY`. + +`indexUid` is the index identifier in your Meilisearch instance in which your website content is stored. It has been defined in the [config file](#configuration-file). +`inputSelector` is the `id` attribute of the HTML search input tag. + + +We strongly recommend providing a `Default Search API Key` in a production environment, which is enough to perform search requests. + +Read more about [Meilisearch security](/learn/security/basic_security). + + +The default behavior of this library fits perfectly for a documentation search bar, but you might need [some customizations](https://github.com/meilisearch/docs-searchbar.js#customization). + + +For more concrete examples, you can check out this [basic HTML file](https://github.com/meilisearch/docs-searchbar.js/blob/main/playgrounds/html/index.html) or [this more advanced Vue file](https://github.com/meilisearch/vuepress-plugin-meilisearch/blob/main/MeiliSearchBox.vue). + + +## Next steps + +At this point, you should have a working search engine on your website, congrats! 🎉 +You can check [this tutorial](/learn/self_hosted/getting_started_with_self_hosted_meilisearch) if you now want to run Meilisearch in production! diff --git a/getting_started/instant_meilisearch/javascript.mdx b/getting_started/instant_meilisearch/javascript.mdx new file mode 100644 index 0000000000..6c9486ed60 --- /dev/null +++ b/getting_started/instant_meilisearch/javascript.mdx @@ -0,0 +1,124 @@ +--- +title: Instant-meilisearch +sidebarTitle: JavaScript +description: Build search interfaces with instant-meilisearch and InstantSearch. +--- + +[instant-meilisearch](https://github.com/meilisearch/instant-meilisearch) is the easiest way to add a search interface to your front-end. It connects Meilisearch to [InstantSearch](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/), an open-source library by Algolia that provides pre-built UI components for search. + +## Why instant-meilisearch? + +- **Pre-built components**: Search boxes, hit lists, facet filters, pagination, and more +- **Framework support**: Works with React, Vue, Angular, and vanilla JavaScript +- **Customizable**: Full control over styling and behavior +- **Search-as-you-type**: Real-time results as users type + +## Quick example + +Create an `index.html` file with the following code: + +```html + + + + + + + +
+ +
+
+ + + + + + +``` + +Open this file in your browser to see a working search interface. + +## Framework guides + + + + Build search UIs with React InstantSearch + + + Build search UIs with Vue InstantSearch + + + +## Available widgets + +InstantSearch provides many pre-built widgets: + +| Widget | Description | +|--------|-------------| +| `searchBox` | Text input for search queries | +| `hits` | Display search results | +| `infiniteHits` | Infinite scroll results | +| `pagination` | Page navigation | +| `refinementList` | Facet filter checkboxes | +| `menu` | Single-select facet filter | +| `rangeSlider` | Numeric range filter | +| `sortBy` | Sort results dropdown | +| `stats` | Search statistics | + +[See all InstantSearch widgets](https://www.algolia.com/doc/api-reference/widgets/js/) + +## Using your own data + +The example above uses a public demo instance. To use your own Meilisearch instance: + +```javascript +const { searchClient } = instantMeiliSearch( + process.env.MEILISEARCH_URL, // Your instance URL + process.env.MEILISEARCH_API_KEY // Your search API key +); +``` + + +**Set up your environment:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" +export MEILISEARCH_API_KEY="your_search_api_key" +``` +[Get a free Cloud instance](https://cloud.meilisearch.com) + + +## Resources + +- [instant-meilisearch on GitHub](https://github.com/meilisearch/instant-meilisearch) +- [InstantSearch documentation](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/) +- [Live demo](https://codesandbox.io/p/sandbox/eager-dust-f98w2w) diff --git a/guides/front_end/react_quick_start.mdx b/getting_started/instant_meilisearch/react.mdx similarity index 97% rename from guides/front_end/react_quick_start.mdx rename to getting_started/instant_meilisearch/react.mdx index 7f8e0253f9..795f992ca8 100644 --- a/guides/front_end/react_quick_start.mdx +++ b/getting_started/instant_meilisearch/react.mdx @@ -1,5 +1,6 @@ --- title: React quick start +sidebarTitle: React description: Integrate a search-as-you-type experience into your React app. --- @@ -124,4 +125,4 @@ Encountering issues? Check out the code in action in our [live demo](https://cod ## Next steps -Want to search through your own data? [Create a project](https://cloud.meilisearch.com) in the Meilisearch Dashboard. Check out our [getting started guide](/learn/getting_started/cloud_quick_start) for step-by-step instructions. +Want to search through your own data? [Create a project](https://cloud.meilisearch.com) in the Meilisearch Dashboard. Check out our [getting started guide](/getting_started/overview) for step-by-step instructions. diff --git a/guides/front_end/vue_quick_start.mdx b/getting_started/instant_meilisearch/vue.mdx similarity index 95% rename from guides/front_end/vue_quick_start.mdx rename to getting_started/instant_meilisearch/vue.mdx index 95b60ae7b7..18ce6d97b5 100644 --- a/guides/front_end/vue_quick_start.mdx +++ b/getting_started/instant_meilisearch/vue.mdx @@ -1,5 +1,6 @@ --- -title: Vue3 quick start +title: Vue quick start +sidebarTitle: Vue description: Integrate a search-as-you-type experience into your Vue app. --- @@ -113,7 +114,7 @@ Use the following CSS classes to add custom styles to your components: `.ais-InstantSearch`, `.ais-SearchBox`, `.ais-InfiniteHits-list`, `.ais-InfiniteHits-item` -## 6.Start the app and search as you type +## 6. Start the app and search as you type Start the app by running: @@ -131,4 +132,4 @@ Encountering issues? Check out the code in action in our [live demo](https://cod ## Next steps -Want to search through your own data? [Create a project](https://cloud.meilisearch.com) in the Meilisearch Dashboard. Check out our [getting started guide](/learn/getting_started/cloud_quick_start) for step-by-step instructions. +Want to search through your own data? [Create a project](https://cloud.meilisearch.com) in the Meilisearch Dashboard. Check out our [getting started guide](/getting_started/overview) for step-by-step instructions. diff --git a/getting_started/integrations/firebase.mdx b/getting_started/integrations/firebase.mdx new file mode 100644 index 0000000000..672184dbfd --- /dev/null +++ b/getting_started/integrations/firebase.mdx @@ -0,0 +1,126 @@ +--- +title: Firebase +sidebarTitle: Firebase +description: Sync your Firestore documents to Meilisearch using the official Firebase extension. +--- + +The official [firestore-meilisearch](https://github.com/meilisearch/firestore-meilisearch) extension automatically synchronizes documents from a Cloud Firestore collection to a Meilisearch index, enabling full-text search on your Firestore data. + + +[Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=docs&utm_medium=firebase) is the easiest way to get a Meilisearch instance for use with Firebase. + + +## Prerequisites + +- A Firebase project on the Blaze (pay-as-you-go) plan +- Cloud Firestore set up in your Firebase project +- A running Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) +- A Meilisearch API key with write permissions + +## Install the extension + +You can install the extension using the Firebase Console or the Firebase CLI. + + + +Visit the [Firebase Extensions Hub](https://extensions.dev/extensions/meilisearch/firestore-meilisearch) and click **Install**. + +Follow the prompts to select your Firebase project and configure the extension. + + +```bash +firebase ext:install meilisearch/firestore-meilisearch --project=YOUR_PROJECT_ID +``` + +Replace `YOUR_PROJECT_ID` with your Firebase project ID. + + + +## Configuration + +During installation, you'll configure the following parameters: + +| Parameter | Description | +|-----------|-------------| +| **Cloud Functions location** | Region where the extension's functions will be deployed | +| **Collection path** | The Firestore collection to sync (e.g., `products`, `articles`) | +| **Fields to index** | Comma-separated list of field names, or leave blank to index all fields | +| **Meilisearch index name** | The name of the Meilisearch index to sync data to | +| **Meilisearch host** | Your Meilisearch instance URL (must start with `http://` or `https://`) | +| **Meilisearch API key** | An API key with permission to manage indexes | + +## How it works + +Once installed, the extension deploys a Cloud Function called `indexingWorker` that: + +1. **Listens** for document creates, updates, and deletions in your specified collection +2. **Syncs** changes to your Meilisearch index in real-time +3. **Maps** Firestore document IDs to a `_firestore_id` field in Meilisearch + + +The extension only monitors the specified collection, not subcollections. Install additional instances to sync other collections. + + +## Data format + +### Document IDs + +Firestore document IDs are automatically mapped to a `_firestore_id` field in Meilisearch. Any field named `_firestore_id` in your source documents will be ignored. + +### Geolocation + +For geo search functionality, name your GeoPoint field `_geo` in Firestore. Meilisearch will automatically recognize it for [geo search queries](/learn/filtering_and_sorting/geosearch). + +```javascript +// Firestore document with geo data +{ + name: "Eiffel Tower", + _geo: new firebase.firestore.GeoPoint(48.8584, 2.2945) +} +``` + +## Import existing documents + +The extension only syncs documents created or modified after installation. To import existing documents, use the provided import script: + +```bash +npx @meilisearch/firestore-meilisearch-scripts import +``` + + +See the [import script documentation](https://github.com/meilisearch/firestore-meilisearch/blob/main/guides/IMPORT_EXISTING_DOCUMENTS.md) for detailed instructions. + + +## Search your data + +Once your data is synced, you can search it using any Meilisearch SDK or the REST API: + + + +```javascript +import { MeiliSearch } from 'meilisearch' + +const client = new MeiliSearch({ + host: process.env.MEILISEARCH_URL, + apiKey: process.env.MEILISEARCH_API_KEY +}) + +const results = await client.index('products').search('phone') +console.log(results.hits) +``` + + +```bash +curl "${MEILISEARCH_URL}/indexes/products/search" \ + -H "Authorization: Bearer ${MEILISEARCH_API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{"q": "phone"}' +``` + + + +## Resources + +- [GitHub repository](https://github.com/meilisearch/firestore-meilisearch) +- [Firebase Extensions Hub](https://extensions.dev/extensions/meilisearch/firestore-meilisearch) +- [Meilisearch blog: Firebase + Meilisearch](https://www.meilisearch.com/blog/firebase-meilisearch) diff --git a/getting_started/integrations/gatsby.mdx b/getting_started/integrations/gatsby.mdx new file mode 100644 index 0000000000..8b3231c730 --- /dev/null +++ b/getting_started/integrations/gatsby.mdx @@ -0,0 +1,223 @@ +--- +title: Gatsby +sidebarTitle: Gatsby +description: Index your Gatsby site content to Meilisearch using the official plugin. +--- + +The official [gatsby-plugin-meilisearch](https://github.com/meilisearch/gatsby-plugin-meilisearch) indexes your Gatsby content to Meilisearch at build time using GraphQL queries. + + +[Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=docs&utm_medium=gatsby) is the easiest way to get a Meilisearch instance for your Gatsby site. + + +## Prerequisites + +- A Gatsby project (v4.3.x or later) +- Node.js >= 14.15.x +- A running Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## Installation + +Install the plugin using npm or yarn: + + + +```bash +npm install gatsby-plugin-meilisearch +``` + + +```bash +yarn add gatsby-plugin-meilisearch +``` + + + +## Configuration + +Add the plugin to your `gatsby-config.js` file: + +```javascript +module.exports = { + plugins: [ + { + resolve: 'gatsby-plugin-meilisearch', + options: { + host: process.env.MEILISEARCH_URL, + apiKey: process.env.MEILISEARCH_API_KEY, + indexes: [ + { + indexUid: 'pages', + query: ` + query { + allMdx { + nodes { + frontmatter { + title + description + } + slug + excerpt + } + } + } + `, + transformer: (data) => + data.allMdx.nodes.map((node, index) => ({ + id: index, + title: node.frontmatter.title, + description: node.frontmatter.description, + slug: node.slug, + excerpt: node.excerpt + })) + } + ] + } + } + ] +} +``` + +## Plugin options + +| Option | Required | Default | Description | +|--------|----------|---------|-------------| +| `host` | Yes | - | Your Meilisearch instance URL | +| `apiKey` | No | - | API key (required if instance is password-protected) | +| `indexes` | Yes | - | Array of index configurations | +| `skipIndexing` | No | `false` | Skip indexing during build | +| `batchSize` | No | `1000` | Number of documents per indexing batch | + +## Index configuration + +Each index object requires three properties: + +### indexUid + +The name of your Meilisearch index. If the index already exists, it will be deleted and recreated during each build. + +```javascript +indexUid: 'blog_posts' +``` + +### query + +A GraphQL query that fetches the data you want to index: + +```javascript +query: ` + query { + allMarkdownRemark { + nodes { + frontmatter { + title + date + tags + } + html + excerpt + } + } + } +` +``` + +### transformer + +A function that transforms the GraphQL response into an array of documents for Meilisearch. Each document **must have an `id` field**: + +```javascript +transformer: (data) => + data.allMarkdownRemark.nodes.map((node, index) => ({ + id: index, + title: node.frontmatter.title, + date: node.frontmatter.date, + tags: node.frontmatter.tags, + content: node.excerpt + })) +``` + + +The transformer must return a flat array of objects. Nested structures should be flattened, and each object must include a unique `id` field. + + +## Index settings + +You can configure Meilisearch index settings like searchable attributes and filters: + +```javascript +{ + resolve: 'gatsby-plugin-meilisearch', + options: { + host: process.env.MEILISEARCH_URL, + apiKey: process.env.MEILISEARCH_API_KEY, + indexes: [ + { + indexUid: 'blog', + query: `...`, + transformer: (data) => ..., + settings: { + searchableAttributes: ['title', 'content', 'tags'], + filterableAttributes: ['tags', 'date'], + sortableAttributes: ['date'] + } + } + ] + } +} +``` + +## Build and index + +Run `gatsby build` to trigger indexing: + +```bash +gatsby build +``` + +You'll see a success message confirming documents were indexed: + +``` +gatsby-plugin-meilisearch: 42 documents added to "blog" index +``` + +## Add search to your site + +Use [instant-meilisearch](/getting_started/instant_meilisearch/javascript) to add a search interface: + +```jsx +import React from 'react' +import { InstantSearch, SearchBox, Hits } from 'react-instantsearch' +import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' + +const searchClient = instantMeiliSearch( + process.env.GATSBY_MEILISEARCH_URL, + process.env.GATSBY_MEILISEARCH_SEARCH_KEY +) + +const Search = () => ( + + + + +) + +const Hit = ({ hit }) => ( +
+

{hit.title}

+

{hit.excerpt}

+
+) + +export default Search +``` + + +Use a search-only API key (`GATSBY_MEILISEARCH_SEARCH_KEY`) for client-side search. Never expose your admin API key in the browser. + + +## Resources + +- [GitHub repository](https://github.com/meilisearch/gatsby-plugin-meilisearch) +- [Meilisearch blog: Add search to Gatsby](https://www.meilisearch.com/blog/add-a-search-bar-to-your-gatsby-project-using-meilisearch) +- [instant-meilisearch documentation](/getting_started/instant_meilisearch/javascript) diff --git a/getting_started/integrations/meilisearch_importer.mdx b/getting_started/integrations/meilisearch_importer.mdx new file mode 100644 index 0000000000..aea53c6eaf --- /dev/null +++ b/getting_started/integrations/meilisearch_importer.mdx @@ -0,0 +1,186 @@ +--- +title: Meilisearch Importer +sidebarTitle: Importer CLI +description: Efficiently import large CSV, NDJSON, or JSON datasets into Meilisearch using the official CLI tool. +--- + +The official [meilisearch-importer](https://github.com/meilisearch/meilisearch-importer) is a high-performance CLI tool for bulk importing large datasets into Meilisearch. It handles millions of documents with automatic retry logic and progress tracking. + +## Features + +- Import CSV, NDJSON, and JSON (array of objects) files +- Handle datasets from thousands to 40+ million documents +- Automatic retry logic for failed batches +- Real-time progress tracking with ETA +- Configurable batch sizes for performance tuning + +## Prerequisites + +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) +- One of: + - [Rust/Cargo](https://rustup.rs/) installed (for building from source) + - Pre-built binary from releases + +## Installation + + + +```bash +cargo install meilisearch-importer +``` + + +Download the latest release from [GitHub Releases](https://github.com/meilisearch/meilisearch-importer/releases) for your platform. + +```bash +# Example for Linux +wget https://github.com/meilisearch/meilisearch-importer/releases/latest/download/meilisearch-importer-linux-amd64 +chmod +x meilisearch-importer-linux-amd64 +mv meilisearch-importer-linux-amd64 /usr/local/bin/meilisearch-importer +``` + + + +## Basic usage + +Import a CSV file: + +```bash +meilisearch-importer \ + --url "${MEILISEARCH_URL}" \ + --api-key "${MEILISEARCH_API_KEY}" \ + --index movies \ + --file movies.csv +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" +export MEILISEARCH_API_KEY="your_api_key" +``` + + +## Supported formats + +### CSV + +```bash +meilisearch-importer --index products --file products.csv +``` + +CSV files must have a header row. The importer automatically detects column types. + +### NDJSON (Newline-delimited JSON) + +```bash +meilisearch-importer --index products --file products.ndjson +``` + +Each line must be a valid JSON object: + +```json +{"id": 1, "title": "Product A", "price": 29.99} +{"id": 2, "title": "Product B", "price": 39.99} +``` + +### JSON array + +```bash +meilisearch-importer --index products --file products.json +``` + +File must contain an array of objects: + +```json +[ + {"id": 1, "title": "Product A", "price": 29.99}, + {"id": 2, "title": "Product B", "price": 39.99} +] +``` + +## Configuration options + +| Option | Description | Default | +|--------|-------------|---------| +| `--url` | Meilisearch URL | `http://localhost:7700` | +| `--api-key` | Meilisearch API key | None | +| `--index` | Target index name | Required | +| `--file` | Input file path | Required | +| `--batch-size` | Documents per batch | `1000` | +| `--primary-key` | Primary key field | Auto-detected | + +## Performance tuning + +### Batch size + +Adjust batch size based on your document size and network: + +```bash +# Smaller documents: larger batches +meilisearch-importer --index logs --file logs.ndjson --batch-size 5000 + +# Larger documents: smaller batches +meilisearch-importer --index articles --file articles.json --batch-size 100 +``` + +### Primary key + +Specify the primary key if auto-detection fails: + +```bash +meilisearch-importer --index products --file products.csv --primary-key product_id +``` + +## Example: Import a large dataset + +Import 10 million products with progress tracking: + +```bash +meilisearch-importer \ + --url "https://ms-xxx.meilisearch.io" \ + --api-key "your_master_key" \ + --index products \ + --file products.ndjson \ + --batch-size 2000 +``` + +Output: + +``` +Importing products.ndjson to index 'products'... +[████████████████████░░░░░░░░░░░░░░░░░░░░] 52% (5.2M/10M) ETA: 12m 34s +``` + +## After import + +Verify your import: + +```bash +curl "${MEILISEARCH_URL}/indexes/products/stats" \ + -H "Authorization: Bearer ${MEILISEARCH_API_KEY}" +``` + +Test a search: + +```bash +curl "${MEILISEARCH_URL}/indexes/products/search" \ + -H "Authorization: Bearer ${MEILISEARCH_API_KEY}" \ + -d '{"q": "test"}' +``` + +## Next steps + + + + Set up searchable and filterable attributes + + + Identify and fix indexing bottlenecks + + + +## Resources + +- [meilisearch-importer on GitHub](https://github.com/meilisearch/meilisearch-importer) +- [Releases](https://github.com/meilisearch/meilisearch-importer/releases) diff --git a/getting_started/integrations/meilisync.mdx b/getting_started/integrations/meilisync.mdx new file mode 100644 index 0000000000..cff2bcfae2 --- /dev/null +++ b/getting_started/integrations/meilisync.mdx @@ -0,0 +1,283 @@ +--- +title: Meilisync +sidebarTitle: Meilisync +description: Real-time sync from MySQL, PostgreSQL, or MongoDB to Meilisearch. +--- + +[Meilisync](https://github.com/long2ice/meilisync) is a community tool that enables real-time synchronization from MySQL, PostgreSQL, or MongoDB to Meilisearch. Changes in your database are automatically reflected in your search index. + + +Meilisync is a community-maintained project, not officially supported by Meilisearch. For bugs or questions, open an issue on the [meilisync GitHub issues page](https://github.com/long2ice/meilisync/issues). + + +## Features + +- Real-time sync using database change streams (CDC) +- Support for MySQL, PostgreSQL, and MongoDB +- Multiple sync tasks for different tables/collections +- Progress tracking via file or Redis +- Plugin system for data transformation + +## Prerequisites + +- Python 3.9 or higher +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) +- A supported database with change data capture enabled + +### Database requirements + + + +Enable binary logging with row format: + +```ini +# my.cnf +[mysqld] +server-id = 1 +log_bin = mysql-bin +binlog_format = ROW +binlog_row_image = FULL +``` + + +Enable logical replication: + +```ini +# postgresql.conf +wal_level = logical +max_replication_slots = 10 +max_wal_senders = 10 +``` + +Install the wal2json extension: + +```bash +# Debian/Ubuntu +sudo apt install postgresql-14-wal2json +``` + + +Enable replica set mode: + +```yaml +# mongod.conf +replication: + replSetName: "rs0" +``` + +Initialize the replica set: + +```javascript +rs.initiate() +``` + + + +## Installation + + + +```bash +pip install meilisync +``` + +Install database-specific drivers: + +```bash +# For MySQL +pip install meilisync[mysql] + +# For PostgreSQL +pip install meilisync[postgres] + +# For MongoDB +pip install meilisync[mongo] +``` + + +```bash +docker pull long2ice/meilisync +``` + + + +## Configuration + +Create a `config.yml` file: + +```yaml +meilisearch: + api_url: https://your-instance.meilisearch.io + api_key: your_master_key + +progress: + type: file # or 'redis' + +source: + type: mysql # or 'postgres', 'mongo' + host: localhost + port: 3306 + user: root + password: password + database: myapp + +sync: + - table: products + index: products + primary_key: id + fields: + - id + - name + - description + - price + - category + + - table: articles + index: articles + primary_key: id +``` + +## Running meilisync + +Start the sync process: + +```bash +meilisync start -c config.yml +``` + + + +```bash +docker run -d \ + -v $(pwd)/config.yml:/app/config.yml \ + long2ice/meilisync \ + meilisync start -c /app/config.yml +``` + + +```yaml +version: '3.8' +services: + meilisync: + image: long2ice/meilisync + volumes: + - ./config.yml:/app/config.yml + command: meilisync start -c /app/config.yml + depends_on: + - mysql + - meilisearch +``` + + + +## Full sync + +Import all existing data before starting real-time sync: + +```bash +meilisync refresh -c config.yml +``` + +This performs a full table scan and indexes all documents. + +## Verify sync + +Check the sync is working: + +```bash +# Check Meilisearch index stats +curl "${MEILISEARCH_URL}/indexes/products/stats" \ + -H "Authorization: Bearer ${MEILISEARCH_API_KEY}" +``` + +Insert a test record in your database and verify it appears in Meilisearch within seconds. + +## Configuration options + +### Source configuration + + + +```yaml +source: + type: mysql + host: localhost + port: 3306 + user: root + password: password + database: myapp + server_id: 1 # Unique server ID for replication +``` + + +```yaml +source: + type: postgres + host: localhost + port: 5432 + user: postgres + password: password + database: myapp + slot_name: meilisync_slot # Replication slot name +``` + + +```yaml +source: + type: mongo + host: localhost + port: 27017 + database: myapp + # Optional authentication + user: root + password: password +``` + + + +### Progress storage + +Track sync progress to resume after restarts: + +```yaml +# File-based (default) +progress: + type: file + path: ./progress.json + +# Redis-based (for distributed setups) +progress: + type: redis + url: redis://localhost:6379/0 +``` + +### Field mapping + +Select specific fields and rename them: + +```yaml +sync: + - table: products + index: products + fields: + id: product_id # Rename 'id' to 'product_id' in Meilisearch + name: ~ # Keep original name + price: ~ +``` + +## Next steps + + + + Set up searchable and filterable attributes + + + Configure ranking and relevancy + + + +## Resources + +- [Meilisync on GitHub](https://github.com/long2ice/meilisync) +- [Meilisync documentation](https://github.com/long2ice/meilisync#readme) +- [Meilisync Admin Dashboard](https://github.com/long2ice/meilisync-admin) diff --git a/getting_started/integrations/postman.mdx b/getting_started/integrations/postman.mdx new file mode 100644 index 0000000000..96a06c3a72 --- /dev/null +++ b/getting_started/integrations/postman.mdx @@ -0,0 +1,51 @@ +--- +title: Postman collection for Meilisearch +sidebarTitle: Postman +description: This how-to guide explains how to use Postman when testing and debugging Meilisearch's API. +--- + +Are you tired of using the `curl` command in your terminal to test Meilisearch? It can be tedious to re-write every route when wanting to try out an API. + +Postman is a platform that lets you create HTTP requests you can easily reuse and share with everyone. We provide a [Postman collection](https://github.com/meilisearch/meilisearch-postman) containing all the routes of the Meilisearch API! 🚀 + +If you don't have Postman already, you can [download it here](https://www.postman.com/downloads/). It's free and available on many OS distributions. + +## Import the collection + +Once you have downloaded the [Postman collection](https://github.com/meilisearch/meilisearch-postman), you need to import it into Postman. + + + The 'Import' button + + +## Edit the configuration + + + Selecting 'Edit' from the overflow menu + + +Set the "Token" if needed (set to `masterKey` by default): + + + The 'Token' field set to masterKey and 'Type' to Bearer Token in the 'Authorization' tab. + + +Set `url` (set to Meilisearch's local port by default) and `indexUID` (set to `indexUID` by default): + + + Setting the 'URL' to http://localhost:7700/ and 'indexUID' to indexUID in the Variables tab. + + +The `url` and `indexUID` variables are used in all the collection routes, like in this one: + + + Highlighting {{url}} and {{indexUID}} + + +## Start to use it + +You can now [run your Meilisearch instance](/learn/self_hosted/getting_started_with_self_hosted_meilisearch#setup-and-installation) and create your first index: + + + The 'Send' button + diff --git a/guides/vercel.mdx b/getting_started/integrations/vercel.mdx similarity index 94% rename from guides/vercel.mdx rename to getting_started/integrations/vercel.mdx index f28098dc9a..068f86af45 100644 --- a/guides/vercel.mdx +++ b/getting_started/integrations/vercel.mdx @@ -1,5 +1,6 @@ --- title: Integrate Meilisearch Cloud with Vercel +sidebarTitle: Vercel description: Link Meilisearch Cloud to a Vercel Project. --- @@ -80,7 +81,7 @@ Use the `Default Search API Key` to access the [search route](/reference/api/sea The Search and Admin API keys are automatically added to Vercel along with the Meilisearch URL. For more information on the other default keys, consult the [security documentation](/learn/security/basic_security#obtaining-api-keys). -The master key–which hasn’t been added to Vercel–grants users full control over an instance. You can find it in your project’s overview on your [Meilisearch Cloud dashboard](https://cloud.meilisearch.com/projects/?utm_campaign=oss&utm_source=docs&utm_medium=vercel-integration). Read more about [Meilisearch security](https://www.meilisearch.com/docs/learn/security/master_api_keys). +The master key–which hasn’t been added to Vercel–grants users full control over an instance. You can find it in your project’s overview on your [Meilisearch Cloud dashboard](https://cloud.meilisearch.com/projects/?utm_campaign=oss&utm_source=docs&utm_medium=vercel-integration). Read more about [Meilisearch security](/learn/security/differences_master_api_keys). ### Review your project settings @@ -96,7 +97,7 @@ Go back to your project settings and check the new Meilisearch environment varia -When using [Next.js](https://nextjs.org/), ensure you prefix your browser-facing environment variables with `NEXT_PUBLIC_`. This makes them available to the browser side of your application. +When using [Next.js](https://nextjs.org/), ensure you prefix your browser-facing environment variables with `NEXT_PUBLIC_`. This makes them available to the browser side of your application. Be aware that any variable with this prefix is embedded in the client-side JavaScript bundle and visible to end users. Only use `NEXT_PUBLIC_` with the search API key, never with the admin or master key. ## Take advantage of the Meilisearch Cloud dashboard diff --git a/getting_started/overview.mdx b/getting_started/overview.mdx new file mode 100644 index 0000000000..63cbba0f93 --- /dev/null +++ b/getting_started/overview.mdx @@ -0,0 +1,57 @@ +--- +title: Welcome to Meilisearch +sidebarTitle: Overview +description: Meilisearch is a lightning-fast search engine that fits effortlessly into your apps, websites, and workflow. +--- + +Meilisearch is a **RESTful search API** that delivers fast, relevant search results in under 50 milliseconds. Whether you're building an e-commerce site, a documentation portal, or a SaaS application, Meilisearch provides a ready-to-go search solution. + + + + Get started in minutes with Meilisearch Cloud + + + Deploy on your own infrastructure + + + +## Why Meilisearch? + + + + Search results in under 50ms, even with millions of documents + + + Returns relevant results even when queries contain mistakes + + + Simple REST API with SDKs for every major language + + + Fine-tune ranking, filtering, and relevancy to your needs + + + +## See it in action + +[![Search bar updating results](/assets/images/movies-demo-dark.gif)](https://where2watch.meilisearch.com/?utm_campaign=oss&utm_source=docs&utm_medium=overview) + +Try our live demos: +- [E-commerce search](https://ecommerce.meilisearch.com/) - Browse millions of products +- [Where to Watch](https://where2watch.meilisearch.com/) - Search the TMDB movie database +- [SaaS search](https://saas.meilisearch.com/) - Multi-model search with Laravel + +## Get started with Meilisearch Cloud + +[Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=docs&utm_medium=overview) gets you up and running in minutes with automatic scaling, updates, and maintenance. Start with a [14-day free trial](https://cloud.meilisearch.com). + +## Next steps + + + + Discover all Meilisearch capabilities + + + Get started with your preferred language + + diff --git a/getting_started/sdks/dart.mdx b/getting_started/sdks/dart.mdx new file mode 100644 index 0000000000..f9adbed636 --- /dev/null +++ b/getting_started/sdks/dart.mdx @@ -0,0 +1,190 @@ +--- +title: Dart quick start +sidebarTitle: Dart +description: Get started with Meilisearch using the Dart SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Dart and Flutter. + +## Prerequisites + +- Dart 3.0 or higher (or Flutter 3.0+) +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +Add the dependency to your `pubspec.yaml`: + +```yaml +dependencies: + meilisearch: ^0.17.1 +``` + +Then run: + +```bash +dart pub get +# or for Flutter +flutter pub get +``` + +## 2. Connect to Meilisearch + +```dart +import 'package:meilisearch/meilisearch.dart'; +import 'dart:io'; + +final client = MeiliSearchClient( + Platform.environment['MEILISEARCH_URL']!, + Platform.environment['MEILISEARCH_API_KEY'], +); +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```dart +// Add documents +final movies = [ + {'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999}, + {'id': 2, 'title': 'Inception', 'genres': ['Action', 'Thriller'], 'year': 2010}, + {'id': 3, 'title': 'Interstellar', 'genres': ['Drama', 'Sci-Fi'], 'year': 2014}, +]; + +final index = client.index('movies'); +final task = await index.addDocuments(movies); + +// Wait for indexing to complete +await client.waitForTask(task.taskUid); +``` + +## 4. Search + +```dart +final result = await index.search('matrix'); + +for (final hit in result.hits) { + print('${hit['title']} (${hit['year']})'); +} +// The Matrix (1999) +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```dart +await index.updateFilterableAttributes(['genres', 'year']); +``` + +Then search with filters: + +```dart +final result = await index.search( + '', + SearchQuery(filter: 'genres = "Sci-Fi" AND year > 2000'), +); +``` + +## Full example + +```dart +import 'package:meilisearch/meilisearch.dart'; +import 'dart:io'; + +void main() async { + // Connect + final client = MeiliSearchClient( + Platform.environment['MEILISEARCH_URL']!, + Platform.environment['MEILISEARCH_API_KEY'], + ); + + // Add documents + final movies = [ + {'id': 1, 'title': 'The Matrix', 'year': 1999}, + {'id': 2, 'title': 'Inception', 'year': 2010}, + {'id': 3, 'title': 'Interstellar', 'year': 2014}, + ]; + + final index = client.index('movies'); + final task = await index.addDocuments(movies); + await client.waitForTask(task.taskUid); + + // Search + final result = await index.search('inter'); + for (final hit in result.hits) { + print(hit['title']); + } +} +``` + +## Flutter example + +```dart +import 'package:flutter/material.dart'; +import 'package:meilisearch/meilisearch.dart'; + +class SearchScreen extends StatefulWidget { + @override + _SearchScreenState createState() => _SearchScreenState(); +} + +class _SearchScreenState extends State { + final client = MeiliSearchClient('YOUR_MEILISEARCH_URL', 'YOUR_SEARCH_KEY'); + List> results = []; + + Future search(String query) async { + final result = await client.index('movies').search(query); + setState(() { + results = List>.from(result.hits); + }); + } + + @override + Widget build(BuildContext context) { + return Column( + children: [ + TextField(onChanged: search), + Expanded( + child: ListView.builder( + itemCount: results.length, + itemBuilder: (context, index) => ListTile( + title: Text(results[index]['title']), + ), + ), + ), + ], + ); + } +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-dart on GitHub](https://github.com/meilisearch/meilisearch-dart) +- [Package on pub.dev](https://pub.dev/packages/meilisearch) diff --git a/getting_started/sdks/dotnet.mdx b/getting_started/sdks/dotnet.mdx new file mode 100644 index 0000000000..87096a44e0 --- /dev/null +++ b/getting_started/sdks/dotnet.mdx @@ -0,0 +1,155 @@ +--- +title: .NET quick start +sidebarTitle: .NET +description: Get started with Meilisearch using the .NET SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with .NET (C#). + +## Prerequisites + +- .NET 6.0 or higher +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + + + +```bash +dotnet add package MeiliSearch +``` + + +```bash +Install-Package MeiliSearch +``` + + + +## 2. Connect to Meilisearch + +```csharp +using Meilisearch; + +var client = new MeilisearchClient( + Environment.GetEnvironmentVariable("MEILISEARCH_URL"), + Environment.GetEnvironmentVariable("MEILISEARCH_API_KEY") +); +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```csharp +// Define your document class +public class Movie +{ + public int Id { get; set; } + public string Title { get; set; } + public string[] Genres { get; set; } + public int Year { get; set; } +} + +// Add documents +var movies = new Movie[] +{ + new Movie { Id = 1, Title = "The Matrix", Genres = new[] { "Action", "Sci-Fi" }, Year = 1999 }, + new Movie { Id = 2, Title = "Inception", Genres = new[] { "Action", "Thriller" }, Year = 2010 }, + new Movie { Id = 3, Title = "Interstellar", Genres = new[] { "Drama", "Sci-Fi" }, Year = 2014 } +}; + +var index = client.Index("movies"); +var task = await index.AddDocumentsAsync(movies); + +// Wait for indexing to complete +await client.WaitForTaskAsync(task.TaskUid); +``` + +## 4. Search + +```csharp +var results = await index.SearchAsync("matrix"); + +foreach (var hit in results.Hits) +{ + Console.WriteLine($"{hit.Title} ({hit.Year})"); +} +// The Matrix (1999) +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```csharp +await index.UpdateFilterableAttributesAsync(new[] { "genres", "year" }); +``` + +Then search with filters: + +```csharp +var results = await index.SearchAsync("", new SearchQuery +{ + Filter = "genres = \"Sci-Fi\" AND year > 2000" +}); +``` + +## Full example + +```csharp +using Meilisearch; + +var client = new MeilisearchClient( + Environment.GetEnvironmentVariable("MEILISEARCH_URL"), + Environment.GetEnvironmentVariable("MEILISEARCH_API_KEY") +); + +// Add documents +var movies = new[] +{ + new { Id = 1, Title = "The Matrix", Year = 1999 }, + new { Id = 2, Title = "Inception", Year = 2010 }, + new { Id = 3, Title = "Interstellar", Year = 2014 } +}; + +var index = client.Index("movies"); +var task = await index.AddDocumentsAsync(movies); +await client.WaitForTaskAsync(task.TaskUid); + +// Search +var results = await index.SearchAsync("inter"); +foreach (var hit in results.Hits) +{ + Console.WriteLine(hit); +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-dotnet on GitHub](https://github.com/meilisearch/meilisearch-dotnet) +- [SDK documentation](https://github.com/meilisearch/meilisearch-dotnet#readme) diff --git a/getting_started/sdks/go.mdx b/getting_started/sdks/go.mdx new file mode 100644 index 0000000000..aa22683d79 --- /dev/null +++ b/getting_started/sdks/go.mdx @@ -0,0 +1,155 @@ +--- +title: Go quick start +sidebarTitle: Go +description: Get started with Meilisearch using the Go SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Go. + +## Prerequisites + +- Go 1.16 or higher +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +```bash +go get github.com/meilisearch/meilisearch-go +``` + +## 2. Connect to Meilisearch + +```go +package main + +import ( + "os" + "github.com/meilisearch/meilisearch-go" +) + +func main() { + client := meilisearch.New( + os.Getenv("MEILISEARCH_URL"), + meilisearch.WithAPIKey(os.Getenv("MEILISEARCH_API_KEY")), + ) +} +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```go +type Movie struct { + ID int `json:"id"` + Title string `json:"title"` + Genres []string `json:"genres"` + Year int `json:"year"` +} + +movies := []Movie{ + {ID: 1, Title: "The Matrix", Genres: []string{"Action", "Sci-Fi"}, Year: 1999}, + {ID: 2, Title: "Inception", Genres: []string{"Action", "Thriller"}, Year: 2010}, + {ID: 3, Title: "Interstellar", Genres: []string{"Drama", "Sci-Fi"}, Year: 2014}, +} + +// Add documents to the 'movies' index +task, _ := client.Index("movies").AddDocuments(movies) + +// Wait for indexing to complete +client.WaitForTask(task.TaskUID) +``` + +## 4. Search + +```go +results, _ := client.Index("movies").Search("matrix", nil) + +fmt.Println(results.Hits) +// [map[id:1 title:The Matrix genres:[Action Sci-Fi] year:1999]] +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```go +client.Index("movies").UpdateFilterableAttributes(&[]string{"genres", "year"}) +``` + +Then search with filters: + +```go +results, _ := client.Index("movies").Search("", &meilisearch.SearchRequest{ + Filter: "genres = 'Sci-Fi' AND year > 2000", +}) +``` + +## Full example + +```go +package main + +import ( + "fmt" + "os" + "github.com/meilisearch/meilisearch-go" +) + +type Movie struct { + ID int `json:"id"` + Title string `json:"title"` + Genres []string `json:"genres"` + Year int `json:"year"` +} + +func main() { + client := meilisearch.New( + os.Getenv("MEILISEARCH_URL"), + meilisearch.WithAPIKey(os.Getenv("MEILISEARCH_API_KEY")), + ) + + // Add documents + movies := []Movie{ + {ID: 1, Title: "The Matrix", Genres: []string{"Action", "Sci-Fi"}, Year: 1999}, + {ID: 2, Title: "Inception", Genres: []string{"Action", "Thriller"}, Year: 2010}, + {ID: 3, Title: "Interstellar", Genres: []string{"Drama", "Sci-Fi"}, Year: 2014}, + } + + task, _ := client.Index("movies").AddDocuments(movies) + client.WaitForTask(task.TaskUID) + + // Search + results, _ := client.Index("movies").Search("inter", nil) + fmt.Println(results.Hits) +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-go on GitHub](https://github.com/meilisearch/meilisearch-go) +- [SDK documentation](https://pkg.go.dev/github.com/meilisearch/meilisearch-go) diff --git a/getting_started/sdks/java.mdx b/getting_started/sdks/java.mdx new file mode 100644 index 0000000000..f394d90958 --- /dev/null +++ b/getting_started/sdks/java.mdx @@ -0,0 +1,176 @@ +--- +title: Java quick start +sidebarTitle: Java +description: Get started with Meilisearch using the Java SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Java. + +## Prerequisites + +- Java 17 or higher +- Maven or Gradle +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + + + +```xml + + com.meilisearch.sdk + meilisearch-java + 0.17.1 + +``` + + +```groovy +implementation 'com.meilisearch.sdk:meilisearch-java:0.17.1' +``` + + + +## 2. Connect to Meilisearch + +```java +import com.meilisearch.sdk.Client; +import com.meilisearch.sdk.Config; + +public class Main { + public static void main(String[] args) { + Client client = new Client(new Config( + System.getenv("MEILISEARCH_URL"), + System.getenv("MEILISEARCH_API_KEY") + )); + } +} +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```java +import com.meilisearch.sdk.Index; +import com.meilisearch.sdk.model.TaskInfo; + +// Define your document class +class Movie { + public int id; + public String title; + public String[] genres; + public int year; + + public Movie(int id, String title, String[] genres, int year) { + this.id = id; + this.title = title; + this.genres = genres; + this.year = year; + } +} + +// Add documents +Movie[] movies = { + new Movie(1, "The Matrix", new String[]{"Action", "Sci-Fi"}, 1999), + new Movie(2, "Inception", new String[]{"Action", "Thriller"}, 2010), + new Movie(3, "Interstellar", new String[]{"Drama", "Sci-Fi"}, 2014) +}; + +Index index = client.index("movies"); +TaskInfo task = index.addDocuments(new Gson().toJson(movies)); + +// Wait for indexing to complete +client.waitForTask(task.getTaskUid()); +``` + +## 4. Search + +```java +import com.meilisearch.sdk.SearchRequest; +import com.meilisearch.sdk.model.SearchResult; + +SearchResult results = index.search("matrix"); + +System.out.println(results.getHits()); +// [{id=1, title=The Matrix, genres=[Action, Sci-Fi], year=1999}] +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```java +index.updateFilterableAttributesSettings(new String[]{"genres", "year"}); +``` + +Then search with filters: + +```java +SearchRequest searchRequest = new SearchRequest("matrix") + .setFilter(new String[]{"genres = \"Sci-Fi\"", "year > 2000"}); + +SearchResult results = index.search(searchRequest); +``` + +## Full example + +```java +import com.meilisearch.sdk.*; +import com.meilisearch.sdk.model.*; +import com.google.gson.Gson; + +public class Main { + public static void main(String[] args) throws Exception { + // Connect + Client client = new Client(new Config( + System.getenv("MEILISEARCH_URL"), + System.getenv("MEILISEARCH_API_KEY") + )); + + // Add documents + String documents = "[" + + "{\"id\": 1, \"title\": \"The Matrix\", \"year\": 1999}," + + "{\"id\": 2, \"title\": \"Inception\", \"year\": 2010}," + + "{\"id\": 3, \"title\": \"Interstellar\", \"year\": 2014}" + + "]"; + + Index index = client.index("movies"); + TaskInfo task = index.addDocuments(documents); + client.waitForTask(task.getTaskUid()); + + // Search + SearchResult results = index.search("inter"); + System.out.println(results.getHits()); + } +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-java on GitHub](https://github.com/meilisearch/meilisearch-java) +- [SDK documentation](https://github.com/meilisearch/meilisearch-java#readme) diff --git a/getting_started/sdks/javascript.mdx b/getting_started/sdks/javascript.mdx new file mode 100644 index 0000000000..a440432323 --- /dev/null +++ b/getting_started/sdks/javascript.mdx @@ -0,0 +1,133 @@ +--- +title: JavaScript quick start +sidebarTitle: JavaScript +description: Get started with Meilisearch using the JavaScript SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with JavaScript/Node.js. + +## Prerequisites + +- Node.js 14 or higher +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +```bash +npm install meilisearch +# or +yarn add meilisearch +``` + +## 2. Connect to Meilisearch + +```javascript +import { MeiliSearch } from 'meilisearch' + +const client = new MeiliSearch({ + host: process.env.MEILISEARCH_URL, + apiKey: process.env.MEILISEARCH_API_KEY +}) +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```javascript +const movies = [ + { id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 }, + { id: 2, title: 'Inception', genres: ['Action', 'Thriller'], year: 2010 }, + { id: 3, title: 'Interstellar', genres: ['Drama', 'Sci-Fi'], year: 2014 } +] + +// Add documents to the 'movies' index +const task = await client.index('movies').addDocuments(movies) + +// Wait for indexing to complete +await client.waitForTask(task.taskUid) +``` + +## 4. Search + +```javascript +const results = await client.index('movies').search('matrix') + +console.log(results.hits) +// [{ id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 }] +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```javascript +await client.index('movies').updateFilterableAttributes(['genres', 'year']) +``` + +Then search with filters: + +```javascript +const results = await client.index('movies').search('', { + filter: 'genres = "Sci-Fi" AND year > 2000' +}) +``` + +## Full example + +```javascript +import { MeiliSearch } from 'meilisearch' + +const client = new MeiliSearch({ + host: process.env.MEILISEARCH_URL, + apiKey: process.env.MEILISEARCH_API_KEY +}) + +async function main() { + // Add documents + const movies = [ + { id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 }, + { id: 2, title: 'Inception', genres: ['Action', 'Thriller'], year: 2010 }, + { id: 3, title: 'Interstellar', genres: ['Drama', 'Sci-Fi'], year: 2014 } + ] + + const task = await client.index('movies').addDocuments(movies) + await client.waitForTask(task.taskUid) + + // Search + const results = await client.index('movies').search('inter') + console.log(results.hits) +} + +main() +``` + +## Next steps + + + + Add search to your React, Vue, or Angular app + + + Configure ranking and relevancy + + + Add filters and facets + + + Explore all search parameters + + + +## Resources + +- [meilisearch-js on GitHub](https://github.com/meilisearch/meilisearch-js) +- [SDK documentation](https://github.com/meilisearch/meilisearch-js#readme) +- [instant-meilisearch](https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch) - InstantSearch adapter diff --git a/getting_started/sdks/php.mdx b/getting_started/sdks/php.mdx new file mode 100644 index 0000000000..b2cdef248d --- /dev/null +++ b/getting_started/sdks/php.mdx @@ -0,0 +1,154 @@ +--- +title: PHP quick start +sidebarTitle: PHP +description: Get started with Meilisearch using the PHP SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with PHP. + +## Prerequisites + +- PHP 7.4 or higher +- Composer +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +```bash +composer require meilisearch/meilisearch-php +``` + +## 2. Connect to Meilisearch + +```php + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```php +$movies = [ + ['id' => 1, 'title' => 'The Matrix', 'genres' => ['Action', 'Sci-Fi'], 'year' => 1999], + ['id' => 2, 'title' => 'Inception', 'genres' => ['Action', 'Thriller'], 'year' => 2010], + ['id' => 3, 'title' => 'Interstellar', 'genres' => ['Drama', 'Sci-Fi'], 'year' => 2014] +]; + +// Add documents to the 'movies' index +$task = $client->index('movies')->addDocuments($movies); + +// Wait for indexing to complete +$client->waitForTask($task['taskUid']); +``` + +## 4. Search + +```php +$results = $client->index('movies')->search('matrix'); + +print_r($results->getHits()); +// [['id' => 1, 'title' => 'The Matrix', 'genres' => ['Action', 'Sci-Fi'], 'year' => 1999]] +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```php +$client->index('movies')->updateFilterableAttributes(['genres', 'year']); +``` + +Then search with filters: + +```php +$results = $client->index('movies')->search('', [ + 'filter' => 'genres = "Sci-Fi" AND year > 2000' +]); +``` + +## Full example + +```php + 1, 'title' => 'The Matrix', 'genres' => ['Action', 'Sci-Fi'], 'year' => 1999], + ['id' => 2, 'title' => 'Inception', 'genres' => ['Action', 'Thriller'], 'year' => 2010], + ['id' => 3, 'title' => 'Interstellar', 'genres' => ['Drama', 'Sci-Fi'], 'year' => 2014] +]; + +$task = $client->index('movies')->addDocuments($movies); +$client->waitForTask($task['taskUid']); + +// Search +$results = $client->index('movies')->search('inter'); +print_r($results->getHits()); +``` + +## Laravel integration + +For Laravel applications, use Laravel Scout with the Meilisearch driver: + +```bash +composer require laravel/scout +php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider" +``` + +Configure in your `.env`: + +```env +SCOUT_DRIVER=meilisearch +MEILISEARCH_HOST=https://your-instance.meilisearch.io +MEILISEARCH_KEY=your_api_key +``` + +[See the full Laravel Scout guide →](/getting_started/frameworks/laravel) + +## Next steps + + + + Full Laravel integration guide + + + Configure ranking and relevancy + + + Add filters and facets + + + Explore all search parameters + + + +## Resources + +- [meilisearch-php on GitHub](https://github.com/meilisearch/meilisearch-php) +- [SDK documentation](https://github.com/meilisearch/meilisearch-php#readme) diff --git a/getting_started/sdks/python.mdx b/getting_started/sdks/python.mdx new file mode 100644 index 0000000000..4310b87f41 --- /dev/null +++ b/getting_started/sdks/python.mdx @@ -0,0 +1,128 @@ +--- +title: Python quick start +sidebarTitle: Python +description: Get started with Meilisearch using the Python SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Python. + +## Prerequisites + +- Python 3.8 or higher +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +```bash +pip install meilisearch +``` + +## 2. Connect to Meilisearch + +```python +import meilisearch +import os + +client = meilisearch.Client( + os.environ.get('MEILISEARCH_URL'), + os.environ.get('MEILISEARCH_API_KEY') +) +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```python +movies = [ + {'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999}, + {'id': 2, 'title': 'Inception', 'genres': ['Action', 'Thriller'], 'year': 2010}, + {'id': 3, 'title': 'Interstellar', 'genres': ['Drama', 'Sci-Fi'], 'year': 2014} +] + +# Add documents to the 'movies' index +task = client.index('movies').add_documents(movies) + +# Wait for indexing to complete +client.wait_for_task(task.task_uid) +``` + +## 4. Search + +```python +results = client.index('movies').search('matrix') + +print(results['hits']) +# [{'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999}] +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```python +client.index('movies').update_filterable_attributes(['genres', 'year']) +``` + +Then search with filters: + +```python +results = client.index('movies').search('', { + 'filter': 'genres = "Sci-Fi" AND year > 2000' +}) +``` + +## Full example + +```python +import meilisearch +import os + +client = meilisearch.Client( + os.environ.get('MEILISEARCH_URL'), + os.environ.get('MEILISEARCH_API_KEY') +) + +# Add documents +movies = [ + {'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999}, + {'id': 2, 'title': 'Inception', 'genres': ['Action', 'Thriller'], 'year': 2010}, + {'id': 3, 'title': 'Interstellar', 'genres': ['Drama', 'Sci-Fi'], 'year': 2014} +] + +task = client.index('movies').add_documents(movies) +client.wait_for_task(task.task_uid) + +# Search +results = client.index('movies').search('inter') +print(results['hits']) +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-python on GitHub](https://github.com/meilisearch/meilisearch-python) +- [SDK documentation](https://github.com/meilisearch/meilisearch-python#readme) diff --git a/getting_started/sdks/ruby.mdx b/getting_started/sdks/ruby.mdx new file mode 100644 index 0000000000..4888fa6814 --- /dev/null +++ b/getting_started/sdks/ruby.mdx @@ -0,0 +1,156 @@ +--- +title: Ruby quick start +sidebarTitle: Ruby +description: Get started with Meilisearch using the Ruby SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Ruby. + +## Prerequisites + +- Ruby 2.7 or higher +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +```bash +gem install meilisearch +``` + +Or add to your Gemfile: + +```ruby +gem 'meilisearch' +``` + +## 2. Connect to Meilisearch + +```ruby +require 'meilisearch' + +client = MeiliSearch::Client.new( + ENV['MEILISEARCH_URL'], + ENV['MEILISEARCH_API_KEY'] +) +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```ruby +movies = [ + { id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 }, + { id: 2, title: 'Inception', genres: ['Action', 'Thriller'], year: 2010 }, + { id: 3, title: 'Interstellar', genres: ['Drama', 'Sci-Fi'], year: 2014 } +] + +# Add documents to the 'movies' index +task = client.index('movies').add_documents(movies) + +# Wait for indexing to complete +client.wait_for_task(task['taskUid']) +``` + +## 4. Search + +```ruby +results = client.index('movies').search('matrix') + +puts results['hits'] +# [{"id"=>1, "title"=>"The Matrix", "genres"=>["Action", "Sci-Fi"], "year"=>1999}] +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```ruby +client.index('movies').update_filterable_attributes(['genres', 'year']) +``` + +Then search with filters: + +```ruby +results = client.index('movies').search('', { + filter: 'genres = "Sci-Fi" AND year > 2000' +}) +``` + +## Full example + +```ruby +require 'meilisearch' + +client = MeiliSearch::Client.new( + ENV['MEILISEARCH_URL'], + ENV['MEILISEARCH_API_KEY'] +) + +# Add documents +movies = [ + { id: 1, title: 'The Matrix', genres: ['Action', 'Sci-Fi'], year: 1999 }, + { id: 2, title: 'Inception', genres: ['Action', 'Thriller'], year: 2010 }, + { id: 3, title: 'Interstellar', genres: ['Drama', 'Sci-Fi'], year: 2014 } +] + +task = client.index('movies').add_documents(movies) +client.wait_for_task(task['taskUid']) + +# Search +results = client.index('movies').search('inter') +puts results['hits'] +``` + +## Rails integration + +For Rails applications, use the meilisearch-rails gem: + +```bash +gem install meilisearch-rails +``` + +Add to your model: + +```ruby +class Movie < ApplicationRecord + include MeiliSearch::Rails + + meilisearch do + attribute :title, :genres, :year + searchable_attributes [:title] + filterable_attributes [:genres, :year] + end +end +``` + +[See the full Rails guide →](/getting_started/frameworks/rails) + +## Next steps + + + + Full Rails integration guide + + + Configure ranking and relevancy + + + Add filters and facets + + + Explore all search parameters + + + +## Resources + +- [meilisearch-ruby on GitHub](https://github.com/meilisearch/meilisearch-ruby) +- [meilisearch-rails on GitHub](https://github.com/meilisearch/meilisearch-rails) diff --git a/getting_started/sdks/rust.mdx b/getting_started/sdks/rust.mdx new file mode 100644 index 0000000000..9efa84f9c8 --- /dev/null +++ b/getting_started/sdks/rust.mdx @@ -0,0 +1,178 @@ +--- +title: Rust quick start +sidebarTitle: Rust +description: Get started with Meilisearch using the Rust SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Rust. + +## Prerequisites + +- Rust stable (1.65+) +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + +Add to your `Cargo.toml`: + +```toml +[dependencies] +meilisearch-sdk = "0.27" +tokio = { version = "1", features = ["full"] } +serde = { version = "1", features = ["derive"] } +``` + +## 2. Connect to Meilisearch + +```rust +use meilisearch_sdk::client::Client; +use std::env; + +#[tokio::main] +async fn main() { + let client = Client::new( + env::var("MEILISEARCH_URL").unwrap(), + Some(env::var("MEILISEARCH_API_KEY").unwrap()) + ).unwrap(); +} +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```rust +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +struct Movie { + id: i32, + title: String, + genres: Vec, + year: i32, +} + +let movies = vec![ + Movie { id: 1, title: "The Matrix".to_string(), genres: vec!["Action".to_string(), "Sci-Fi".to_string()], year: 1999 }, + Movie { id: 2, title: "Inception".to_string(), genres: vec!["Action".to_string(), "Thriller".to_string()], year: 2010 }, + Movie { id: 3, title: "Interstellar".to_string(), genres: vec!["Drama".to_string(), "Sci-Fi".to_string()], year: 2014 }, +]; + +// Add documents to the 'movies' index +let task = client.index("movies").add_documents(&movies, Some("id")).await.unwrap(); + +// Wait for indexing to complete +task.wait_for_completion(&client, None, None).await.unwrap(); +``` + +## 4. Search + +```rust +let results: SearchResults = client + .index("movies") + .search() + .with_query("matrix") + .execute() + .await + .unwrap(); + +println!("{:?}", results.hits); +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```rust +client.index("movies") + .set_filterable_attributes(&["genres", "year"]) + .await + .unwrap(); +``` + +Then search with filters: + +```rust +let results: SearchResults = client + .index("movies") + .search() + .with_filter(r#"genres = "Sci-Fi" AND year > 2000"#) + .execute() + .await + .unwrap(); +``` + +## Full example + +```rust +use meilisearch_sdk::client::Client; +use meilisearch_sdk::search::SearchResults; +use serde::{Deserialize, Serialize}; +use std::env; + +#[derive(Serialize, Deserialize, Debug)] +struct Movie { + id: i32, + title: String, + genres: Vec, + year: i32, +} + +#[tokio::main] +async fn main() { + let client = Client::new( + env::var("MEILISEARCH_URL").unwrap(), + Some(env::var("MEILISEARCH_API_KEY").unwrap()) + ).unwrap(); + + // Add documents + let movies = vec![ + Movie { id: 1, title: "The Matrix".to_string(), genres: vec!["Action".to_string(), "Sci-Fi".to_string()], year: 1999 }, + Movie { id: 2, title: "Inception".to_string(), genres: vec!["Action".to_string(), "Thriller".to_string()], year: 2010 }, + Movie { id: 3, title: "Interstellar".to_string(), genres: vec!["Drama".to_string(), "Sci-Fi".to_string()], year: 2014 }, + ]; + + let task = client.index("movies").add_documents(&movies, Some("id")).await.unwrap(); + task.wait_for_completion(&client, None, None).await.unwrap(); + + // Search + let results: SearchResults = client + .index("movies") + .search() + .with_query("inter") + .execute() + .await + .unwrap(); + + println!("{:?}", results.hits); +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-rust on GitHub](https://github.com/meilisearch/meilisearch-rust) +- [SDK documentation](https://docs.rs/meilisearch-sdk) diff --git a/getting_started/sdks/swift.mdx b/getting_started/sdks/swift.mdx new file mode 100644 index 0000000000..9a2a15d29a --- /dev/null +++ b/getting_started/sdks/swift.mdx @@ -0,0 +1,172 @@ +--- +title: Swift quick start +sidebarTitle: Swift +description: Get started with Meilisearch using the Swift SDK in 5 minutes. +--- + +This guide walks you through setting up Meilisearch with Swift for iOS, macOS, and server-side Swift applications. + +## Prerequisites + +- Swift 5.5 or higher +- Xcode 13+ (for iOS/macOS development) +- A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](/learn/self_hosted/getting_started_with_self_hosted_meilisearch)) + +## 1. Install the SDK + + + +Add the dependency to your `Package.swift`: + +```swift +dependencies: [ + .package(url: "https://github.com/meilisearch/meilisearch-swift.git", from: "0.17.0") +] +``` + +Or in Xcode: File → Add Packages → Enter the repository URL. + + +Add to your `Podfile`: + +```ruby +pod 'MeiliSearch' +``` + +Then run `pod install`. + + + +## 2. Connect to Meilisearch + +```swift +import MeiliSearch + +let client = try! MeiliSearch( + host: ProcessInfo.processInfo.environment["MEILISEARCH_URL"]!, + apiKey: ProcessInfo.processInfo.environment["MEILISEARCH_API_KEY"] +) +``` + + +**Set your environment variables:** +```bash +export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700 +export MEILISEARCH_API_KEY="your_api_key" +``` +[Get a free Cloud instance →](https://cloud.meilisearch.com) + + +## 3. Add documents + +```swift +// Define your document struct +struct Movie: Codable, Equatable { + let id: Int + let title: String + let genres: [String] + let year: Int +} + +// Add documents +let movies = [ + Movie(id: 1, title: "The Matrix", genres: ["Action", "Sci-Fi"], year: 1999), + Movie(id: 2, title: "Inception", genres: ["Action", "Thriller"], year: 2010), + Movie(id: 3, title: "Interstellar", genres: ["Drama", "Sci-Fi"], year: 2014) +] + +let index = client.index("movies") + +// Using async/await +let task = try await index.addDocuments(documents: movies) +try await client.waitForTask(taskUid: task.taskUid) +``` + +## 4. Search + +```swift +let searchResult: Searchable = try await index.search("matrix") + +for hit in searchResult.hits { + print("\(hit.title) (\(hit.year))") +} +// The Matrix (1999) +``` + +## 5. Search with filters + +First, configure filterable attributes: + +```swift +try await index.updateFilterableAttributes(["genres", "year"]) +``` + +Then search with filters: + +```swift +let searchParams = SearchParameters( + query: "", + filter: "genres = \"Sci-Fi\" AND year > 2000" +) + +let results: Searchable = try await index.search(searchParams) +``` + +## Full example + +```swift +import MeiliSearch + +// Connect +let client = try! MeiliSearch( + host: ProcessInfo.processInfo.environment["MEILISEARCH_URL"]!, + apiKey: ProcessInfo.processInfo.environment["MEILISEARCH_API_KEY"] +) + +struct Movie: Codable, Equatable { + let id: Int + let title: String + let year: Int +} + +Task { + // Add documents + let movies = [ + Movie(id: 1, title: "The Matrix", year: 1999), + Movie(id: 2, title: "Inception", year: 2010), + Movie(id: 3, title: "Interstellar", year: 2014) + ] + + let index = client.index("movies") + let task = try await index.addDocuments(documents: movies) + try await client.waitForTask(taskUid: task.taskUid) + + // Search + let results: Searchable = try await index.search("inter") + for hit in results.hits { + print(hit.title) + } +} +``` + +## Next steps + + + + Configure ranking and relevancy + + + Add filters and facets + + + Add semantic search + + + Explore all search parameters + + + +## Resources + +- [meilisearch-swift on GitHub](https://github.com/meilisearch/meilisearch-swift) +- [SDK documentation](https://github.com/meilisearch/meilisearch-swift#readme)