Permalink
Browse files

improve search results, add docversion index

  • Loading branch information...
1 parent 9b23237 commit d9a1b88c235f3875199d7079ab30eaf46b5e5e9a @schacon schacon committed Apr 6, 2012
@@ -2,7 +2,6 @@ class DocController < ApplicationController
layout "layout"
def index
- @docs = DocFile.all
end
def ref
@@ -6,28 +6,26 @@ def index
end
def search
- query = { 'query' => params[:search] }
-
query_options = {
- 'bool' => {
- 'must' => [
- # Search for the query across all fields
- { 'field' => { '_all' => query } },
- ]
+ 'prefix' => {
+ 'name' => params['search'].downcase
}
}
+ p query_options
+
resp = BONSAI.search( 'doc',
'query' => query_options,
'size' => 10)
+ p resp
ref_hits = []
resp['hits']['hits'].each do |hit|
name = hit["_source"]["name"]
ref_hits << {
:name => name,
- :url => "/doc/ref/#{name}"
+ :url => "/ref/#{name}"
}
end
View
@@ -11,6 +11,17 @@ def self.for_version(doc_name, version_name)
for_doc(doc_name).joins(:version).where(['versions.name=?', version_name]).first
end
+ def index
+ file = self.doc_file
+ doc = self.doc
+ data = {
+ 'name' => file.name,
+ 'blob_sha' => doc.blob_sha,
+ 'text' => doc.plain,
+ }
+ BONSAI.add 'doc', file.name, data
+ end
+
private
def self.for_doc(doc_name)
View
@@ -38,6 +38,7 @@ class PropertyMapping < Struct.new(:name, :type)
class Index
def initialize(name, server)
@name = name
+ @server = server
@conn = ElasticSearch.get_connection(server)
end
@@ -84,8 +85,8 @@ def clear
# create_options - a hash of index creation options
#
# Returns a hash, the parsed response body from elasticsearch.
- def create(server, create_options={})
- self.class.create @name, server, create_options
+ def create(create_options={})
+ self.class.create @name, @server, create_options
end
# Force a refresh of this index
View
@@ -1,17 +1,8 @@
task :search_index => :environment do
# BONSAI.clear
- Version.all.each do |version|
- puts version.name
- version.doc_versions.each do |docv|
- file = docv.doc_file
- doc = docv.doc
- data = {
- 'name' => file.name,
- 'description' => file.description,
- 'blob_sha' => doc.blob_sha,
- 'text' => doc.plain,
- }
- BONSAI.add 'doc', file.name, data
- end
+ version = Version.all.last
+ puts version.name
+ version.doc_versions.each do |docv|
+ p docv.index
end
end

0 comments on commit d9a1b88

Please sign in to comment.