public GNResultSet(GNXMLQuery query, Object userInfo, Observer[] observers, ServiceContext srvctx) throws Exception { super(observers); this.query = query; this.srvxtx = srvctx; try { GeonetContext gc = (GeonetContext) this.srvxtx.getHandlerContext(Geonet.CONTEXT_NAME); SearchManager searchMan = gc.getBean(SearchManager.class); metasearcher = searchMan.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_Z3950_SERVER); } catch (Exception e) { if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "error constructing GNresult set: " + e); e.printStackTrace(); } }
public int evaluate(int timeout) { try { if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "INCOMING XML QUERY:\n" + query); Element request = new Element("request"); request.addContent(query.toGNXMLRep()); List<String> categories = query.getCollections(); for (String category : categories) { if (!category.equals("geonetwork") && !category.equals("Default")) request.addContent(new Element("category").setText(category)); } ServiceConfig config = new ServiceConfig(); // perform the search and save search results metasearcher.search(this.srvxtx, request, config); // System.out.println("summary:\n" + Xml.getString(s.getSummary())); // // DEBUG // Random number of records.. Set up the result set setFragmentCount(metasearcher.getSize()); setTaskStatusCode(IRResultSetStatus.COMPLETE); this.srvxtx.getResourceManager().close(); } catch (Throwable e) { Log.error(Geonet.Z3950_SERVER, "error evaluating query.." + e); e.printStackTrace(); try { this.srvxtx.getResourceManager().abort(); } catch (Exception e2) { e2.printStackTrace(); } } return (getStatus()); }
public void testStatelessSearch() throws org.jzkit.configuration.api.ConfigurationException, org.jzkit.search.SearchException, org.jzkit.search.util.ResultSet.IRResultSetException, org.jzkit.search.util.QueryModel.InvalidQueryException { Logger log = Logger.getLogger(TestService.class.getName()); log.info("Starting jzkit2 server..."); RecordFormatSpecification request_spec = new ArchetypeRecordFormatSpecification("F"); ExplicitRecordFormatSpecification display_spec = new ExplicitRecordFormatSpecification("text:html:F"); ApplicationContext app_context = new ClassPathXmlApplicationContext("TestApplicationContext.xml"); log.info("JZKit server startup completed"); Vector collection_ids = new Vector(); collection_ids.add("LC/BOOKS"); QueryModel qm = new PrefixString("@attrset bib-1 @attr 1=4 Science"); System.err.println("Processing search......"); try { Map additional_properties = new HashMap(); additional_properties.put("base_dir", "/a/b/c/d"); StatelessQueryService stateless_query_service = (StatelessQueryService) app_context.getBean("StatelessQueryService"); org.jzkit.search.landscape.SimpleLandscapeSpecification landscape = new org.jzkit.search.landscape.SimpleLandscapeSpecification(collection_ids); // Test 1 - Kick off a search StatelessSearchResultsPageDTO rp = stateless_query_service.getResultsPageFor( null, qm, landscape, 1, 5, request_spec, display_spec, additional_properties); if (rp != null) { System.err.println( "Result Set Size....." + rp.total_hit_count + " records - result contains " + rp.number_of_records + " records"); System.err.println("Result Set ID : " + rp.result_set_id); } else { System.err.println("Results page was null"); } if (rp.records != null) { for (int i = 0; ((i < rp.records.length) && (i < 25)); i++) { System.err.println( "Getting next record (" + i + " out of " + rp.number_of_records + ")....."); InformationFragment frag = rp.records[i]; System.err.println(frag); } } // Test 2 - use the result set ID to get a page of requests rp = stateless_query_service.getResultsPageFor( rp.result_set_id, qm, landscape, 6, 5, request_spec, display_spec, additional_properties); if (rp.records != null) { for (int i = 0; ((i < rp.records.length) && (i < 25)); i++) { System.err.println( "Getting next record (" + i + " out of " + rp.number_of_records + ")....."); InformationFragment frag = rp.records[i]; System.err.println(frag); } } // Test 3 - Use the query to get a cache hit rp = stateless_query_service.getResultsPageFor( null, qm, landscape, 6, 5, request_spec, display_spec, additional_properties); if (rp.records != null) { for (int i = 0; ((i < rp.records.length) && (i < 25)); i++) { System.err.println( "Getting next record (" + i + " out of " + rp.number_of_records + ")....."); InformationFragment frag = rp.records[i]; System.err.println(frag); } } } catch (Exception e) { e.printStackTrace(); } }
public InformationFragment[] getFragment( int startingFragment, int count, RecordFormatSpecification spec) throws IRResultSetException { if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug( Geonet.Z3950_SERVER, "Request for fragment start:" + startingFragment + ", count:" + count); InformationFragment fragment[] = new InformationFragment[count]; ExplicitRecordFormatSpecification rec_spec = new ExplicitRecordFormatSpecification("xml", null, "f"); try { // build fragment data int from = startingFragment; int to = startingFragment + count - 1; Element request = new Element("request"); request.addContent(new Element("from").setText(from + "")); request.addContent(new Element("to").setText(to + "")); ServiceConfig config = new ServiceConfig(); if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "Search request:\n" + Xml.getString(request)); // get result set Element result = this.metasearcher.present(this.srvxtx, request, config); if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "Search result:\n" + Xml.getString(result)); // remove summary result.removeChildren("summary"); @SuppressWarnings("unchecked") List<Element> list = result.getChildren(); if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "Set name asked:" + spec); // save other records to fragment for (int i = 0; i < count; i++) { Element md = list.get(0); md.detach(); if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "Returning fragment:\n" + Xml.getString(md)); // add metadata // fragment[i] = new DOMTree("geonetwork", "geonetwork", null, getRecord(md),rec_spec ); // fragment[i].setHitNo(startingFragment+i); DOMOutputter outputter = new DOMOutputter(); Document doc = new Document(md); org.w3c.dom.Document doc2 = outputter.output(doc); fragment[i] = new InformationFragmentImpl( startingFragment + i, "geonetwork", "geonetwork", null, doc2, rec_spec); // fragment[i] = new // InformationFragmentImpl(startingFragment+i,"geonetwork","geonetwork",null,doc,rec_spec); // System.err.println(fragment[i]); } this.srvxtx.getResourceManager().close(); if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "Fragment returned"); } catch (Throwable e) { try { this.srvxtx.getResourceManager().abort(); } catch (Exception e2) { e2.printStackTrace(); } if (Log.isDebugEnabled(Geonet.Z3950_SERVER)) Log.debug(Geonet.Z3950_SERVER, "Exception: " + e.getClass().getName() + " " + e); // e.printStackTrace(); } return fragment; }