Created
February 23, 2012 16:24
-
-
Save egaumer/1893529 to your computer and use it in GitHub Desktop.
Simple Filtered Search with Cloud9 Javascript API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A simple search example using the Cloud9 API */ | |
(function($) { | |
/* create a query object */ | |
var query = c9.query.QueryString("message:hello"); | |
/* create a simple term filter that filters by user */ | |
var filter = c9.filter.TermFilter("user", "jsmith"); | |
/* compose the query and filter into a Lucene filterQuery */ | |
var filterQuery = c9.query.FilteredQuery(query, filter); | |
/* a function to display results - uses underscore.js templates */ | |
var resultsCallBack = function(results) { | |
if (results.hits) { | |
var template = _.template($("#results").html(), results.hits); | |
$(".search").empty(); | |
$(".search").append(template); | |
} | |
}; | |
/* execute the request using the filterQuery */ | |
c9.search.Request() | |
.collections("twitter") | |
.types("tweet") | |
.query(filterQuery) | |
.get(resultsCallBack); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<head> | |
<title>Simple Search</title> | |
<!-- Example search template using underscore.js --> | |
<script type="text/template" id="results"> | |
<% _.each(hits, function(hit) { %> | |
<li><%= hit._source.message %></li> | |
<% }); %> | |
</script> | |
</head> | |
<body> | |
<div class="search"></div> | |
<script src="js/jquery-1.6.2.min.js"></script> | |
<script src="js/underscore-min.js"></script> | |
<script src="js/c9/c9api.min.js"></script> | |
<!-- change 'yourapp' to the name of your Cloud9 application --> | |
<script defer src="yourapp/js/filterSearch.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
curl -XPUT -H 'Content-Type:application/json' 'http://localhost:2600/v1/twitter/tweet/1' -d '{ | |
"user": "jsmith", | |
"date": "2012-03-02", | |
"message": "A simple message saying hello" | |
}' | |
curl -XPUT -H 'Content-Type:application/json' 'http://localhost:2600/v1/twitter/tweet/2' -d '{ | |
"user": "jsmith", | |
"date": "2012-03-03", | |
"message": "A simple message saying goodbye" | |
}' | |
curl -XPUT -H 'Content-Type:application/json' 'http://localhost:2600/v1/twitter/tweet/3' -d '{ | |
"user": "jdoe", | |
"date": "2012-03-02", | |
"message": "A simple message saying hello back" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment