Changeset 1565
- Timestamp:
- 09/10/06 16:45:10 (14 years ago)
- Location:
- TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/DiscoveryServiceSkeleton.java
r1558 r1565 34 34 agent.setStart( requestContent.getStart() ); 35 35 } 36 else37 {38 agent.setStart( 1 );39 }40 36 41 37 if ( requestContent.isSetHowMany() ) … … 43 39 agent.setHowMany( requestContent.getHowMany() ); 44 40 } 45 else 46 { 47 agent.setHowMany( 30 ); 48 } 41 49 42 if ( requestContent.isSetOrderBy() ) 50 43 { 51 44 agent.setOrderBy( requestContent.getOrderBy().toString() ); 52 }53 else54 {55 agent.setOrderBy( "date" );56 45 } 57 46 -
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/FullTextSearchAgent.java
r1554 r1565 8 8 import java.io.BufferedReader; 9 9 import java.io.InputStreamReader; 10 import java.io.ByteArrayInputStream; 10 11 import java.io.IOException; 12 13 import javax.xml.xpath.*; 14 import javax.xml.*; 15 import javax.xml.namespace.*; 16 import org.xml.sax.InputSource; 17 import org.w3c.dom.*; 11 18 12 19 import org.apache.xmlrpc.XmlRpc; … … 57 64 public SearchSummary doSearch() { 58 65 59 SearchSummary result = n ull;66 SearchSummary result = new SearchSummary(); 60 67 XmlRpc.setEncoding("UTF-8"); 61 68 Vector myResultDocuments = new Vector(); … … 78 85 79 86 80 Hashtable options = new Hashtable();81 options.put("indent", "yes");82 options.put("encoding", "UTF-8");83 options.put("process-xsl-pi", "no");84 85 87 //1. Execute the search 86 Vector executeQueryParams = new Vector();88 Vector queryParams = new Vector(); 87 89 88 90 // Load fullText XQuery from a file … … 104 106 else 105 107 { 106 xqueryStr += line ;108 xqueryStr += line + "\n"; 107 109 } 108 110 } … … 111 113 // Substitute __term__ in the xquery for value from request message 112 114 xqueryStr = xqueryStr.replaceAll("__term__", term); 113 executeQueryParams.addElement( xqueryStr ); 114 executeQueryParams.addElement( options ); 115 resultId = ((Integer)xmlrpc.execute( "executeQuery", executeQueryParams )).intValue(); 115 //xqueryStr = xqueryStr.replaceAll("__orderBy__", orderBy); 116 116 117 //2. Fetch the querySummary 118 Vector querySummaryParams = new Vector(); 119 querySummaryParams.addElement( resultId ); //resultId from last query 120 Hashtable querySummaryHashtable = (Hashtable)xmlrpc.execute( "querySummary", querySummaryParams ); 121 result = new SearchSummary( querySummaryHashtable, resultId ); 117 queryParams.addElement( xqueryStr.getBytes("UTF-8") ); 122 118 123 //3. Do a releaseQueryResult 124 Vector releaseQueryResultParams = new Vector(); 125 releaseQueryResultParams.addElement( resultId ); //resultId from last query 126 xmlrpc.execute( "releaseQueryResult", releaseQueryResultParams ); 119 queryParams.addElement( this.howMany ); 120 queryParams.addElement( this.start ); 121 122 Hashtable options = new Hashtable(); 123 options.put("indent", "yes"); 124 options.put("encoding", "UTF-8"); 125 options.put("process-xsl-pi", "no"); 126 queryParams.addElement( options ); 127 byte[] resultByteArray = (byte[])xmlrpc.execute( "query", queryParams ); 128 ByteArrayInputStream resultStream = new ByteArrayInputStream( resultByteArray ); 129 130 // Mark the beginning of the Stream, so can reset before each xpath evaluation (!) 131 resultStream.mark( resultStream.available() ); 132 InputSource resultSource = new InputSource( resultStream ); 133 134 XPath xpath = XPathFactory.newInstance().newXPath(); 135 String hitsExpr = "/exist:result/@hits"; 136 String documentExpr = "//exist:result/document"; 137 xpath.setNamespaceContext( new existNamespaceContextImpl() ); 138 139 result.setHits( (new Integer( xpath.evaluate(hitsExpr, resultSource) )).intValue() ); 140 141 resultStream.reset(); 142 NodeList nodeList = (NodeList)xpath.evaluate( documentExpr, resultSource, XPathConstants.NODESET ); 143 Vector documents = new Vector(); 144 for (int i=0; i<nodeList.getLength(); i++) 145 { 146 Hashtable thisDoc = new Hashtable(); 147 thisDoc.put("name", nodeList.item(i).getFirstChild().getNodeValue() ); 148 thisDoc.put("matches", 1); 149 thisDoc.put("position", i); 150 documents.add( thisDoc ); 151 } 152 result.setDocuments( documents ); 153 result.setStatus( true ); 154 127 155 } 128 156 catch (org.apache.xmlrpc.XmlRpcException e) … … 144 172 } 145 173 174 public class existNamespaceContextImpl implements NamespaceContext 175 { 176 public String getNamespaceURI(String prefix) 177 { 178 return "http://exist.sourceforge.net/NS/exist"; 179 } 180 181 // Doesn't matter what the prefix in the source doc is, override it 182 // Important thing is that the namespace URI matches, and that 183 // whatever prefix is set here, is used in the xpath query 184 public String getPrefix(String namespace) 185 { 186 return "exist"; 187 } 188 189 public Iterator getPrefixes(String namespace) 190 { 191 return null; 192 } 193 } 194 146 195 // setter methods for start, howMany, OrderBy already defined in superclass SearchAgent 147 196 -
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/SearchAgent.java
r1554 r1565 28 28 String orderBy; 29 29 30 public static final int startDefault = 1; 31 public static final int howManyDefault = 30; 32 30 33 // Output parameters 31 34 boolean status; … … 40 43 41 44 /** 42 * Sets the start position of result set 45 * Sets the start position of result set. 46 * <p>Value should be integer > 0, else defaults to howManyDefault. 43 47 * @param i position of first result to fetch 44 48 */ 45 49 public void setStart(int i) 46 50 { 47 this.start = i; 51 if ( i > 0) 52 { 53 this.start = i; 54 } 55 else 56 { 57 this.start = this.startDefault; 58 } 48 59 } 49 60 50 61 /** 51 * Sets how many results to fetch 62 * Sets how many results to fetch. 63 * <p>Value should be integer > 0, else defaults to howManyDefault. 52 64 * @param i position of first result to fetch 53 65 */ 54 66 public void setHowMany(int i) 55 67 { 56 this.howMany = i; 68 if ( i > 0) 69 { 70 this.howMany = i; 71 } 72 else 73 { 74 this.howMany = this.howManyDefault; 75 } 57 76 } 58 77 … … 63 82 public void setOrderBy(String s) 64 83 { 65 this.orderBy = s; 84 if ( s.equals("date") ) 85 { 86 this.orderBy = " order by $i//DIF_Creation_Date"; 87 } 88 else if ( s.equals("dataCentre") ) 89 { 90 this.orderBy = "order by $i//Data_Center/Data_Center_Name/Short_Name"; 91 } 92 else 93 { 94 this.orderBy = "order by document-uri($i)"; 95 } 66 96 } 67 97 }
Note: See TracChangeset
for help on using the changeset viewer.