Claude Skills Guide

Claude Code Typesense Full Text Search Setup Tutorial

Full-text search is a critical feature for modern applications, enabling users to find relevant content quickly and accurately. Typesense, an open-source search engine, provides lightning-fast, typo-tolerant search results. When combined with Claude Code’s AI capabilities, you can create intelligent search experiences that understand context and intent. This comprehensive tutorial walks you through setting up Typesense with Claude Code to build powerful search functionality.

Prerequisites and Initial Setup

Before diving into the implementation, ensure you have the necessary tools installed. You’ll need Node.js (version 18 or higher), Docker for running Typesense, and Claude Code configured on your system. This tutorial assumes you have basic familiarity with JavaScript/TypeScript and command-line operations.

Start by creating a new project directory and initializing it with npm. Open your terminal and execute the following commands:

mkdir typesense-search-demo && cd typesense-search-demo
npm init -y
npm install typesense @types/node typescript

Next, you’ll need to set up a Docker container for Typesense. The official Typesense Docker image provides an easy way to get started:

docker run -d -p 8108:8108 \
  --name typesense \
  -v /tmp/typesense-data:/data \
  typesense/typesense:0.25.2 \
  --data-dir /data \
  --api-key=xyz \
  --enable-cors

This command starts Typesense on port 8108 with CORS enabled for development purposes. Remember to replace the API key with a secure value in production environments.

Configuring Claude Code for Typesense Integration

Claude Code excels at generating boilerplate code and explaining complex APIs. When working with Typesense, you can use Claude Code’s skills to accelerate development. Create a Claude Code configuration file to establish the connection:

importTypesensefrom'typesense';

constclient=newTypesense.Client({
  nodes:[{
    host:'localhost',
    port:8108,
    protocol:'http'
  }],
  apiKey:'xyz',
  connectionTimeoutSeconds:2
});

exportdefaultclient;

This configuration establishes a connection to your local Typesense instance. Claude Code can help you expand this setup with additional features like retry logic, load balancing, and error handling.

Creating and Managing Search Collections

Typesense organizes data into collections with predefined schemas. Claude Code can generate the schema definitions and help you understand the various field types available. Here’s how to create a products collection for an e-commerce search:

async functioncreateProductsCollection(){
  constschema={
    name:'products',
    fields:[
      {name:'name',type:'string'},
      {name:'description',type:'string'},
      {name:'category',type:'string',facet:true},
      {name:'price',type:'float',facet:true},
      {name:'brand',type:'string',facet:true},
      {name:'tags',type:'string[]'},
      {name:'rating',type:'int32'}
    ],
    default_sorting_field:'rating'
  };

  try{
    awaitclient.collections().create(schema);
    console.log('Products collection created successfully');
  }catch(error){
    console.error('Collection creation failed:',error);
  }
}

The schema defines multiple searchable fields with faceting enabled for category, price, and brand—essential for building filterable search interfaces. The default sorting field ensures relevant results appear first.

Indexing Documents and Performing Searches

With the collection created, you can now index documents. Claude Code can help you construct efficient indexing pipelines that handle large datasets:

constproducts=[
  {
    name:'Wireless Bluetooth Headphones',
    description:'Premium noise-cancelling headphones with 30-hour battery life',
    category:'Electronics',
    price:299.99,
    brand:'AudioMax',
    tags:['wireless','bluetooth','noise-cancelling'],
    rating:4
  },
  {
    name:'Organic Green Tea',
    description:'Premium organic green tea leaves from Japan',
    category:'Beverages',
    price:24.99,
    brand:'TeaMasters',
    tags:['organic','green-tea','healthy'],
    rating:5
  }
];

async functionindexDocuments(){
  constreturnDocuments=awaitclient
    .collections('products')
    .documents()
    .import(products);

  console.log(`Indexed ${returnDocuments.length} documents`);
}

Now for the exciting part—performing searches. Typesense supports various search parameters for refined results:

async functionsearchProducts(query:string){
  constsearchParameters={
    q:query,
    query_by:'name,description,tags',
    query_by_weights:'3,2,1',
    filter_by:'category:=Electronics',
    sort_by:'price:desc',
    per_page:10,
    page:1
  };

  constresults=awaitclient
    .collections('products')
    .documents()
    .search(searchParameters);

  returnresults;
}

This search configuration prioritizes name matches over description matches, filters for electronics, sorts by price in descending order, and returns ten results per page.

Building a CLI Search Tool with Claude Code

Claude Code shines when building command-line interfaces. Let’s create a practical search tool that uses Typesense:

#!/usr/bin/envnode
importreadlinefrom'readline';

constrl=readline.createInterface({
  input:process.stdin,
  output:process.stdout
});

functionpromptSearch(){
  rl.question('Enter search query (or "quit" to exit): ',async(query)=>{
    if(query.toLowerCase()==='quit'){
      rl.close();
      return;
    }

    constresults=awaitsearchProducts(query);
    
    if(results.hits){
      console.log('\nSearch Results:\n');
      results.hits.forEach((hit:any,i)=>{
        console.log(`${i+1}. ${hit.document.name}`);
        console.log(`   Price: $${hit.document.price}`);
        console.log(`   Category: ${hit.document.category}`);
        console.log('');
      });
    }

    promptSearch();
  });
}

console.log('Welcome to Products Search!');
promptSearch();

This interactive CLI tool allows users to search your Typesense index directly from the terminal, demonstrating how Claude Code can help you build practical search utilities.

Advanced Search Features

Typesense offers advanced features that Claude Code can help you implement. Faceted search enables users to filter results by multiple categories simultaneously:

async functionfacetedSearch(){
  constresults=awaitclient
    .collections('products')
    .documents()
    .search({
      q:'wireless',
      query_by:'name,description,tags',
      facet_by:'category,brand',
      max_facet_values:5
    });

  console.log('Available Filters:');
  console.log(results.facet_counts);
}

Typo tolerance is built-in, so searches for “headphons” will still find “headphones.” You can adjust the typo tolerance threshold based on your needs:

constsearchWithTypoTolerance={
  q:'bluetooh',
  query_by:'name',
  typo_tokens_threshold:1
};

Conclusion

Integrating Claude Code with Typesense opens up possibilities for building sophisticated search experiences. This tutorial covered the essential setup, configuration, indexing, and search operations. With these foundations, you can expand into more advanced features like synonym handling, geo-search, and vector search. Claude Code’s ability to understand and generate code makes implementing these features more accessible, allowing you to focus on creating exceptional user experiences rather than wrestling with implementation details.

The combination of Claude Code’s AI capabilities and Typesense’s performance makes for a powerful search solution suitable for applications of any scale. As you continue exploring, you’ll discover even more ways to enhance your search functionality with features like dynamic ranking, personalization, and analytics.

Built by theluckystrike — More at zovo.one