Solr Jquery 自动完成 URL 源

发布于 2024-12-04 07:26:10 字数 2263 浏览 3 评论 0原文

浏览完SO后,我发现这段代码到处都是,即使我想实现AutoComplete,我正在使用Solr来实现搜索,并且想使用TermsComponent来实现Autocomplet

    var cache = {};
    $("#textbox").autocomplete({
      source: function(request, response) {
       if (request.term in cache) {
        response($.map(cache[request.term].d, function(item) {
         return { value: item.value, id: item.id }
        }))
        return;
       }
       $.ajax({
        url: "/Services/AutoCompleteService.asmx/GetEmployees",  /* I use a web service */
        data: "{ 'term': '" + request.term + "' }",
        dataType: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataFilter: function(data) { return data; },
        success: function(data) {
         cache[request.term] = data;
         response($.map(data.d, function(item) {
          return {
           value: item.value,
           id: item.id
          }
         }))
        },
        error: HandleAjaxError  // custom method
       });
      },
      minLength: 3,
      select: function(event, ui) {
       if (ui.item) {
        formatAutoComplete(ui.item);   // custom method
       }
      }
     });

现在我的问题是,如何配置url源,等等应该是,下面的url http://localhost:8983 /solr/terms?terms.fl=name&terms.prefix=at&wt=json&omitHeader=true 给我完美结果,现在请告诉我 wat 应该是我的网址源,如果我想自定义添加更多参数,如 terms.lower=py&terms.lower.incl=false&indent=true& ;wt=json 等,我应该更好地在 url 或我的 java 类中对它们进行编码吗 列表项 = query(q, Integer.parseInt(limit));

private List<TermsResponse.Term> query(String q, int limit) {
List<TermsResponse.Term> items = null;
SolrQuery query = new SolrQuery();
query.addTermsField("spell");
query.setTerms(true);
query.setTermsLimit(limit);
query.setTermsLower(q);
query.setTermsPrefix(q);
query.setQueryType("/terms");
try {
  QueryResponse qr = server.query(query);
  TermsResponse resp = qr.getTermsResponse();
  items = resp.getTerms("name");
} catch (SolrServerException e) {
  items = null;
}
return items;

请帮忙,嗯

,jquery 不太好,所以想确认一件事,对于我需要的东西,我只需要修改这里的 url 或者必须自定义更多的东西

After browsing thru SO, i found this piece of code everywhere, even I want to implement AutoComplete, I am using Solr to implement search, and wanted to use TermsComponent foe implementing Autocomplet

    var cache = {};
    $("#textbox").autocomplete({
      source: function(request, response) {
       if (request.term in cache) {
        response($.map(cache[request.term].d, function(item) {
         return { value: item.value, id: item.id }
        }))
        return;
       }
       $.ajax({
        url: "/Services/AutoCompleteService.asmx/GetEmployees",  /* I use a web service */
        data: "{ 'term': '" + request.term + "' }",
        dataType: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataFilter: function(data) { return data; },
        success: function(data) {
         cache[request.term] = data;
         response($.map(data.d, function(item) {
          return {
           value: item.value,
           id: item.id
          }
         }))
        },
        error: HandleAjaxError  // custom method
       });
      },
      minLength: 3,
      select: function(event, ui) {
       if (ui.item) {
        formatAutoComplete(ui.item);   // custom method
       }
      }
     });

Now my question is, How to configure the url source, wat it should be, the following url
http://localhost:8983/solr/terms?terms.fl=name&terms.prefix=at&wt=json&omitHeader=true
gives me perfect result, now pls tell me wat should be my url source, and if i want to customize add more parameters like terms.lower=py&terms.lower.incl=false&indent=true&wt=json etc ,should i better harcode them in url or in my java class like
List terms = query(q, Integer.parseInt(limit));

private List<TermsResponse.Term> query(String q, int limit) {
List<TermsResponse.Term> items = null;
SolrQuery query = new SolrQuery();
query.addTermsField("spell");
query.setTerms(true);
query.setTermsLimit(limit);
query.setTermsLower(q);
query.setTermsPrefix(q);
query.setQueryType("/terms");
try {
  QueryResponse qr = server.query(query);
  TermsResponse resp = qr.getTermsResponse();
  items = resp.getTerms("name");
} catch (SolrServerException e) {
  items = null;
}
return items;

}

Please help, um not so good in jquery, so wanted to confirm one more thing,for wat i need, i just need to modify the url over here or have to customize few more things

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2024-12-11 07:26:11

您不太可能需要参数化此客户端,因此请在服务器端设置这些参数。用代码设置它们而不是在 URL 中硬编码它们通常更好,它揭示了意图。另请记住,您可以在 solr 配置中设置参数

最后,不要巧合地编程。了解您正在使用的 jQuery 代码片段,否则您迟早会遇到问题。

It's not very likely that you need to parameterize this client-side, so set those parameters server-side. Setting them with code instead of hardcoding them in the URL is generally better, it reveals the intention. Also remember that you can set parameters in the solr config.

Lastly, don't program by coincidence. Understand the jQuery snippet you're using, otherwise you will have problems sooner or later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文