
Mini lesson 20 of 30 · Connect data and AI
Try the ready search
Who is this for?
People who want readers to find topics on a small website. The search project is supplied; a coding assistant can maintain its technical index.
Find a topic and open the actual article.
Purpose of this lesson
- Search the supplied content and open a real result.
- Add a new article and keep search in step with it.
- Distinguish no matches from unavailable search.
Explanation, worked example and practice
Before you start
The supplied blog/search workshop and a coding assistant to start the public folder over HTTP. You can use its ready articles; an existing personal blog is not required.
Check your starting skills
These are useful skills, not locked course requirements. If you can already do them, start this lesson; otherwise open the linked preparation. The supplied starter files mean you do not need an existing personal website.
- How to add a blog to your website
Turn an ordinary draft into a readable article page.
Estimated time: 14–26 min
Estimates for the supplied starter files with prerequisite accounts and tools ready. Setup, deployment queues and delivery/DNS waits take additional time. This simple public index suits small content sets. Large archives and multilingual ranking need a different search strategy.
Understand the idea
Have the assistant start the supplied public folder over HTTP. Search a topic from one of the ready posts, then open a result and compare it with the promised title/summary.
Only public content should appear in search. Hiding a draft’s menu link does not make its included text private.
A concrete example
A search result is useful when it leads to the substantive article, not an empty page.
Use the supplied blog/search project. Add the supplied fourth article or my draft and update its search data together, keeping drafts private and destinations safe. Handle the index code for me. Help test a distinctive phrase, an absent topic and a failed search-data load, while preserving a way to browse articles.Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
What did your first query find, and where did the result open?
Show a worked solution
Illustrative first search: “I searched smaller image and got Send a smaller image to a smaller screen. Opening the result reached the article explaining display size versus downloaded bytes.”
A matching title alone would not be enough if its destination were empty. Private drafts should remain out of the public search data even when their navigation links are hidden.
What a sound answer includes
- Names a query from the supplied public articles and the result it returned.
- Opens the result and checks that the destination contains the promised article.
How it works (optional)
Help visitors find the right article
Search should connect a question to a real page, not merely animate a search box.
The workshop extends the blog site with search.html, a JSON index and a browser script. It searches article titles and text and returns links to the existing pages.
The entire index is public and downloaded to the browser. Do not put private drafts or confidential notes into it. Search is a navigation feature here, not a permission system.
Worked example
Searching “image” returns the article about smaller image sources. Searching an unrelated word returns a clear no-results message while keeping the browse link available.
Extra implementation exercise
Can a draft stay private if you hide its page link but include its full text in search-index.json?
Show a worked solution
No. Anyone can download the JSON. Exclude private content from public search and enforce access on any genuinely private backend.
- Recognizes the index itself is public.
- Keeps private material out of public assets.

Step 1 · How to add search to your website
Use a distinctive phrase
Choose something you can recognize in the article and search.
Explanation, worked example and practice
Understand the idea
Pick a short distinctive topic phrase for the fourth supplied or new article. Ask the assistant to publish the article and update search data together.
Search does not automatically know a page exists just because it was saved. A simple word-based search can also miss typos or unfamiliar wording.
A concrete example
An exact phrase can isolate whether the new article was connected to search at all.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
Which phrase will you use, and can you find it in the intended article?
Show a worked solution
Illustrative search plan: “My fourth practice article will contain the phrase turquoise anchor check. I will ask the assistant to publish that article and add its matching search entry together, then search the same phrase.”
Finding the words in a saved draft does not establish a searchable result. First check that the intended public article contains them, then test the running search.
What a sound answer includes
- Chooses a distinctive phrase actually present in the fourth article.
- Explains that both the article and its search entry must be updated before a result is expected.
How it works (optional)
Match words and render safe results
Make the matching rule simple enough to explain and test.
The script lowercases the query, splits it into words and requires every word to occur somewhere in the article title/text. It is substring matching, not semantic search or typo correction.
It creates links with DOM methods and textContent. The index validator limits destinations to the expected blog filename format. That is useful even for a locally maintained index because it prevents accidental malformed or unsafe destinations.
The matching rule is AND across the query words, anywhere in the combined title and body. Word order does not matter: 'image browser' and 'browser image' have the same matches. It is not exact-phrase search. A word found only in the article body still counts; a misspelling does not receive automatic correction.
Worked example
“image browser” matches a page containing both words. “imagge” does not automatically become “image”. If you want typo handling later, add explicit behaviour and tests.
const matches = entries.filter(entry =>
words.every(word => (entry.title + ' ' + entry.text)
.toLowerCase().includes(word))
);Extra implementation exercise
Why might a relevant article fail a query that contains a misspelled word?
Show a worked solution
The literal substring does not occur in its text. The current search has no typo correction; either correct the query or implement a tested alternative.
- Describes the implemented literal matching.
- Does not claim a failed request or semantic understanding.

