Searchable Data Model Property

In this chapter, you'll learn what a searchable property is and how to define it.

What is a Searchable Property?#

Methods generated by the service factory that accept filters, such as list{ModelName}s, accept a q property as part of the filters.

When the q filter is passed, the data model's searchable properties are queried to find matching records.


Define a Searchable Property#

Use the searchable method on a text property to indicate that it's searchable.

For example:

Code
1import { model } from "@medusajs/framework/utils"2
3const MyCustom = model.define("my_custom", {4  name: model.text().searchable(),5  // ...6})7
8export default MyCustom

In this example, the name property is searchable.

Search Example#

If you pass a q filter to the listMyCustoms method:

Code
1const myCustoms = await helloModuleService.listMyCustoms({2  q: "John",3})

This retrieves records that include John in their name property.

Was this chapter helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break