Skip to content

Commit

Permalink
Search started working
Browse files Browse the repository at this point in the history
  • Loading branch information
Abin committed Jun 22, 2012
1 parent ce5f2ba commit 19ca162
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
40 changes: 30 additions & 10 deletions src/controller/Search.gs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package controller
/**
* Created with IntelliJ IDEA.
* User: ashahab
* Date: 6/21/12
* Time: 3:13 AM
* To change this template use File | Settings | File Templates.
*/
uses ronin.config.*

uses ronin.RoninController
uses view.Layout
uses view.ViewPost
Expand All @@ -21,13 +27,12 @@ uses org.elasticsearch.node.NodeBuilder;
uses org.elasticsearch.client.transport.TransportClient;
uses org.elasticsearch.common.transport.InetSocketTransportAddress;
uses org.elasticsearch.action.index.IndexRequestBuilder
/**
* Created with IntelliJ IDEA.
* User: ashahab
* Date: 6/21/12
* Time: 3:13 AM
* To change this template use File | Settings | File Templates.
*/
uses org.elasticsearch.index.query.FilterBuilders;
uses org.elasticsearch.index.query.QueryBuilders;
uses org.elasticsearch.index.query.QueryStringQueryBuilder;
uses org.elasticsearch.action.search.SearchType;
uses org.elasticsearch.search.SearchHit;

class Search extends RoninController {
function index() {
question();
Expand All @@ -37,7 +42,22 @@ class Search extends RoninController {
view.Search.render(Writer)
})
}
function ask() {

function ask(question: String) {
print("question: " + question);
//make a query to elastic search
var client = Overflow.getCachedClient()
var qb = QueryBuilders.queryString(question);
var response = client.prepareSearch({"posts"})
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(qb)
.setFrom(0).setSize(60)
.execute()
.actionGet();
//get the answers and return
var docs = response.getHits().getHits();
for (var sd in docs) {
print("hit: " + sd.getSource().get("Body"))
}
//print to a page nicely
}
}
2 changes: 1 addition & 1 deletion src/view/EditPost.gst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Ext.require([
//'Ext.tab.Panel'
'*'
]);
//alert("poo before!");

Ext.onReady(function() {
Ext.QuickTips.init();

Expand Down
16 changes: 7 additions & 9 deletions src/view/Search.gst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%@ extends ronin.RoninTemplate %>
<% uses controller.Overflow %>
<% uses controller.Search %>

<% uses java.lang.String %>
<% using(target(Search #ask(String))) { %>
<script type="text/javascript" >
alert("pook!");
Ext.require([
//'Ext.form.*',
//'Ext.layout.container.Column',
Expand All @@ -20,9 +20,9 @@ Ext.onReady(function() {

bd.createChild({tag: 'h2', html: 'Search posts'});

alert("puk!");

var top = new Ext.form.FormPanel({
standardSubmit: true,
// standardSubmit: true,
id: 'searchForm',
collapsible: true,
frame: true,
Expand Down Expand Up @@ -61,11 +61,8 @@ Ext.onReady(function() {
var form = top.getForm();
if(form.isValid()){
form.submit({
url: 'poot!',
waitMsg: 'Saving...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your post has been saved.');
}
url: '${TargetURL}',
waitMsg: 'Searching...'
});
}
}
Expand All @@ -76,3 +73,4 @@ Ext.onReady(function() {

});
</script>
<%}%>

0 comments on commit 19ca162

Please sign in to comment.