This application is designed to record and analyze search queries entered by users in real-time. It includes a simple backend built with Ruby on Rails and a Vanilla JS frontend.
Loom video demonstrating functionality
- Loom Video
- Link to live app in Heroku here
Make sure you have the following installed on your machine:
git clone
https://github.com/your-username/search-analytics-app.git
cd search-analytics-app
bundle install
bundle exec rspec
![Screenshot 2024-01-10 at 19 47 44](https://private-user-images.githubusercontent.com/50773868/295643680-4a80a079-302e-4232-accd-a335a8a4b0ff.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTI3ODkwOTYsIm5iZiI6MTcxMjc4ODc5NiwicGF0aCI6Ii81MDc3Mzg2OC8yOTU2NDM2ODAtNGE4MGEwNzktMzAyZS00MjMyLWFjY2QtYTMzNWE4YTRiMGZmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA0MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNDEwVDIyMzk1NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc1MGNlODI2NGJhYzA3MjBjMmFkY2MxZmFjODgyNmYxYjc5OWQ1MmE4ZjE1OTVlNjc1NjI3OWU5NTc1ZTI4ZTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.cBBdIUfoBrQheDtji_4tGBHZ2P-RB-OFfqXP9X-w2Zk)
rails db:create
rails db:migrate
rails server rerun rails server to restart on detecting changes
Access the application in your web browser at http://localhost:3000.
The app provides an API endpoint for creating searches. Send a POST request to /searches with the search query as the query parameter. Example using cURL:
curl -X POST -d "query=what is a good car" http://localhost:3000/searches
To view search analytics, you can access the /searches/all_searches endpoint. The app provides a JSON response containing the search results. Additionally, the frontend can be customized to display these results in a user-friendly manner.
Consider implementing caching to store frequently queried searches. This can significantly reduce the load on the database and improve response times.
Add indexes to the database columns used in search queries to speed up retrieval. In the migration file db/migrate/YYYYMMDDHHMMSS_create_searches.rb, add indexes as follows:
class CreateSearches < ActiveRecord::Migration[7.0]
def change
create_table :searches do |t|
t.string :query
t.string :ip_address
t.timestamps
end
add_index :searches, :query
add_index :searches, :ip_address
end
end
Move search creation and analytics processing to a background job queue. This can be achieved using tools like Sidekiq or Resque. Background processing ensures that your application remains responsive even during heavy traffic.
Implement robust error handling to gracefully handle unexpected issues. Log errors for analysis and debugging. Use Rails' built-in exception handling and logging mechanisms.
Integrate monitoring tools to keep track of your application's health. Services like New Relic or Datadog can help you monitor performance, detect anomalies, and set up alerts for critical issues.
Determining the accurate IP address of a user can be challenging due to factors like proxy servers and network configurations. The app uses the request.remote_ip method, which may not always reflect the user's actual IP address. Consider additional measures, such as using a service like ipinfo.io to enhance IP address accuracy. Also getting the searches as per ip address may pose a challenge.