Skip to content

Conversation

@kisiohlova
Copy link
Owner

@kisiohlova kisiohlova commented Nov 18, 2023

Add Chewy Gem
Add Search Functionality
Change views to add search bar and search results
Add Active Storage Validations Gem to validate attachments
Add tests

User can search books by book name, author and words that may be in description.

telegram-cloud-photo-size-2-5395745316814313314-y

Search by book name:
telegram-cloud-photo-size-2-5395745316814313316-y

telegram-cloud-photo-size-2-5395745316814313315-y

Search by author:
telegram-cloud-photo-size-2-5395745316814313516-y

telegram-cloud-photo-size-2-5395745316814313517-y

Search by any word may be in description:
telegram-cloud-photo-size-2-5395745316814313518-y

telegram-cloud-photo-size-2-5395745316814313519-y

If the search doesn't find anything it redirects to main page and shows notice:
image

If the search query is empty it redirects to main page and shows notice:
image

@kisiohlova kisiohlova requested a review from loqimean November 18, 2023 11:46
@kisiohlova kisiohlova self-assigned this Nov 18, 2023
end

def search
@search_query = params[:search][:query]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а якщо сьорч поверне ніл?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def self.search(query)
search_results = BooksIndex.query(query_string: {fields: [:title, :author, :description], query: query}).to_a
book_ids = search_results.map(&:id)
Book.where(id: book_ids)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не тре цього, це не оптимально

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,6 @@
<%= simple_form_for :search, url: search_books_path, method: :get, html: { class: "flex items-center" } do |f| %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

огорни у семантичний тег search

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Initialize the Rails application.
Rails.application.initialize!

BooksIndex.import(force: true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тобі точно треба це?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


before(:each) do
BooksIndex.reset
BooksIndex.import(force: true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нашо це?)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

щоб ресетнути індекс і заповнити його актуальними даними перед тестами?)


describe ".search" do
it "returns books matching the query" do
search_results = BookSearch.search("ruby")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а лет і сабджект для кого?))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants