Skip to content
Hacker News Search
JavaScript Ruby CSS HTML Shell
Find file
Latest commit 35456ac @redox redox Merge pull request #75 from petasittek/master
Add Social Meter, a Chrome extension
Failed to load latest commit information.
app Add Social Meter, a Chrome extension
bin Add bluepill binstub
config Upgrade the underlying rails dependency + improved 404.
db Tag items that are on the front page every minute
lib rails_apps_composer: initial commit
public Down for maintenance page
test Play with highstock
vendor/assets Officially upgrade to the latest JS API client. Fix #46
.gitignore minor corrections
Capfile Realtime indexing
Gemfile Upgrade the underlying rails dependency + improved 404.
Gemfile.lock Upgrade the underlying rails dependency + improved 404.
Guardfile Prepare angular.js-based new front
LICENSE.txt MIT License Improved README
Rakefile rails_apps_composer: initial commit rails_apps_composer: initial commit New thumbnails
wkhtmltoimage-mac Custom code for thumbnails extraction + updated ranking

HN Search powered by Algolia

This is the Rails 4 application providing HN Search. It's mainly based on angular.js, algoliasearch-rails and uses wkhtmltoimage to crawl+render thumbnails.


We love pull-requests :)


# clone the repository
git clone
cd hn-search

# install dependencies
bundle install

# setup credentials
cp config/database.example.yml config/database.yml # feel free to edit, default configuration is OK for search-only
cp config/application.example.yml config/application.yml # feel free to edit, default configuration is OK for search-only

# setup your (sqlite3) database
rake db:migrate

# start contributing enjoying Guard (watchers, livereload, notifications, ...)

# done!
open http://localhost:3000


If you want to contribute to the UI, the only directory you need to look at is app/assets. This directory contains all the JS, HTML & CSS code.

Indexing Configuration

The indexing is configured using the following algoliasearch block:

class Item < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch per_environment: true do
    # the list of attributes sent to Algolia's API
    attribute :created_at, :title, :url, :author, :points, :story_text, :comment_text, :author, :num_comments, :story_id, :story_title
    attribute :created_at_i do

    # `title` is more important than `{story,comment}_text`, `{story,comment}_text` more than `url`, `url` more than `author`
    # btw, do not take into account position in most fields to avoid first word match boost
    attributesToIndex ['unordered(title)', 'unordered(story_text)', 'unordered(comment_text)', 'unordered(url)', 'author', 'created_at_i']

    # list of attributes to highlight
    attributesToHighlight ['title', 'story_text', 'comment_text', 'url', 'story_url', 'author', 'story_title']

    # tags used for filtering
    tags do
      [item_type, "author_#{author}", "story_#{story_id}"]

    # use associated number of HN points to sort results (last sort criteria)
    customRanking ['desc(points)', 'desc(num_comments)']

    # controls the way results are sorted sorting on the following 4 criteria (one after another)
    # I removed the 'exact' match critera (improve 1-words query relevance, doesn't fit HNSearch needs)
    ranking ['typo', 'proximity', 'attribute', 'custom']

    # google+, $1.5M raises, C#: we love you
    separatorsToIndex '+#$'

  def story_text
    item_type_cd != Item.comment ? text : nil

  def story_title
    comment? && story ? story.title : nil

  def story_url
    comment? && story ? story.url : nil

  def comment_text
    comment? ? text : nil

  def comment?
    item_type_cd == Item.comment


Something went wrong with that request. Please try again.