2011-12-12 72 views
0

我使用Solr的实现自动完成使用JSP,我使用下面的代码,以便检索术语列表:Solr的和Ajax的自动完成与远程数据源

SolrQuery query = new SolrQuery(); 
query.addTermsField("name_auto"); 
query.setTerms(true); 
query.setTermsPrefix(TEXTFIELD VALUE); 

... 

我已经到根据文本字段(前缀)的值(例如:“k”)检索术语列表,同样,我必须为每个按键更新此列表。

我跟着这个链接: http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/

和我使用的JQuery的文件:(它同样成立于谷歌图书馆) http://jquery.com/

原因我想这个代码,但问题是如何能我写的URL,所以我可以做一个远程数据源到我的自动完成?

感谢

+1

可能的重复http://stackoverflow.com/questions/868985/javascript-jsp –

+0

嗨javanna,我知道,JSP在服务器端和客户端上的JP工作,我只想知道是否有任何其他解决方案知道文本字段的值作为前缀。 thankx – sakurami

+0

我仍然理解你的问题是要访问同一个JSP内的JS内容,这是无法完成的。请随时编辑更多详细信息,但我的重复评论仍然有效。 –

回答

1

好吧,谢谢ü所有,我修复使用jQueryUI的文件和教程我prblem,这是我的代码:

$(function() { 
$(MYTEXTFIELDNAME).autocomplete({ 
    source: function(request, response) { 
    $.ajax({ 
      url: 'http://localhost:8080/solr/terms?terms=true&terms.fl=MYAUTOFIELD&terms.prefix=' 
       +request.term+'&wt=json', 
    dataType: "json", 
    data: { 
     style: "full", 
     maxRows: 5, 
     name_startsWith: request.term 
     }, 

     success: function(data) { 
    response($.map(data.terms.MYAUTOFIELD, function(item) { 
     return { 
     label: item, 
     value: item, 
      } 
    })); 
    } 
     }); 
    }, 
     minLength: 1, 
.... 

是在http://jqueryui.com/demos/autocomplete/#remote

再次感谢描述的其余代码。