来自大型数据库的Primefaces自动完成功能无法快速运行 [英] Primefaces Autocomplete from huge database not acting fast

查看:253
本文介绍了来自大型数据库的Primefaces自动完成功能无法快速运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有pojos的primefaces自动完成组件,该组件是从具有大量行的数据库表中填充的. 当我从包含数百万个条目(SELECT synonym FROM synonyms WHERE synonym like '%:query%')的数据库中选择值时,由于表上的数据库条目很大,因此需要很长时间才能找到关于自动完成的单词,并且将来还会更大. 关于提高自动完成功能的速度有什么建议.

I am using primefaces autocomplete component with pojos and which is filled from a database table with huge number of rows. When I select value from database which contains millions of entries (SELECT synonym FROM synonyms WHERE synonym like '%:query%') it takes a very long time to find the word on autocomplete because of huge database entries on my table and it will be bigger in future. Is there any suggestions on making autocomplete acting fast.

推荐答案

我终于开始使用索引solar来进行快速请求,而我的表将包含超过400万个条目,这些条目必须快速解析且不会消耗很多记忆. 这是我的解决方案,也许有人会和我有同样的问题.

I finally went to using an index solar for doing fast requests while my table will contains more than 4 million entries which must be parsed fastly and without consuming a lot of memory. Here's I my solution maybe someone will have same problem as me.

public List<Synonym> completeSynonym(String query) {

    List<Synonym> filteredSynonyms = new ArrayList<Synonym>();
    // ResultSet result;
    // SolrQuery solrQ=new SolrQuery();
    String sUrl = "http://......solr/synonym_core";

    SolrServer solr = new HttpSolrServer(sUrl);
    ModifiableSolrParams parameters = new ModifiableSolrParams();
    parameters.set("q", "*:*"); // query everything
    parameters.set("fl", "id,synonym");// send back just the id
                                                //and synonym values
    parameters.set("wt", "json");// this in json format
    parameters.set("fq", "synonym:\"" + query+"\"~0"); //my conditions

    QueryResponse response;
    try {

        if (query.length() > 1) {
            response = solr.query(parameters);

            SolrDocumentList dl = response.getResults();
            for (int i = 0; i < dl.size(); i++) {
                Synonym s = new Synonym();
                s.setSynonym_id((int) dl.get(i).getFieldValue("id"));
                s.setSynonymName(dl.get(i).getFieldValue("synonym")
                        .toString());
                filteredSynonyms.add(s);
            }
        }
    } catch (SolrServerException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    return filteredSynonyms;
}

这篇关于来自大型数据库的Primefaces自动完成功能无法快速运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