예제 #1
0
  @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());
  }
예제 #2
0
 /*
  * Makes current cpath2 instance properties
  * available to the JSP views.
  * @return
  */
 @ModelAttribute("cpath")
 public CPathSettings instance() {
   return CPathSettings.getInstance();
 }