Skip to content

Instantly share code, notes, and snippets.

View phillro's full-sized avatar

Phillip Rosen phillro

View GitHub Profile
@phillro
phillro / gist:1126799
Created August 5, 2011 02:19
Easy Document Searching with Jquery, jquery-templates and Elastic Search
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<script id="searchResultTemplate" type="text/x-jquery-tmpl">
{{each(i,result) hits}}
var serverOptions = {
host: 'www.elasticsearchhq.com',
port: 9200,
secure: true,
auth: {
username:'[USERNAME]',
password:'[PASSWORD]'
}
};
@phillro
phillro / gist:1126819
Created August 5, 2011 02:33
Grails Restclient. Elastic Search with authentication for ElasticSearch HQ
withRest(uri: 'https://esh01.elasticsearchhq.com:9200) {
handler.success = { resp, results ->
return results
}
handler.failure = { resp ->
log.error "Unexpected failure: ${resp.statusLine}"
return false;
}
def response = post(
@phillro
phillro / gist:1147250
Created August 15, 2011 17:23
Elastica search example
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/Elastica/lib'));
function elasticsearch_autoload($class) {
$file = str_replace('_', '/', $class) . '.php';
require_once $file;
}
spl_autoload_register('elasticsearch_autoload');
@phillro
phillro / gist:1147306
Created August 15, 2011 17:50
Elastica with an authenticated search
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/Elastica/lib'));
function elasticsearch_autoload($class) {
$file = str_replace('_', '/', $class) . '.php';
require_once $file;
}
spl_autoload_register('elasticsearch_autoload');
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
@phillro
phillro / gist:1182306
Created August 30, 2011 22:44
Adding a document and searching
<?php
//This example was adapted from the documentation available at https://github.com/ruflin/Elastica
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/Elastica/lib'));
function elasticsearch_autoload($class) {
$file = str_replace('_', '/', $class) . '.php';
require_once $file;
}
spl_autoload_register('elasticsearch_autoload');
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
<?php
//This example was adapted from the documentation available at https://github.com/ruflin/Elastica
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/Elastica/lib'));
function elasticsearch_autoload($class) {
$file = str_replace('_', '/', $class) . '.php';
require_once $file;
}
spl_autoload_register('elasticsearch_autoload');
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
@phillro
phillro / gist:1193227
Created September 4, 2011 17:59
Elasticsearch autocomplete example with cross origin resource sharing
<html>
<head>
<link rel="stylesheet" href="/examples/stylesheets/ui-lightness/jquery-ui-1.8.16.custom.css" type="css">
<script type="text/javascript" src="/examples/javascripts/jquery.min.js"></script>
<script type="text/javascript" src="/examples/javascripts/jquery.base64.min.js"></script>
<script type="text/javascript" src="/examples/javascripts/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/examples/javascripts/jquery.tmpl.min.js"></script>
</head>
<body>
@phillro
phillro / gist:1193253
Created September 4, 2011 18:10
Elasticsearch autocomplete example with cross origin resource sharing and authentication
<html>
<head>
<link rel="stylesheet" href="./stylesheets/ui-lightness/jquery-ui-1.8.16.custom.css" type="css">
<script type="text/javascript" src="/javascripts/jquery.min.js"></script>
<script type="text/javascript" src="/javascripts/jquery.base64.min.js"></script>
<script type="text/javascript" src="/javascripts/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/javascripts/jquery.tmpl.min.js"></script>
</head>
<body>
module.exports = textUtil = function() {
var self = this;
self.fieldRelevancyValues = {
distance: {value:.10, type:'-exp'},
nameLev : {value:.30},
zip: {value:.40}
}