Skip to content

Commit

Permalink
Fixed search term returning null exception and updated deprecated use…
Browse files Browse the repository at this point in the history
… of TermAttribute
  • Loading branch information
sparkica committed Jan 24, 2013
1 parent 9ffb489 commit 0fdcb77
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 75 deletions.
54 changes: 3 additions & 51 deletions module/scripts/suggestterm.suggest.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
$.suggest.suggest.prototype, $.suggest.suggest.prototype,
{ {
create_item: function(data,response_data) { create_item: function(data,response_data) {
console.log("---- create item ----");
var css = this.options.css; var css = this.options.css;


var li = $("<li>").addClass(css.item); var li = $("<li>").addClass(css.item);
var name = $("<div>").addClass(css.item_name) var name = $("<div>").addClass(css.item_name)

.append($("<label>") .append($("<label>")
.append($.suggest.strongify(data.name,response_data.prefix))); .append($.suggest.strongify(data.name,response_data.prefix)));
// this converts html escaped strings like "&amp;" // this converts html escaped strings like "&amp;"
Expand All @@ -29,7 +27,6 @@
}, },


request: function(value, cursor) { request: function(value, cursor) {
console.log("---- request ---");
var self = this, var self = this,
o = this.options; o = this.options;


Expand All @@ -38,85 +35,43 @@
data[o.query_param_name] = query; data[o.query_param_name] = query;


clearTimeout(this.request.timeout); clearTimeout(this.request.timeout);
console.log("Data before ajax call");
data["prefix"] = query; data["prefix"] = query;
data["type_strict"] = "classes"; data["type_strict"] = "classes";
data["type"] = theProject.id; data["type"] = theProject.id;


var url = o.service_url + o.service_path + "?" + $.param(data, true); var url = o.service_url + o.service_path + "?" + $.param(data, true);
console.log(url);
console.log(data);

var ajax_options = { var ajax_options = {
url: o.service_url + o.service_path, url: o.service_url + o.service_path,
data: data, data: data,
traditional: true, traditional: true,
/* beforeSend: function(xhr) { error: function(xhr) {
console.log("--- before send ---");
console.log(xhr);
var calls = self.input.data("request.count.suggest") || 0;
calls += 1;
self.trackEvent(self.name, "request", "count", calls);
self.input.data("request.count.suggest", calls);
},
*/ error: function(xhr) {
console.log("--- request error --");
console.log(xhr);
self.status_error(); self.status_error();

self.trackEvent(self.name, "request", "error", { self.trackEvent(self.name, "request", "error", {
url: this.url, url: this.url,
response: xhr ? xhr.responseText : '' response: xhr ? xhr.responseText : ''
}); });
self.input.trigger("fb-error", Array.prototype.slice.call(arguments)); self.input.trigger("fb-error", Array.prototype.slice.call(arguments));
}, },
complete: function(xhr) { complete: function(xhr) {
console.log(" -- complete --");
if (xhr) { if (xhr) {
self.trackEvent(self.name, "request", "tid", self.trackEvent(self.name, "request", "tid",
xhr.getResponseHeader("X-Metaweb-TID")); xhr.getResponseHeader("X-Metaweb-TID"));
} }
}, },
success: function(data) { success: function(data) {
console.log("--- success ---");
console.log(data);
$.suggest.cache[url] = data; $.suggest.cache[url] = data;
data.prefix = value; // keep track of prefix to match up response with input value data.prefix = value; // keep track of prefix to match up response with input value
self.response(data, cursor ? cursor : -1); self.response(data, cursor ? cursor : -1);

}, },
dataType: "json", dataType: "json",
cache: true cache: true
}; };
this.request.timeout = setTimeout(function() { this.request.timeout = setTimeout(function() {
console.log("Doing something...");
$.ajax(ajax_options); $.ajax(ajax_options);
}, o.xhr_delay); }, o.xhr_delay);


}, },

flyout_request:function(data){
response: function(data){
console.log("---- response ----");
console.log(data);
var o = this.options,
p = this.pane,
s = this.get_selected() || [];
if (p.is(":visible") && s.length) {
var sug_data = s.data("data.suggest");
if (sug_data && data.id === sug_data.id) {
this.flyoutpane.html('<div class="fbs-flyout-content">' + data.description + '</div>');
this.flyout_position(s);
this.flyoutpane.show()
.data("data.suggest", sug_data);
this.input.trigger("fb-flyoutpane-show", this);
}
}

},

flyout_request:function(data){
console.log("----- flyout request ---");

var self = this; var self = this;


var o = this.options, var o = this.options,
Expand Down Expand Up @@ -145,7 +100,6 @@
}, },


flyout_response:function(data){ flyout_response:function(data){
console.log("---- flyout response ----");
var o = this.options, var o = this.options,
p = this.pane, p = this.pane,
s = this.get_selected() || []; s = this.get_selected() || [];
Expand All @@ -162,8 +116,6 @@
} }
})); }));




$.extend($.suggest.suggestterm, { $.extend($.suggest.suggestterm, {
defaults: $.extend( defaults: $.extend(
true, true,
Expand Down
1 change: 0 additions & 1 deletion src/org/deri/grefine/rdf/commands/SuggestTermCommand.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
String projectId = request.getParameter("type"); String projectId = request.getParameter("type");


response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
//response.setStatus(HttpServletResponse.SC_OK);


JSONWriter writer = new JSONWriter(response.getWriter()); JSONWriter writer = new JSONWriter(response.getWriter());
String type = request.getParameter("type_strict"); String type = request.getParameter("type_strict");
Expand Down
24 changes: 1 addition & 23 deletions src/org/deri/grefine/rdf/vocab/imp/VocabularySearcher.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.TokenStream;
//import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
Expand Down Expand Up @@ -61,14 +60,6 @@ public class VocabularySearcher implements IVocabularySearcher {
private IndexSearcher searcher; private IndexSearcher searcher;


private Directory _directory; private Directory _directory;

// public VocabularySearcher(File dir) throws IOException {
// _directory = new SimpleFSDirectory(new File(dir, "luceneIndex"));
// writer = new IndexWriter(_directory, new SimpleAnalyzer(),
// IndexWriter.MaxFieldLength.LIMITED);
// writer.commit();
// searcher = new IndexSearcher(_directory);
// }


public VocabularySearcher(File dir) throws IOException { public VocabularySearcher(File dir) throws IOException {
_directory = new SimpleFSDirectory(new File(dir, "luceneIndex")); _directory = new SimpleFSDirectory(new File(dir, "luceneIndex"));
Expand Down Expand Up @@ -109,20 +100,7 @@ public void importAndIndexVocabulary(String name, String uri, Repository reposit
public List<SearchResultItem> searchClasses(String str, String projectId) public List<SearchResultItem> searchClasses(String str, String projectId)
throws ParseException, IOException { throws ParseException, IOException {
Query query = prepareQuery(str, CLASS_TYPE, projectId); Query query = prepareQuery(str, CLASS_TYPE, projectId);
if(query == null) TopDocs docs = searcher.search(query, getMaxDoc());
{
logger.error("Query null");
}

logger.info("Query: " + query);

TopDocs docs = searcher.search(query, getMaxDoc());

if(docs == null) {
logger.error("Docs null...");
}

logger.info("Got docs.");
return prepareSearchResults(docs); return prepareSearchResults(docs);
} }


Expand Down

0 comments on commit 0fdcb77

Please sign in to comment.