Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
it works! searching 40k source files over 30 git projects in 0.005s
(210M total / processing 65 docs/sec) freaking sweet.
- Loading branch information
Showing
4 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class GitFile | ||
include DataMapper::Resource | ||
property :id, Integer, :serial => true | ||
property :repo, String | ||
property :path, String | ||
property :sha_value, String | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#! /usr/bin/env ruby | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'riddle' | ||
require 'dm-core' | ||
require 'dm-aggregates' | ||
require 'git_file' | ||
require 'pp' | ||
|
||
# sinatra server for searching your codes | ||
DataMapper.setup(:default, 'mysql://localhost/git_file_index') | ||
$client = Riddle::Client.new | ||
|
||
def show_doc(id) | ||
f = GitFile.get(id.to_i) | ||
[f.repo, f.path].join(', ') | ||
end | ||
|
||
template :layout do | ||
" | ||
<html> | ||
<form method=\"POST\" action=\"/search\"> | ||
<input name=\"search\" type=\"text\"> | ||
<input type=\"submit\"> | ||
</form> | ||
<%= yield %> | ||
</html> | ||
" | ||
end | ||
|
||
template :index do | ||
'<em>type a search term to begin</em>' | ||
end | ||
|
||
template :results do | ||
' | ||
<h1><%= @results[:total] %> Results</h1> | ||
<% @results[:matches].each do |match| %> | ||
<li><%= show_doc(match[:doc]) %> | ||
<% end %> | ||
<hr/> | ||
<h3>Matches</h3> | ||
<% @results[:words].each do |word, stats| %> | ||
<li><%= word %> (docs:<%= stats[:docs] %>, hits:<%= stats[:hits] %>) | ||
<% end %> | ||
<hr/> | ||
Results took : <%= @results[:time] %>s | ||
' | ||
end | ||
|
||
get '/' do | ||
erb :index | ||
end | ||
|
||
post '/search' do | ||
|
||
@results = $client.query params[:search] | ||
erb :results | ||
end | ||
|
||
#collected 40569 docs, 216.5 MB | ||
#sorted 15.8 Mhits, 100.0% done | ||
#total 40569 docs, 216528702 bytes | ||
#total 617.686 sec, 350548.44 bytes/sec, 65.68 docs/sec |