Step 2 · How to add search to your website
Check no-match and broken-search cases
Different states need different next actions.
Explanation, worked example and practice
Understand the idea
Search an absent topic and inspect its no-match state. For an unavailable-data check, use a fresh page load and ask the assistant to block or fail the search-data request locally before the first search. The app reuses data after it loads, so blocking a later request alone may not reproduce the intended failure.
No matching article and search temporarily failing should have different messages. Keep the query available to correct or retry, and try the fallback route to browse all articles. Label a deliberately blocked request as a simulation, not a real outage.
A concrete example
A request error does not prove that no relevant article exists.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
Try it yourself
What did the missing-topic and unavailable-search tests each show?
Show a worked solution
Illustrative two-state record: “A made-up topic returned No matching articles. In a fresh page with the search-data request deliberately blocked, search reported it was unavailable; Browse all articles still opened the index.”
The fresh load matters because this search keeps successfully loaded data in memory. Blocking the request after data is already loaded would not reproduce a new load failure; record that simulation boundary honestly.
What a sound answer includes
- Distinguishes an absent-topic result from a failed search-data load.
- Checks a correction/retry or browse-all route for each state and labels any simulation.
How it works (optional)
Separate no results from unavailable search
A failed index download does not prove that no article matches.
Run the supplied successful, missing-topic and blank-query cases. Then use developer tools to block search-index.json and reload before searching; the script caches a successfully loaded index in memory.
The failure message offers the article index. The visitor can still browse when search fails. Verify each result URL and test the form with the keyboard.
Worked example
“No matching articles” means a usable index was searched. “Search unavailable” means the index could not be obtained or validated. Those messages describe different evidence.
Extra implementation exercise
The JSON request returns 500. Should the page say there are no matching articles?
Show a worked solution
No. Report search as unavailable and retain the browse link. Only claim zero matches after successfully loading and checking the index.
- Distinguishes transport failure from empty matches.
- Offers a working alternative navigation route.

Step 3 · How to add search to your website
Keep a new article searchable
Repeat the reader task after the change.
Explanation, worked example and practice
Understand the idea
Complete the fourth article and matching search entry with your assistant. Reload so the running page uses current data, search the distinctive phrase and open the returned article.
Verify the loaded result reaches the actual new content. Keep no-match, failure and browse-all behavior working too.
A concrete example
The supplied turquoise-anchor example is a comparison, not a required personal writing topic.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
- public/search-index.jsonDownload this file
- public/search.jsDownload this file
- search-tests.txtDownload this file
- worksheet.htmlDownload this file
- reference/assignment-walkthrough.txtDownload this file
- reference/public/index.htmlDownload this file
- reference/public/blog/contact-anchor-check.htmlDownload this file
- reference/public/search-index.jsonDownload this file
Try it yourself
Provide the new article and observed search/failure results.
What to produce: The new article/search entry and observed found, no-match and unavailable checks.
Show a worked solution
Illustrative final record: “After the fourth article and search data were updated, turquoise anchor check returned its new page. I opened that result and found the promised phrase and explanation. An absent topic still showed no matches, and a fresh-load failure simulation still offered the article index.”
If the saved article exists but the search does not return it, the searchable route is incomplete. Ask the assistant to inspect the current search data and loaded page, rather than treating the reference’s result as your own observation.
What a sound answer includes
- Returns the new article for its distinctive phrase and opens the correct substantive page.
- Retests no-match and unavailable-search recovery after updating the index.
How it works (optional)
Your assignment: keep search in sync with a new article
Publishing a page and making it searchable are separate steps in this small site.
Add a fourth article and a corresponding index entry. Choose a distinctive topic phrase and confirm it finds the new page. Keep the destination within the allowed blog filename pattern.
Remove that entry temporarily and observe that the page still exists but no longer appears in search. This exposes why a larger site may generate its index automatically from the article source.
Your fourth article can use any genuine topic and distinctive phrase. contact-anchor-check.html and “turquoise anchor check” are only the supplied comparison case, not required submission content. What matters is that your own real filename and searchable text agree in the article and loaded index.
Worked example
A static generator can produce pages and the index from one source. In this hand-maintained version, the test record is your protection against forgetting one side.
The complete reference walkthrough is available in reference/assignment-walkthrough.txt. Compare its steps with your own result; fill the test record from observations in your own project.
Extra implementation exercise
Publish the fourth sample article and prove search finds its distinctive phrase.
Show a worked solution
The reference fourth article uses the distinctive phrase 'turquoise anchor check'. The corresponding search-index.json entry has its real blog filename plus searchable summary/body text; the complete reference files show both sides.
Reload to clear the in-memory cached index, search that phrase and open the returned article. Inspect the loaded JSON too: merely placing the phrase in the HTML without updating the index will not make it searchable.
Retest a missing topic and a blocked index download in a fresh tab/reload. Missing matches and unavailable search must produce different messages, while Browse all articles still works.
- Result opens the intended real article.
- New content is indexed without breaking failure and empty-query handling.
Was this lesson useful?
Leave a like, or share it with someone who could use it.