Guide 2.15: Developer Guide

Searching the Question Bank

Sometimes you want to find questions that contain a specific word or phrase, like "photosynthesis" or "calculus". While SdashAPI is heavily optimized for filtering by metadata (subject, year, exam type), it does not currently expose a direct full-text search parameter via the V1 endpoint. Here is the recommended workaround.

Client-Side Filtering (The Workaround)

2.15.1

To simulate a search experience, you should request the maximum allowable batch of questions (50) for a specific subject, and then use JavaScript's native Array .filter() method to search through the question strings on the client side.

const searchTerm = "photosynthesis".toLowerCase();

// Assume 'apiData' is the array of 50 biology questions returned by SdashAPI
const searchResults = apiData.filter(item => {
  return item.question.toLowerCase().includes(searchTerm);
});

console.log(`Found ${searchResults.length} matching questions.`);

Using the V4 Intelligence API

2.15.2

If you absolutely need to build a search engine, consider upgrading to the V4 endpoint. While it doesn't offer a traditional keyword search, V4's /similar endpoint allows you to pass a specific Question ID and retrieve conceptually similar questions based on AI vector embeddings, which is often much more powerful than simple keyword matching.

Caching for Search

2.15.3

If you are building an application where search is the primary feature, we highly recommend setting up a cron job on your backend server. You can write a script that fetches batches of questions from SdashAPI overnight, saves them into your own local database (like PostgreSQL or MongoDB), and utilizes native database indexing to provide lightning-fast full-text search to your users.

What happens when searches fail?

Next, we will look at how to handle empty result sets gracefully.

Next Guide: Handling Empty Results →
Avatar

How can we help?

We reply immediately

Hello! 👋 How can we help you today?