Guide
Search

Search allows you to find differnt kinds of content including kits, sections and assets.

LingoJS uses a Search object to build and perform search queries.

Context and Types

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, sections, headings as well as assets and tags in the library.

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.

Search Results

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.

interface SearchResult {
  total: number;
  offset: number;
  limit: number;
  results: {
    type: "item" | "section" | "kit" | "asset";
    object: Item | Kit | Section | Asset;
  }[];
}
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; // Section
 
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

Filters

There are a number of different filters you can use to narrow down your search results. This example makes use of all availble filters to find some logo/branding assets.

Some filters can be added more than once. For some filters this will produce an OR operator, others will use AND. Details for each filter can be found below. Each distinct type of filter included will always be combined with an AND operator.

Here is an example of a search query that uses all available filters.

const result = await lingo
  .search()
  .inKit(kitId1) // in a specific kit
  .inKit(kitId2) // in a specific kit
  .matchingKeyword("Logo") // name, tag or description contains logo
  .withTag("Brand") // has tag 'Brand'
  .ofType("images") // an image type
  .createdAt({ after: "2022-01-01", before: "2023-01-01" }) // created in 2022
  .fetch();

This query will find content in either of the specific kits that match the logo keyword and contain a brand tag and are images and were created in 2022.

Kit

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.

// 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

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 will be combined with an OR operator.

// 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

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, landscape and square;

// Find square assets
const result = await lingo.search().orientation("square");

Keyword

Kit filters can be applied to global searches as well as library asset queries. you can call inKit multiple times to find results across multiple kits.

// Search for content in a specific kit
const result = await lingo.search().mathcingKeyword("branding");

Tag

Tag filters can be applied to content and any library query. Multiple type filters will will be combined with an AND operator.

This is the onyl valid filter for searching tags.

// 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

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.

// 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" });

Examples

Search For Kits

Returns a list of all kits matching "Brand".

const response = await lingo.search().kits().matchingKeyword("Brand").fetch();
const kits = response.results.map(res => res.object);

Search Kit Content

Returns items in a specific kit that match the keyword "logo".

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);

Search Assets in the Library

Returns asset obejcts from the library that contain the tag "logo".

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);

Search Tags in the Library

Returns tags that contain the text "primary"

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);