简体   繁体   中英

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:

 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.

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.

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(); is giving connection without any delay.
  2. Instead of creating new HashMap hashItems = new HashMap(); you can use

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

in jsp use

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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