Revision 2366
Added by sgarg almost 20 years ago
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
686 | 686 |
{ |
687 | 687 |
|
688 | 688 |
StringBuffer self = new StringBuffer(); |
689 |
StringBuffer queryString = new StringBuffer(); |
|
689 | 690 |
|
690 |
self.append("SELECT docid,docname,doctype,");
|
|
691 |
self.append("date_created, date_updated, rev ");
|
|
692 |
self.append("FROM xml_documents WHERE docid IN (");
|
|
691 |
queryString.append("SELECT docid,docname,doctype,");
|
|
692 |
queryString.append("date_created, date_updated, rev ");
|
|
693 |
queryString.append("FROM xml_documents WHERE");
|
|
693 | 694 |
|
694 |
// This determines the documents that meet the query conditions |
|
695 |
self.append(query.printSQL(useXMLIndex)); |
|
695 |
// Get the query from the QueryGroup and check |
|
696 |
// if no query has been returned |
|
697 |
String queryFromQueryGroup = query.printSQL(useXMLIndex); |
|
698 |
if(!queryFromQueryGroup.trim().equals("()")){ |
|
699 |
self.append(" docid IN ("); |
|
700 |
self.append(query.printSQL(useXMLIndex)); |
|
701 |
self.append(") "); |
|
702 |
} |
|
696 | 703 |
|
697 |
self.append(") "); |
|
698 |
|
|
699 | 704 |
// Add SQL to filter for doctypes requested in the query |
700 | 705 |
// This is an implicit OR for the list of doctypes. Only doctypes in |
701 | 706 |
// this |
702 | 707 |
// list will be searched if the tag is present |
703 | 708 |
if (!filterDocList.isEmpty()) { |
704 | 709 |
boolean firstdoctype = true; |
705 |
self.append(" AND ("); |
|
710 |
boolean emptyString = true; |
|
711 |
|
|
712 |
if(!self.toString().equals("")){ |
|
713 |
self.append(" AND ("); |
|
714 |
emptyString = false; |
|
715 |
} |
|
716 |
|
|
706 | 717 |
Enumeration en = filterDocList.elements(); |
707 | 718 |
while (en.hasMoreElements()) { |
708 | 719 |
String currentDoctype = (String) en.nextElement(); |
... | ... | |
713 | 724 |
self.append(" OR doctype = '" + currentDoctype + "'"); |
714 | 725 |
} |
715 | 726 |
} |
716 |
self.append(") "); |
|
727 |
|
|
728 |
if(!emptyString){ |
|
729 |
self.append(") "); |
|
730 |
} |
|
717 | 731 |
} |
718 | 732 |
|
719 | 733 |
// Add SQL to filter for owners requested in the query |
720 | 734 |
// This is an implicit OR for the list of owners |
721 | 735 |
if (!ownerList.isEmpty()) { |
722 | 736 |
boolean first = true; |
723 |
self.append(" AND ("); |
|
737 |
boolean emptyString = true; |
|
738 |
|
|
739 |
if(!self.toString().equals("")){ |
|
740 |
self.append(" AND ("); |
|
741 |
emptyString = false; |
|
742 |
} |
|
743 |
|
|
724 | 744 |
Enumeration en = ownerList.elements(); |
725 | 745 |
while (en.hasMoreElements()) { |
726 | 746 |
String current = (String) en.nextElement(); |
... | ... | |
734 | 754 |
self.append(" OR lower(user_owner) = '" + current + "'"); |
735 | 755 |
} |
736 | 756 |
} |
737 |
self.append(") "); |
|
757 |
|
|
758 |
if(!emptyString){ |
|
759 |
self.append(") "); |
|
760 |
} |
|
738 | 761 |
} |
739 | 762 |
|
740 | 763 |
// Add SQL to filter for sites requested in the query |
741 | 764 |
// This is an implicit OR for the list of sites |
742 | 765 |
if (!siteList.isEmpty()) { |
743 | 766 |
boolean first = true; |
744 |
self.append(" AND ("); |
|
767 |
boolean emptyString = true; |
|
768 |
|
|
769 |
if(!self.toString().equals("")){ |
|
770 |
self.append(" AND ("); |
|
771 |
emptyString = false; |
|
772 |
} |
|
773 |
|
|
745 | 774 |
Enumeration en = siteList.elements(); |
746 | 775 |
while (en.hasMoreElements()) { |
747 | 776 |
String current = (String) en.nextElement(); |
... | ... | |
754 | 783 |
+ accNumberSeparator + "')-1) = '" + current + "'"); |
755 | 784 |
} |
756 | 785 |
} |
757 |
self.append(") "); |
|
786 |
|
|
787 |
if(!emptyString){ |
|
788 |
self.append(") "); |
|
789 |
} |
|
758 | 790 |
} |
759 | 791 |
|
760 | 792 |
// if there is only one percentage search item, this query is a |
... | ... | |
767 | 799 |
percentageSearch = true; |
768 | 800 |
} |
769 | 801 |
|
770 |
return self.toString(); |
|
802 |
queryString.append(self.toString()); |
|
803 |
return queryString.toString(); |
|
771 | 804 |
} |
772 | 805 |
|
773 | 806 |
/** |
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
406 | 406 |
qspec.setGroup(groups); |
407 | 407 |
// Get access query |
408 | 408 |
String accessQuery = qspec.getAccessQuery(); |
409 |
query = query + accessQuery; |
|
409 |
if(!query.endsWith("WHERE")){ |
|
410 |
query = query + accessQuery; |
|
411 |
} else { |
|
412 |
query = query + accessQuery.substring(4, accessQuery.length()); |
|
413 |
} |
|
410 | 414 |
MetaCatUtil.debugMessage(" final query: " + query, 30); |
411 | 415 |
} |
412 | 416 |
|
src/edu/ucsb/nceas/metacat/QueryGroup.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* '$RCSfile$' |
3 |
* Purpose: A Class that represents a structured query, and can be
|
|
4 |
* constructed from an XML serialization conforming to
|
|
5 |
* pathquery.dtd. The printSQL() method can be used to print
|
|
3 |
* Purpose: A Class that represents a structured query, and can be |
|
4 |
* constructed from an XML serialization conforming to |
|
5 |
* pathquery.dtd. The printSQL() method can be used to print |
|
6 | 6 |
* a SQL serialization of the query. |
7 | 7 |
* Copyright: 2000 Regents of the University of California and the |
8 | 8 |
* National Center for Ecological Analysis and Synthesis |
... | ... | |
43 | 43 |
private String operator = null; // indicates how query terms are combined |
44 | 44 |
private Vector children = null; // the list of query terms and groups |
45 | 45 |
private int countPercentageSearchItem = 0; |
46 |
/**
|
|
47 |
* construct a new QueryGroup
|
|
46 |
/** |
|
47 |
* construct a new QueryGroup |
|
48 | 48 |
* |
49 |
* @param operator the boolean conector used to connect query terms
|
|
49 |
* @param operator the boolean conector used to connect query terms |
|
50 | 50 |
* in this query group |
51 | 51 |
*/ |
52 | 52 |
public QueryGroup(String operator) { |
... | ... | |
54 | 54 |
children = new Vector(); |
55 | 55 |
} |
56 | 56 |
|
57 |
/**
|
|
57 |
/** |
|
58 | 58 |
* Add a child QueryGroup to this QueryGroup |
59 | 59 |
* |
60 | 60 |
* @param qgroup the query group to be added to the list of terms |
61 | 61 |
*/ |
62 | 62 |
public void addChild(QueryGroup qgroup) { |
63 |
children.add((Object)qgroup);
|
|
63 |
children.add((Object)qgroup); |
|
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
/** |
... | ... | |
69 | 69 |
* @param qterm the query term to be added to the list of terms |
70 | 70 |
*/ |
71 | 71 |
public void addChild(QueryTerm qterm) { |
72 |
children.add((Object)qterm);
|
|
72 |
children.add((Object)qterm); |
|
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
/** |
... | ... | |
78 | 78 |
public Enumeration getChildren() { |
79 | 79 |
return children.elements(); |
80 | 80 |
} |
81 |
|
|
81 |
|
|
82 | 82 |
public int getPercentageSymbolCount() |
83 | 83 |
{ |
84 | 84 |
return countPercentageSearchItem; |
85 | 85 |
} |
86 |
|
|
86 |
|
|
87 | 87 |
/** |
88 | 88 |
* create a SQL serialization of the query that this instance represents |
89 | 89 |
*/ |
... | ... | |
109 | 109 |
countPercentageSearchItem = countPercentageSearchItem + count; |
110 | 110 |
} else if (qobject instanceof QueryTerm) { |
111 | 111 |
QueryTerm qt = (QueryTerm)qobject; |
112 |
self.append(qt.printSQL(useXMLIndex)); |
|
112 |
String queryString = qt.printSQL(useXMLIndex); |
|
113 |
if(!(qt.getSearchMode().equals("contains") && qt.getValue().equals("%"))){ |
|
114 |
self.append(queryString); |
|
115 |
} |
|
113 | 116 |
// count percerntage number |
114 | 117 |
int count = qt.getPercentageSymbolCount(); |
115 | 118 |
countPercentageSearchItem = countPercentageSearchItem + count; |
Also available in: Unified diff
Modified code so that when a % search is done, a xml_nodes search is not done. This search is not required and hence saves time in doing a % search