Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[#22] SQL text match on var name first, then try sphinx if no results.

  • Loading branch information...
commit 3a5c8e129ed40adbd36a7702dd257065c912b6ba 1 parent 3821ca6
@zk authored
View
40 app/controllers/main_controller.rb
@@ -86,13 +86,9 @@ def libs
def search
q = params[:q] || ""
+ # for display on page -- 'You search for x'
@orig_query = q
- # if not q.match("@library")
- # q += " @library (\"Clojure Core\" | \"Clojure Contrib\")"
- # end
-
- #q = "*" + q + "*"
res = []
for i in (0..q.size)
@@ -104,12 +100,32 @@ def search
qm = res.clone
qm = qm.fill("?")
- sql = "select name from functions where name RLIKE " + qm.join(" or name RLIKE ")
- @functions = Function.find_by_sql([sql] + res)
- puts "found: #{@functions.length}"
- puts "f: "
- puts @functions.map {|f| f.name }
-
+ sql = "select * from functions where name RLIKE " + qm.join(" or name RLIKE ") + " LIMIT 100"
+
+ begin
+
+ @functions = Function.find_by_sql([sql] + res)
+ @functions = @functions.sort{|a,b| Levenshtein.distance(q, a.name) <=> Levenshtein.distance(q, b.name)}
+ @functions = @functions[0..24]
+
+ rescue
+ @functions = []
+ end
+
+ if @functions.size <= 0
+
+ if not q.match("@library")
+ q += " @library (\"Clojure Core\" | \"Clojure Contrib\")"
+ end
+
+ q = "*" + q + "*"
+
+ @functions = Function.search(q, :page => params[:page], :per_page => 16, :match_mode => :extended, :field_weights => {:name => 10,:doc => 1})
+
+ @functions = @functions[0..24]
+
+ end
+
if params[:feeling_lucky] and @functions.size > 0
func = @functions[0]
redirect_to "/#{func.library}/#{func.ns}/#{CGI::escape(func.name)}"
@@ -117,7 +133,7 @@ def search
end
- end
+ end
def lib_search
q = params[:q]
View
8 app/views/main/search.html.erb
@@ -53,7 +53,7 @@ $(document).ready(function() {
<%= 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>
+ <p class="doc"><%= f.doc %></p>
<span class="extra_info">
<span class="examples_count">
<%= f.examples.size %> example<%= (f.examples.size != 1 ? "s" : "") %>
@@ -66,11 +66,7 @@ $(document).ready(function() {
<% end %>
<% end %>
<h4 style="border-top: solid #ccc 1px">
- Showing results
- <%= @functions.current_page * @functions.per_page - @functions.per_page + 1 %>
- -
- <%= [@functions.current_page * @functions.per_page, @functions.total_entries].min %>
- <span><%= will_paginate @functions %></span>
+
</h4>
<% end%>
</div>
View
12 config/development.sphinx.conf
@@ -5,9 +5,9 @@ indexer
searchd
{
listen = 127.0.0.1:9312
- log = /Users/zkim/napplelabs/clojuredocs/log/searchd.log
- query_log = /Users/zkim/napplelabs/clojuredocs/log/searchd.query.log
- pid_file = /Users/zkim/napplelabs/clojuredocs/log/searchd.development.pid
+ log = /home/zkim/clojuredocs/log/searchd.log
+ query_log = /home/zkim/clojuredocs/log/searchd.query.log
+ pid_file = /home/zkim/clojuredocs/log/searchd.development.pid
max_matches = 10000
}
@@ -31,7 +31,7 @@ source function_core_0
index function_core
{
source = function_core_0
- path = /Users/zkim/napplelabs/clojuredocs/db/sphinx/development/function_core
+ path = /home/zkim/clojuredocs/db/sphinx/development/function_core
charset_type = utf-8
min_prefix_len = 1
enable_star = 1
@@ -63,7 +63,7 @@ source library_core_0
index library_core
{
source = library_core_0
- path = /Users/zkim/napplelabs/clojuredocs/db/sphinx/development/library_core
+ path = /home/zkim/clojuredocs/db/sphinx/development/library_core
charset_type = utf-8
}
@@ -94,7 +94,7 @@ source namespace_core_0
index namespace_core
{
source = namespace_core_0
- path = /Users/zkim/napplelabs/clojuredocs/db/sphinx/development/namespace_core
+ path = /home/zkim/clojuredocs/db/sphinx/development/namespace_core
charset_type = utf-8
}
Please sign in to comment.
Something went wrong with that request. Please try again.