简体   繁体   English

改善搜索功能

[英]Improve the search functionality

How can I improve the search functionality.? 如何改善搜索功能。 I have written some codes to search for something.The search was taking too much time. 我已经写了一些代码来搜索某些东西,搜索花费了太多时间。 And the code snippets here, 这里的代码段

I am pulling the data from the database using this method., 我正在使用这种方法从数据库中提取数据。

   OracleConnection connection = null;
   OraclePreparedStatement ptmst = null;
   OracleResultSet rs = null;
   OracleCallableStatement cstmt = null;
   StringBuffer strBfr = new StringBuffer();
   ArrayList myList = new ArrayList();
    try
    {     
      connection = (OracleConnection) TransactionScope.getConnection();
      strBfr.append("select distinct .......... ");  
      ptmst = (OraclePreparedStatement)connection.prepareStatement(strBfr.toString());    
      rs = (OracleResultSet)ptmst.executeQuery();           
      while (rs.next()) 
                {               
                HashMap hashItems = new HashMap();
                hashItems.put("first",rs.getString(1));
                hashItems.put("second",rs.getString(2));    
                myList.add(hashItems);
                }       

    }
    catch (Exception e) {
        }
    finally {

            try {
                if (ptmst != null) {
                    ptmst.close();
                }
            } catch (Exception e) {
            }

            try {
                if (connection != null) {
                    TransactionScope.releaseConnection(connection);
                }
            } catch (Exception e) {
            }

        }
        return myList; 

In my jsp: 在我的jsp中:

 ArrayList getValues = new ArrayList();     
    getValues = //calling Method here.
    for(int i=0; i < getValues.size();i++)  
    {
    HashMap quoteSrch=(HashMap)allPOV.get(i);                        
    first = (String)quoteSrch.get("first");
    second = (String)quoteSrch.get("second");
    }

Query: 查询:

SELECT DISTINCT(mtl.segment1),
  mtl.description ,
  mtl.inventory_item_id ,
  mtl.attribute16
FROM mtl_system_items_b mtl,
  mtl_system_items_tl k
WHERE 1                           =1
AND mtl.organization_id           = ?
AND k.inventory_item_id           = mtl.inventory_item_id
AND NVL(orderable_on_web_flag,'N')= 'Y'
AND NVL(web_status,'UNPUBLISHED') = 'PUBLISHED'
AND mtl.SEGMENT1 LIKE ?  --Here is the search term

Make sure organization_id , inventory_item_id and especially SEGMENT1 is indexed in your table. 确保在表中索引了organization_id,inventory_item_id,尤其是SEGMENT1

Your query is pretty standard , if that doesn't work then it seems like your DB server is responding slow which could be due to number of reasons like low space , low memory , slow disk/read etc. 您的查询是非常标准的,如果不起作用,则您的数据库服务器似乎响应缓慢,这可能是由于空间不足,内存不足,磁盘/读取速度慢等多种原因造成的。

You can then ask your DBA/Server admins to check that. 然后,您可以要求DBA /服务器管理员进行检查。

First you need to find out the real problem 首先,您需要找出真正的问题

  • Is it the DB query 是数据库查询
  • Is it the Network (is the App and the DB located on the same machine?) 是网络吗(应用程序和数据库位于同一台计算机上吗?)

Once you have identified that it is the DB query, then it becomes more of a DB question. 一旦确定它是数据库查询,它就更多地成为数据库问题。

  • How does the two tables look like? 这两个表看起来如何?
  • Any index used? 使用任何索引?
  • How does the data look like (How many rows etc) 数据如何显示(多少行等)

After you have analyzed this, you should be able to post the question differently and expect an answer. 在分析了此问题之后,您应该能够以不同的方式发布问题并期望得到答案。 I am not a DB guy, but I am sure someone would be able to provide some pointers. 我不是数据库专家,但我敢肯定有人会提供一些指导。

Tunning has to be done: 必须进行调音:

  1. Check TransactionScope.getConnection(); 检查TransactionScope.getConnection(); is giving connection without any delay. 没有任何延迟地建立连接。
  2. Instead of creating new HashMap hashItems = new HashMap(); 而不是创建新的HashMap hashItems = new HashMap(); you can use 您可以使用

     while (rs.next()){ myList.add(rs.getString(1) + "delimiter" + rs.getString(2)); } 

in jsp use 在jsp中使用

first = allPOV.get(i).split("delimter")[0];
second = allPOV.get(i).split("delimter")[1];

so that you can reduce memory . 这样可以减少内存

  1. If possible use limit in your query, and use index on SEGMENT1 link . 如果可能,请在查询中使用限制,并在SEGMENT1 链接上使用索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM