Skip to content

Commit

Permalink
Support full text search
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Dec 22, 2016
1 parent 624dde6 commit 0774606
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/controllers/documents_controller.rb
Expand Up @@ -4,7 +4,11 @@ class DocumentsController < ApplicationController
# GET /documents
# GET /documents.json
def index
@documents = Document.all
@query = params[:query]
searcher = DocumentsSearcher.new
@result_set = searcher.search.
query(@query).
result_set
end

# GET /documents/1
Expand Down
10 changes: 9 additions & 1 deletion app/views/documents/index.html.erb
Expand Up @@ -2,6 +2,13 @@

<h1>Documents</h1>

<p><%= @result_set.n_hits %> records</p>

<%= form_tag(documents_path, method: "get") do %>
<%= search_field_tag "query", @query %>
<%= submit_tag "Search" %>
<% end %>

<table>
<thead>
<tr>
Expand All @@ -12,7 +19,8 @@
</thead>

<tbody>
<% @documents.each do |document| %>
<% @result_set.records.each do |record| %>
<% document = record.source %>
<tr>
<td><%= document.title %></td>
<td><%= document.content %></td>
Expand Down

0 comments on commit 0774606

Please sign in to comment.