Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Portfolio: Blog Search

portfolio_blog_search.livemd

Portfolio: Blog Search

Mix.install([
  {:kino, github: "livebook-dev/kino", override: true},
  {:kino_lab, "~> 0.1.0-dev", github: "jonatanklosko/kino_lab"},
  {:vega_lite, "~> 0.1.4"},
  {:kino_vega_lite, "~> 0.1.1"},
  {:benchee, "~> 0.1"},
  {:ecto, "~> 3.7"},
  {:math, "~> 0.7.0"},
  {:faker, "~> 0.17.0"},
  {:utils, path: "#{__DIR__}/../utils"}
])

Navigation

Return Home Report An Issue

Blog Page

You’re going to add the ability to search for blogs posts to your portfolio project.

The blog page should have a text input and a search button that directs the user to http://localhost:4000/blogs?title=input_string where search_string is the text inside of the form.

http://localhost:4000/blogs?title=input_string should only display blogs whose title includes the search_string (case-insensitive).

Blog Context

The blog context should be able to search for blogs by their title. The exact interface depends on how you have implemented blogs. You might consider something like the following.

Blog.list_all(title: "My Title")

Which would return a list of blog structs that include the search string in their title (case insensitive).

[
  %Blog{id: 1, title: "My Title", content: "My Example Content"},
  %Blog{id: 3, title: "my title", content: "My Example Content"}
  %Blog{id: 3, title: "MY TITLE", content: "My Example Content"}
]

Filter out blogs that do not include the searched text in their title. Blogs that include the text should be found.

Consider including the following test cases.

  • Find blog(s) that exactly match search. ("My Title" matches "My Title")
  • Find blog(s) that partially match search. ("My Title" matches "This Includes My Title In It")
  • Find blog(s) that match search lower case insensitive. ("My Title" matches "my title")
  • Find blog(s) that match search capital case insensitive. ("My Title" matches "MY TITLE")
  • Do not find blogs that do not match search. ("My Title" does not match "Non-matching Title")

Blog Controller

The blog controller should already display all blogs on the blog page when the client visits http://localhost:4000/blogs.

There should be a form with a text input and a submit button that triggers a GET request to http://localhost:4000/blogs?title=search_string where search_string is the value of the text input.

The blog controller should filter the list of blogs by the title query parameter when the client visits http://localhost:4000/blogs?title=search_string.

Consider including the following test cases.

Commit Your Progress

Run the following in your command line from the project folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish portfolio blog search copy exercise"