Project

General

Profile

« Previous | Next » 

Revision 3226

Added by Jing Tao over 17 years ago

Add a new method to print out more effecient query.

View differences:

src/edu/ucsb/nceas/metacat/QueryGroup.java
47 47
    private Vector queryTermsWithSameValue = null;//this two dimension vectors.
48 48
                                                  //will hold query terms which has same search value.
49 49
    private Vector queryTerms = null;//this vector only holds query terms without same search value.
50
    private Vector queryGroupsChildren = null;
50 51
    private static Logger logMetacat = Logger.getLogger(QueryGroup.class);
51 52

  
52 53
    /**
......
60 61
      children = new Vector();
61 62
      queryTermsWithSameValue = new Vector();
62 63
      queryTerms = new Vector();
64
      queryGroupsChildren = new Vector();
63 65
    }
64 66

  
65 67
    /**
......
68 70
     * @param qgroup the query group to be added to the list of terms
69 71
     */
70 72
    public void addChild(QueryGroup qgroup) {
71
      children.add((Object)qgroup);
73
      //children.add((Object)qgroup);
74
      queryGroupsChildren.add(qgroup);
72 75
    }
73 76

  
74 77
    /**
......
77 80
     * @param qterm the query term to be added to the list of terms
78 81
     */
79 82
    public void addChild(QueryTerm qterm) {
80
      children.add((Object)qterm);
83
      // children.add((Object)qterm);
81 84
      handleNewQueryTerms(qterm);
82 85
      
83 86
    }
......
157 160
			+ self.toString());
158 161
      return self.toString();
159 162
    }
163
    
164
    
165
    /*
166
     * If every query term in a queryGroup share a search value, we should
167
     * use a new query to replace the original query term query in order to
168
     * improve performance
169
     */
170
    private String printSQLStringWithSameSearchValue()
171
    {
172
    	String sql ="";
173
    	String value ="";
174
    	StringBuffer sqlBuff = new StringBuffer();
175
    	Vector pathVector = new Vector();
176
    	int index =0;
177
    	
178
    	if (queryTermsWithSameValue != null)
179
    	{
180
    		QueryTerm term1 = (QueryTerm)queryTermsWithSameValue.elementAt(0);
181
        	value = term1.getValue();
182
        	boolean first = true;
183
			sqlBuff.append("SELECT DISTINCT docid FROM xml_path_index WHERE UPPER(nodedata) LIKE '%");
184
			sqlBuff.append(value);
185
			sqlBuff.append("%' AND path IN (");
186
    		//gets every path in query term object
187
    		for (int i=0; i<queryTermsWithSameValue.size(); i++)
188
    		{
189
    			QueryTerm term = (QueryTerm)queryTermsWithSameValue.elementAt(i);
190
    			value = term.getValue();
191
    			String path = term.getPathExpression();
192
    			if (path != null && !path.equals(""))
193
    			{
194
    				if (first)
195
    				{
196
    					first = false;
197
    					sqlBuff.append("'");
198
    					sqlBuff.append(path);
199
    					sqlBuff.append("'");
200
    					
201
    				}
202
    				else
203
    				{
204
    					sqlBuff.append(",'");
205
    					sqlBuff.append(path);
206
    					sqlBuff.append("'");
207
    				}
208
    				index++;
209
    			}
210
    		}
211
    		sqlBuff.append(")");
212
    	
213
    	}
214
    	if (index >0)
215
    	{
216
    		sql = sqlBuff.toString();
217
    	}
218
    	return sql;
219
    }
160 220

  
161 221
    /**
162 222
     * create a String description of the query that this instance represents.

Also available in: Unified diff