private void searchForTypesUsed( SearchEngine engine, IJavaElement parent, IType[] types, IJavaSearchScope scope) throws CoreException { for (int i = 0; i < types.length; i++) { if (types[i].isAnonymous()) continue; TypeReferenceSearchRequestor requestor = new TypeReferenceSearchRequestor(); engine.search( SearchPattern.createPattern(types[i], IJavaSearchConstants.REFERENCES), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, scope, requestor, null); if (requestor.containMatches()) { TypeDeclarationSearchRequestor decRequestor = new TypeDeclarationSearchRequestor(); engine.search( SearchPattern.createPattern(types[i], IJavaSearchConstants.DECLARATIONS), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, SearchEngine.createJavaSearchScope(new IJavaElement[] {parent}), decRequestor, null); Match match = decRequestor.getMatch(); if (match != null) fSearchResult.addMatch(match); } } }
@Override public void run() { try { SearchEngine.Result result = engine.search(query, page); if (run) { h.post(new ResultRunnable(result, requestId)); } } catch (Exception e) { e.printStackTrace(); h.post( new Runnable() { @Override public void run() { Toast.makeText(getActivity(), "Network Error", Toast.LENGTH_SHORT).show(); } }); } }
@Test public final void testSearch() throws IOException { SimpleIOHandler reader = new SimpleIOHandler(); Model model = reader.convertFromOWL( resourceLoader.getResource("classpath:merge/pathwaydata1.owl").getInputStream()); SearchEngine searchEngine = new SearchEngine(model, indexLocation); searchEngine.index(); assertTrue(new File(indexLocation).exists()); SearchResponse response = searchEngine.search("ATP", 0, null, null, null); assertNotNull(response); assertFalse(response.isEmpty()); assertEquals(7, response.getSearchHit().size()); assertEquals(7, response.getNumHits().intValue()); CPathSettings.getInstance().setDebugEnabled(false); response = searchEngine.search("ATP", 0, Interaction.class, null, null); assertNotNull(response); assertFalse(response.isEmpty()); assertEquals(2, response.getSearchHit().size()); // if cPath2 debugging is disabled, - no score/explain in the excerpt assertFalse(response.getSearchHit().get(0).getExcerpt().contains("-SCORE-")); // enable cPath2 debugging... CPathSettings.getInstance().setDebugEnabled(true); response = searchEngine.search("ATP", 0, Pathway.class, null, null); assertNotNull(response); assertFalse(response.isEmpty()); assertEquals(1, response.getSearchHit().size()); SearchHit hit = response.getSearchHit().get(0); assertEquals(4, hit.getSize().intValue()); // no. member processes, not counting the hit itself assertTrue(hit.getExcerpt().contains("-SCORE-")); CPathSettings.getInstance().setDebugEnabled(false); // test a special implementation for wildcard queries response = searchEngine.search("*", 0, Pathway.class, null, null); assertNotNull(response); assertFalse(response.isEmpty()); assertEquals(1, response.getSearchHit().size()); // find all objects (this here works with page=0 as long as the // total no. objects in the test model < max hits per page) response = searchEngine.search("*", 0, null, null, null); assertEquals(50, response.getSearchHit().size()); response = searchEngine.search("*", 0, PhysicalEntity.class, null, null); assertEquals(8, response.getSearchHit().size()); response = searchEngine.search("*", 0, PhysicalEntity.class, null, new String[] {"562"}); assertEquals(2, response.getSearchHit().size()); response = searchEngine.search("*", 0, PhysicalEntity.class, null, new String[] {"Escherichia"}); assertFalse(response.isEmpty()); assertEquals(2, response.getSearchHit().size()); response = searchEngine.search("*", 0, PhysicalEntity.class, null, new String[] {"Escherichia coliü"}); assertFalse(response.isEmpty()); assertEquals(2, response.getSearchHit().size()); response = searchEngine.search("*", 0, Provenance.class, null, null); assertEquals(2, response.getSearchHit().size()); response = searchEngine.search("*", 0, Provenance.class, new String[] {"kegg"}, null); assertEquals(1, response.getSearchHit().size()); // datasource filter using a URI (required for -update-counts console command and // datasources.html page to work) response = searchEngine.search( "*", 0, Pathway.class, new String[] {"http://identifiers.org/kegg.pathway/"}, null); assertFalse(response.isEmpty()); assertEquals(1, response.getSearchHit().size()); response = searchEngine.search("pathway:glycolysis", 0, SmallMoleculeReference.class, null, null); assertEquals(5, response.getSearchHit().size()); // test search with pagination searchEngine.setMaxHitsPerPage(10); response = searchEngine.search("*", 0, null, null, null); assertEquals(0, response.getPageNo().intValue()); assertEquals(50, response.getNumHits().intValue()); assertEquals(10, response.getSearchHit().size()); response = searchEngine.search("*", 1, null, null, null); assertEquals(10, response.getSearchHit().size()); assertEquals(1, response.getPageNo().intValue()); }