Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up search errors.

  • Loading branch information...
commit 34e7813de3e7c4df573357e092c3fd5fd737304c 1 parent 55da58f
@zk authored
View
27 app/controllers/main_controller.rb
@@ -240,6 +240,7 @@ def function_short_link
end
def search_autocomplete
+
q = params[:term]
q = q.gsub("-", "")
if not q
@@ -253,8 +254,9 @@ def search_autocomplete
core_current_version = (Library.find_by_name_and_current("Clojure Core", true).version rescue nil || "1.2.0")
contrib_current_version = (Library.find_by_name_and_current("Clojure Contrib", true).version rescue nil || "1.2.0")
+ # @version (\"#{core_current_version}\" | \"#{contrib_current_version}\")
- @functions = Function.search("@name #{q} @library (\"Clojure Core\" | \"Clojure Contrib\") @version (\"#{core_current_version}\" | \"#{contrib_current_version}\")", :field_weights => {
+ @functions = Function.search("@name #{q} @library (\"Clojure Core\" | \"Clojure Contrib\")", :field_weights => {
:name => 100,
:library => 1,
:ns => 1,
@@ -264,7 +266,12 @@ def search_autocomplete
@functions.delete(nil)
if @functions != nil and @functions.size > 0
- # sort clojure core & contrib higher than other libs
+
+ @functions.sort!{|a,b|
+ Levenshtein.distance(q, a.name) <=> Levenshtein.distance(q, b.name)
+ }
+
+ # sort clojure core & contrib higher than other libs
@functions.sort!{|a,b|
aval = 0
bval = 0
@@ -281,19 +288,23 @@ def search_autocomplete
bval = 1
end
- bval <=> aval
+ aval <=> bval
}
- @functions.sort!{|a,b|
- Levenshtein.distance(q, a.name) <=> Levenshtein.distance(q, b.name)
- }
+
end
-
+
+ @exact_matches = Function.find_all_by_name(params[:term])
+
+ if @exact_matches
+ @functions = (@exact_matches + @functions).uniq
+ end
+
if @functions.size > 10
@functions = @functions[0, 10]
end
- render :json => @functions.map{|f| {:href => f.href, :ns => f.ns, :name => f.name, :examples => f.examples.size, :shortdoc => f.shortdoc }}
+ render :json => @functions.map{|f| {:href => f.href, :ns => f.namespace.name, :name => f.name, :examples => f.examples.size, :shortdoc => f.shortdoc }}
end
def examples_style_guide
View
2  app/helpers/application_helper.rb
@@ -10,7 +10,7 @@ def font_size_for_weight(weight)
end
def group_into_ns(functions)
- functions.group_by do |f|
+ functions.sort{|a,b| a.name <=> b.name}.group_by do |f|
name = f[:name]
first_char = name[0,1].downcase
if first_char == "*"
View
11 app/models/function.rb
@@ -22,14 +22,17 @@ class Function < ActiveRecord::Base
#:nocov:
define_index do
# fields
- indexes "REPLACE(name, '-', '')", :as => :name
+ #indexes "REPLACE(name, '-', '')", :as => :name
set_property :enable_star => true
set_property :min_prefix_len => 1
- #indexes name
+ indexes name
indexes doc
- indexes library
- indexes ns
+ indexes '(select libraries.name from libraries where libraries.id = (select library_id from namespaces where namespaces.id = functions.namespace_id))', :as => :library
+ indexes '(select namespaces.name from namespaces where namespaces.id = namespace_id)'
+# indexes namespace
+# indexes functions(:namespace, :name), :as => :ns
indexes version
+
end
#:nocov:
View
10 app/models/namespace.rb
@@ -2,6 +2,16 @@ class Namespace < ActiveRecord::Base
belongs_to :library
has_many :functions
+ #:nocov:
+ define_index do
+ # fields
+ indexes name
+ indexes libraries.name, :as => :library
+
+ has library_id
+ end
+ #:nocov:
+
def self.versions_of(ns)
Namespace.find(:all, :include => :library, :conditions => {:name => ns.name, :libraries => {:name => ns.library.name}})
end
View
2  app/views/layouts/_header.html.erb
@@ -46,7 +46,7 @@
</div>
<div class="grid_8">
- <% if params[:lib] %>
+ <% if @library %>
<h1><a href="/">ClojureDocs</a><span class="version">(alpha)</span> :: <a class="lib_name" href="/<%= @library.url_friendly_name %>"><%= @library.name %></a></h1>
<% else %>
<h1><a href="/">ClojureDocs</a><span class="version">(alpha)</span></h1>
View
2  app/views/layouts/main.html.erb
@@ -60,7 +60,7 @@
var acUrl = "<%= ROOT_URL %>/ac_search";
<% if params[:lib] %>
- acUrl = "<%= ROOT_URL %>/ac_search/<%= CGI::escape(params[:lib]) %>";
+ //acUrl = "<%= ROOT_URL %>/ac_search/<%= CGI::escape(params[:lib]) %>";
<% end %>
$('#main_search').keydown(function(e) {
View
4 app/views/main/search.html.erb
@@ -53,9 +53,9 @@ $(document).ready(function() {
<% @functions.each do |f| %>
<div class="search_result">
<h4>
- <a href="<%= f.href %>"><%= f.excerpts.name %></a>
+ <%= link_to f.name, f.link_opts %>
<span class="ns">
- <%= link_to f.excerpts.ns, :controller => 'main', :action => 'ns', :lib => f.library, :ns => f.ns %>
+ <%= link_to f.namespace.name, :controller => 'main', :action => 'ns', :lib => f.library.url_friendly_name, :ns => f.namespace.name %>
</span>
</h4>
<p class="doc"><%= f.excerpts.doc %></p>
View
43 config/development.sphinx.conf
@@ -17,15 +17,15 @@ source function_core_0
sql_host = 127.0.0.1
sql_user = root
sql_pass =
- sql_db = clojuredocs
+ sql_db = clojuredocs_development
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = '+0:00'
- sql_query = SELECT SQL_NO_CACHE `functions`.`id` * 2 + 0 AS `id` , REPLACE(name, '-', '') AS `name`, `functions`.`doc` AS `doc`, `functions`.`library` AS `library`, `functions`.`ns` AS `ns`, `functions`.`id` AS `sphinx_internal_id`, 869823595 AS `class_crc`, 0 AS `sphinx_deleted` FROM `functions` WHERE `functions`.`id` >= $start AND `functions`.`id` <= $end GROUP BY `functions`.`id` ORDER BY NULL
+ sql_query = SELECT SQL_NO_CACHE `functions`.`id` * 3 + 0 AS `id` , `functions`.`name` AS `name`, `functions`.`doc` AS `doc`, (select libraries.name from libraries where libraries.id = (select library_id from namespaces where namespaces.id = functions.namespace_id)) AS `library`, (select namespaces.name from namespaces where namespaces.id = namespace_id) AS `(select namespaces.name from namespaces where namespaces.id = namespace_id)`, `functions`.`version` AS `version`, `functions`.`id` AS `sphinx_internal_id`, 869823595 AS `class_crc`, 0 AS `sphinx_deleted` FROM `functions` WHERE `functions`.`id` >= $start AND `functions`.`id` <= $end GROUP BY `functions`.`id` ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `functions`
sql_attr_uint = sphinx_internal_id
sql_attr_uint = class_crc
sql_attr_uint = sphinx_deleted
- sql_query_info = SELECT * FROM `functions` WHERE `id` = (($id - 0) / 2)
+ sql_query_info = SELECT * FROM `functions` WHERE `id` = (($id - 0) / 3)
}
index function_core
@@ -49,15 +49,15 @@ source library_core_0
sql_host = 127.0.0.1
sql_user = root
sql_pass =
- sql_db = clojuredocs
+ sql_db = clojuredocs_development
sql_query_pre = SET NAMES utf8
sql_query_pre = SET TIME_ZONE = '+0:00'
- sql_query = SELECT SQL_NO_CACHE `libraries`.`id` * 2 + 1 AS `id` , `libraries`.`name` AS `name`, `libraries`.`description` AS `description`, `libraries`.`id` AS `sphinx_internal_id`, 1849532704 AS `class_crc`, 0 AS `sphinx_deleted` FROM `libraries` WHERE `libraries`.`id` >= $start AND `libraries`.`id` <= $end GROUP BY `libraries`.`id` ORDER BY NULL
+ sql_query = SELECT SQL_NO_CACHE `libraries`.`id` * 3 + 1 AS `id` , `libraries`.`name` AS `name`, `libraries`.`description` AS `description`, `libraries`.`id` AS `sphinx_internal_id`, 1849532704 AS `class_crc`, 0 AS `sphinx_deleted` FROM `libraries` WHERE `libraries`.`id` >= $start AND `libraries`.`id` <= $end GROUP BY `libraries`.`id` ORDER BY NULL
sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `libraries`
sql_attr_uint = sphinx_internal_id
sql_attr_uint = class_crc
sql_attr_uint = sphinx_deleted
- sql_query_info = SELECT * FROM `libraries` WHERE `id` = (($id - 1) / 2)
+ sql_query_info = SELECT * FROM `libraries` WHERE `id` = (($id - 1) / 3)
}
index library_core
@@ -72,3 +72,34 @@ index library
type = distributed
local = library_core
}
+
+source namespace_core_0
+{
+ type = mysql
+ sql_host = 127.0.0.1
+ sql_user = root
+ sql_pass =
+ sql_db = clojuredocs_development
+ sql_query_pre = SET NAMES utf8
+ sql_query_pre = SET TIME_ZONE = '+0:00'
+ sql_query = SELECT SQL_NO_CACHE `namespaces`.`id` * 3 + 2 AS `id` , `namespaces`.`name` AS `name`, `namespaces`.`name` AS `library`, `namespaces`.`id` AS `sphinx_internal_id`, 2970675701 AS `class_crc`, 0 AS `sphinx_deleted`, `namespaces`.`library_id` AS `library_id` FROM `namespaces` WHERE `namespaces`.`id` >= $start AND `namespaces`.`id` <= $end GROUP BY `namespaces`.`id` ORDER BY NULL
+ sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `namespaces`
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = class_crc
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = library_id
+ sql_query_info = SELECT * FROM `namespaces` WHERE `id` = (($id - 2) / 3)
+}
+
+index namespace_core
+{
+ source = namespace_core_0
+ path = /Users/zkim/napplelabs/clojuredocs/db/sphinx/development/namespace_core
+ charset_type = utf-8
+}
+
+index namespace
+{
+ type = distributed
+ local = namespace_core
+}
View
2  config/environments/development.rb
@@ -11,7 +11,7 @@
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs = true
-config.action_controller.perform_caching = true
+config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
Please sign in to comment.
Something went wrong with that request. Please try again.