Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor examples, separating indexing from search.

  • Loading branch information...
commit 6812a7d4417d06598056e9842b375f3b00ecaa4b 1 parent a69610e
Ori Pekelman OriPekelman authored
19 example.rb
View
@@ -1,19 +0,0 @@
-require './gitelasticsearch.rb'
-require 'pygments'
-DEBUG = true
-repo_index = GitElasticSearch.new("/Users/git/repositories/gitlabhq.git")
-
-repo_index.init!
-repo_index.index!
-
-s = Tire.search repo_index.index_name do
- query do
- string 'admin'
- end
-end
-
-s.results.each do |document|
- puts "<h1>#{document.path}#{document.name}</h1>"
- puts Pygments.highlight(document.code)
-end
-puts "<style>#{Pygments.css}</style>"
8 examples/example_index.rb
View
@@ -0,0 +1,8 @@
+require './gitelasticsearch.rb'
+
+DEBUG = true
+repo_index = GitElasticSearch.new("/Users/git/repositories/gitlabhq.git")
+
+repo_index.init!
+repo_index.index!
+
39 examples/example_search.rb
View
@@ -0,0 +1,39 @@
+require './gitelasticsearch.rb'
+DEBUG = true
+
+repo_index = GitElasticSearch.new("/Users/git/repositories/gitlabhq.git")
+repo_index.refresh
+
+s = Tire.search repo_index.index_name do
+ query do
+ boolean do
+ should {string 'code:*j*'}
+ should {terms :branch, ['pratica'] }
+ end
+ end
+ facet 'language' do
+ terms :language
+ end
+ facet 'timeline' do
+ date :date, :interval => 'month'
+ end
+ highlight :code=> { :number_of_fragments => 0 }, :options => { :tag => "<span class=\"highlight\">" }
+end
+puts "<h1>Facets:</h1><pre>"
+s.results.facets['language']['terms'].each do |f|
+ puts "#{f['term'].ljust(10)} #{f['count']}"
+end
+ s.results.facets['timeline']['terms'].each do |f|
+ puts "#{f['term'].ljust(10)} #{f['count']}"
+end
+puts "</pre><hr>"
+
+s.results.each do |document|
+ puts "<h1>#{document.path}/#{document.name} @ #{document.branch} </h1>"
+ if document.highlight.nil? then
+ puts "<strong>ERROR ERROR ERROR</strong>"
+ else
+ puts document.highlight.code.join("")
+ end
+end
+puts "<style>#{Pygments.css}</style>"
Please sign in to comment.
Something went wrong with that request. Please try again.