// Basic searchconst{ results, query, totalRecords, elapsedTime }=await search.search.search({
query:'laptop',
limit:20,
offset:0,});// Search with entity type filteringconst{ results }=await search.search.search({
query:'john',
entityTypes:['users','contacts'],
limit:10,});// Search with include/exclude termsconst{ results }=await search.search.search({
query:'programming',
include:['javascript','typescript'],
exclude:['java'],});// Get search suggestions (autocomplete)const suggestions =await search.search.suggest('lap',5);
suggestions.forEach((s)=>console.log(s.title));// Get available entity typesconst entityTypes =await search.search.entityTypes();
entityTypes.forEach((type)=>{console.log(type.name, type.count);});
history - Search History
// Get recent searchesconst recentSearches =await search.history.recent(20);
recentSearches.forEach((q)=>{console.log(q.query, q.totalRecords);});// Get specific query detailsconst queryDetails =await search.history.get('query-id');// Clear all search historyawait search.history.clear();// Delete specific query from historyawait search.history.delete('query-id');
favorites - Favorites Management
// List favorites with paginationconst{ data: favorites, meta }=await search.favorites.list({
page:1,
perPage:20,});
favorites.forEach((fav)=>{console.log(fav.entityAlias, fav.entityType);});// Get a specific favoriteconst favorite =await search.favorites.get('favorite-id');// Add to favoritesconst newFavorite =await search.favorites.add({
entityUniqueId:'product-123',
entityType:'Product',
entityAlias:'MacBook Pro',
entityUrl:'/products/product-123',
entityAvatarUrl:'https://example.com/image.jpg',});// Remove from favoritesawait search.favorites.remove('favorite-id');// Check if entity is favoritedconst isFavorited =await search.favorites.isFavorite('product-123');if(isFavorited){console.log('This item is in your favorites');}