af83

Searching a git repository with ElasticSearch

We are thinking about using gitlabhq for some of our internal repositories.

But then it would be cool to be able to do some full text searches on the code as well as on commit messages, tags etc..

So I wrote a quick and very dirty proof of concept (Ruby) to search a git repository through elastic search (which in its own right is extremely cool, and we should write a big article about it soon).

  • uses the grit and tire gems, please notice that grit is self hosted on github

Note: as per default Grit behaviour it gets the current master but its trivial to have it index other stuff.

Note to self: Could be useful with gitlabhq

Installation

bundle install

You should have a local elastic search running.

Usage:

# Inits with a full path to a local git repository
repo_index = GitElasticSearch.new("/Users/git/repositories/gitlabhq.git")  
# Inits elastic search index       
repo_index.init!
# Indexes the repo                 
repo_index.index!

To search the code:

Tire.search repo_index.index_name do
   query do
     string 'mysearchterm'
   end             
end

You can look at example.rb to see the full example

Todo

Well basically everything, but let's start with writing some tests and then different branches, adding the commit messages, make elastic search configurable and other fun stuff

Please remember : this is a very quick and a very dirty implementation.

Licence

BSD Copyright Ori Pekelman, AF83 2011

blog comments powered by Disqus