Permalink
Browse files

added html and jquery

  • Loading branch information...
1 parent 9bc7f11 commit fb23f4d602f727b1200b2810441e128203c354c0 @dbasch committed Jul 10, 2011
View
@@ -9,6 +9,7 @@
require 'indextank'
require 'json'
require 'open-uri'
+require 'yaml'
def fetch(name, uri)
begin
@@ -22,6 +23,9 @@ def fetch(name, uri)
end
end
+config = YAML::load(File.open('config.yaml'))
+categories = config['categories'].split('|').map{|x| x.split(",")}
+
categories = [ ['person', 'people'],
['company', 'companies'],
['product', 'products'],
@@ -33,4 +37,4 @@ def fetch(name, uri)
toget = 'http://api.crunchbase.com/v/1/' + c[0] + '/' + x['permalink'] + '.js'
fetch('data/' + c[1] + '/' + x['permalink'] +'.js', toget)
end
-end
+en
View
@@ -6,8 +6,12 @@
require 'yaml'
def index(props,description)
- #rel = props['relationships'].length
- #products = props['products'].length
+ rel = 0
+ products = 0
+ if description == 'company' #make companies more likely to be a top result
+ rel = props['relationships'].length
+ products = props['products'].length
+ end
overview = Math.log(1 + (props['overview'] or '').length)
url = props['crunchbase_url']
t = props['image']
@@ -16,35 +20,48 @@ def index(props,description)
else
thumbnail = 'http://www.gravatar.com/avatar/00000000000000000000000000000000?default=mm'
end
- docs << { :docid => url, :fields => {:name => name, :thumbnail => thumbnail, :url => url, :description => description} , :variables => {0 => 0, 1 => 0, 2 => overview}}
- @count +=1
- if @count == 3000 or i == (things.length - 1)
- response = index.batch_insert(docs)
- batches += 1
- puts "batches: ", batches, docs.length
- docs = []
- @count = 0
+ docs << { :docid => url,
+ :fields => {:name => name, :thumbnail => thumbnail, :url => url, :description => description} ,
+ :variables => {0 => rel, 1 => products, 2 => overview}}
+ @count +=1
+ if @count == 3000 or i == (things.length - 1)
+ response = index.batch_insert(docs)
+ batches += 1
+ puts "batches: ", @batches, docs.length
+ @docs = []
+ @count = 0
+ end
end
-end
-
-config = YAML::load(File.open('config.yaml'))
-api = IndexTank::Client.new config['api_url']
-index = api.indexes "crunchbase"
-batches = 0
+ config = YAML::load(File.open('config.yaml'))
+ api = IndexTank::Client.new config['api_url']
+ categories = config['categories'].split('|').map{|x| x.split(",")}
-things = JSON.parse(File.read('data/products.js'))
-@count = 0
-docs = []
-things.each_with_index do |x, i|
- name = x['name']
- f = 'data/products/' + x['permalink'] + '.js'
- begin
- props = JSON.parse(File.read(f))
- rescue => e
- next
+ index = api.indexes config['index_name']
+ if not index.exists?
+ index.add({:public_search => true})
+ while not index.running?
+ sleep 0.5
+ printf "waiting for index %s to be ready...\n", idxname
+ end
end
- index(props, 'product')
+ printf "Ready.\n"
-end
+ @batches = 0
+ categories.each do |c|
+ things = JSON.parse(File.read('data/' +c[1] + '.js'))
+ @count = 0
+ @docs = []
+ things.each_with_index do |x, i|
+ name = x['name']
+ f = 'data/' c[1] + '/' + x['permalink'] + '.js'
+ begin
+ props = JSON.parse(File.read(f))
+ rescue => e
+ next
+ end
+ index(props, c[0])
+ end
+
+ end
View
@@ -0,0 +1,90 @@
+<html>
+ <head>
+ <!-- Dependencies -->
+
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
+ <script type="text/javascript" src="jquery.indextank.ize.js"></script>
+ <script type="text/javascript" src="jquery.indextank.autocomplete.js"></script>
+ <script type="text/javascript" src="jquery.indextank.ajaxsearch.js"></script>
+ <script type="text/javascript" src="jquery.indextank.renderer.js"></script>
+ <script type="text/javascript" src="jquery.indextank.instantsearch.js"></script>
+ <script type="text/javascript" src="jquery.indextank.instantlinks.js"></script>
+ <script type="text/javascript" src="jquery.indextank.basic.js"></script>
+
+<!-- <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/smoothness/jquery-ui.css" media="all" /> -->
+
+ <link type="text/css" rel="stylesheet" href="jquery-ui-1.8.13.custom.css" media="all" />
+ <link type="text/css" rel="stylesheet" href="jquery.ui.autocomplete.css" media="all" />
+ <style>
+ .ui-menu {
+ padding: 0em;
+ width: 500px;
+ }
+
+ .ui-menu-item {
+ border-bottom: 1px solid #eee;
+ padding: 2px;
+ }
+
+ .result span {
+ font-size: 14px;
+ vertical-align: top;
+ padding-left: 5px;
+ }
+
+ .result span.highlighted {
+ font-weight: bolder;
+ padding-left: 0px;
+ }
+
+ .result span.regular {
+ padding-left: 0px;
+ }
+
+ .result span.description:before {
+ content: "--";
+ vertical-align: top;
+ padding: 5px;
+ }
+ .result span.description {
+ font-size: 10px;
+ padding-left: 0px;
+ }
+
+ #query {
+ width: 300px;
+ }
+h3,body {
+ font-family:verdana;
+ }
+
+ </style>
+
+ <script>
+ $(document).ready(function(){
+ $("#myform").indextank_Ize("http://your_public_part.api.indextank.com", "crunchbase");
+ $("#query").indextank_InstantLinks({fieldThumbnail:'thumbnail'});
+ });
+ function load() {
+ var mytext = document.getElementById("query");
+ mytext.focus();
+ };
+
+
+</script>
+ </script>
+ </head>
+
+ <body onload="load()">
+ <h3>Instant Crunchbase</h3>
+ This is a demo of <a href="http://indextank.com/">IndexTank</a>'s search running on a static html page.<p/>
+
+ <form id="myform">
+ <small>Start typing the name of a company, person, etc.</small>
+ <input id="query" type="text" size="20"/>
+ </form>
+
+ Made by <a href="http://twitter.com/dbasch">@dbasch</a>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit fb23f4d

Please sign in to comment.