Language
Search allows you to find different kinds of content including kits, pages and assets.
LingoJS uses a Search object to build and perform search queries.
The first thing to consider when building a search is the context and type of content you are looking for. By default results will include results for content within kits such as assets, notes and guides but you can also search kits, pages, headings as well as assets and tags in the library.
Typescript
const content = await lingo.search().fetch(); // Default
const kits = await lingo.search().kits().fetch();
const sections = await lingo.search().sections().fetch();
const headings = await lingo.search().headings().fetch();
// Library
const assets = await lingo.search().assets().fetch();
const tags = await lingo.search().tags().fetch();
Only call one context function when building a search.
.assets()` will search assets in the library, not items in kits.
A search response includes the total number of results, the offset, the limit, and the results themselves.
Each search context will return different types of objects as results. For example, the default "content" context results will contain items (a note or an asset from a kit) while .assets() will return an asset and .tags() a tag object.
Typescript
interface SearchResult {
total: number;
offset: number;
limit: number;
results: {
type: "item" | "section" | "kit" | "asset";
object: Item | Kit | Section | Asset;
}[];
}
Typescript
const content = await lingo.search().fetch(); // Default
content.results[0].object; // Item
const kits = await lingo.search().kits().fetch();
content.results[0].object; // Kit
const sections = await lingo.search().sections().fetch();
content.results[0].object; // Page
const headings = await lingo.search().headings().fetch();
content.results[0].object; // Item of type heading
// Library
const assets = await lingo.search().assets().fetch();
content.results[0].object; // Asset
const tags = await lingo.search().tags().fetch();
content.results[0].object; // Tag
There are a number of different filters you can use to narrow down your search results.
Some filter functions can be included more than once. The resulting query in some cases will use an OR operator for those values. Details for each filter can be found below.
Kit filters can be applied to global searches as well as library asset queries. Multiple kit filters will be combined with an OR operator.
Version defaults to 0.
Typescript
// Search for content in v0 of a specific kit
const result = await lingo.search().inKit(kitId, 1);
// Search for assets from the library in select kits
const result = await lingo.search().inKit(kitId1).inKit(kitId2);
Type filters narrow results by content type. This can mean different things for different object types. For example a content query for type="Heading" will return heading items. A library asset query for type="Fonts" will return font assets.
Multiple type filters will be combined with an OR operator.
Typescript
// Search for Guides across all kits
const result = await lingo.search().ofType("Guides");
// Search for PNG assets from the library
const result = await lingo.search().assets().ofType("PNG");
Orientation filters filter results based on the orientation of the file. Multiple orientation filters will be combined with an OR operator. When applied, assets with no dimensions such as color are excluded.
Supported values are horizontal, vertical and square;
Typescript
// Find square assets
const result = await lingo.search().orientation("square");
Keyword filters match results on multiple fields including names, tags, text content, and inferred colors. Multiple keyword filters will be combined with an AND operator.
Typescript
// Search for content matching "branding"
const result = await lingo.search().matchingKeyword("branding");
Tag filters can be applied to content and any library query. Multiple tag filters will be combined with an AND operator.
This is the only valid filter for searching tags.
Typescript
// Search for content in a specific kit
const result = await lingo.search().withTag("Brand");
// Search for assets with both tags
const result = await lingo.search().withTag("Brand").withTag("Logo");
Date filters filter results based on the date the content was added to Lingo.
Only one before and after filter may be included in a single query.
Typescript
// Search for content created on a specific date
const result = await lingo.search().createdAt({ exactly: "2023-02-15" });
// Search for content created between two dates
const result = await lingo.search().createdAt({ after: "2023-02-01", before: "2023-03-01" });
Returns a list of all kits matching "Brand".
Typescript
const response = await lingo.search().kits().matchingKeyword("Brand").fetch();
const kits = response.results.map(res => res.object);
Returns items in a specific kit that match the keyword "logo".
Typescript
const result = await lingo
.search()
.inKit(kitId) // in a specific kit
.matchingKeyword("Logo") // name, tag or description contains logo
.fetch();
console.log(`Found ${result.total} matches!`);
const items = result.results.map(res => res.object);
Returns asset objects from the library that contain the tag "logo".
Typescript
const result = await lingo
.search()
.assets() // search assets in the library
.withTag("Logo") // name, tag or description contains logo
.fetch();
console.log(`Found ${result.total} matches!`);
const assets = result.results.map(res => res.object);
Returns tags that contain the text "primary"
Typescript
const result = await lingo
.search()
.tags() // search tags in the library
.withTag("primary") // Tags that contain "primary"
.fetch();
console.log(`Found ${result.total} matches!`);
const tags = result.results.map(res => res.object);