Search in sources :

Example 1 with KeyValue

use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.

the class SearchControllerTest method testSearch.

@Test
public void testSearch() throws Exception {
    // Build a simple query.
    SearchQuery query = new SearchQuery();
    query.setBooleanQuery(new LinkedList<KeyValue>());
    KeyValue kv = new KeyValue();
    kv.setKey(SearchConstants.FIELD_ID);
    kv.setValue(project.getId());
    query.getBooleanQuery().add(kv);
    // the mock request
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("POST");
    request.addHeader("Accept", "application/json");
    request.addHeader("Content-Type", "application/json");
    request.setRequestURI("/search");
    request.setParameter(AuthorizationConstants.USER_ID_PARAM, TestUserDAO.TEST_USER_NAME);
    request.setContent(EntityFactory.createJSONStringForEntity(query).getBytes("UTF-8"));
    DispatchServletSingleton.getInstance().service(request, response);
    if (response.getStatus() != HttpStatus.CREATED.value()) {
        throw new RuntimeException(response.getContentAsString());
    }
    SearchResults results = EntityFactory.createEntityFromJSONString(response.getContentAsString(), SearchResults.class);
    assertNotNull(results);
    assertNotNull(results.getHits());
    assertEquals(1l, results.getHits().size());
    Hit hit = results.getHits().get(0);
    assertNotNull(hit);
    assertEquals(project.getId(), hit.getId());
}
Also used : SearchQuery(org.sagebionetworks.repo.model.search.query.SearchQuery) Hit(org.sagebionetworks.repo.model.search.Hit) KeyValue(org.sagebionetworks.repo.model.search.query.KeyValue) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SearchResults(org.sagebionetworks.repo.model.search.SearchResults) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 2 with KeyValue

use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.

the class IT510SynapseJavaClientSearchTest method testBooleanQuerySearch.

/**
 * @throws Exception
 */
@Test
public void testBooleanQuerySearch() throws Exception {
    SearchQuery searchQuery = new SearchQuery();
    List<String> queryTerms = new ArrayList<String>();
    queryTerms.add(distictValue1);
    searchQuery.setQueryTerm(queryTerms);
    List<String> returnFields = new ArrayList<String>();
    returnFields.add("name");
    searchQuery.setReturnFields(returnFields);
    KeyValue booleanQueryClause = new KeyValue();
    booleanQueryClause.setKey("node_type");
    booleanQueryClause.setValue("data");
    List<KeyValue> booleanQuery = new ArrayList<KeyValue>();
    booleanQuery.add(booleanQueryClause);
    searchQuery.setBooleanQuery(booleanQuery);
    SearchResults results = synapse.search(searchQuery);
    assertTrue(1 <= results.getFound());
}
Also used : SearchQuery(org.sagebionetworks.repo.model.search.query.SearchQuery) KeyValue(org.sagebionetworks.repo.model.search.query.KeyValue) ArrayList(java.util.ArrayList) SearchResults(org.sagebionetworks.repo.model.search.SearchResults) Test(org.junit.Test)

Example 3 with KeyValue

use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.

the class IT510SynapseJavaClientSearchTest method testUpdateACLBooleanQuerySearch.

/**
 * @throws Exception
 */
@Ignore
@Test
public void testUpdateACLBooleanQuerySearch() throws Exception {
    SearchQuery searchQuery = new SearchQuery();
    KeyValue booleanQueryClause = new KeyValue();
    booleanQueryClause.setKey("update_acl");
    booleanQueryClause.setValue("Sage Curators");
    List<KeyValue> booleanQuery = new ArrayList<KeyValue>();
    booleanQuery.add(booleanQueryClause);
    searchQuery.setBooleanQuery(booleanQuery);
    SearchResults results = synapse.search(searchQuery);
    assertTrue(1 <= results.getFound());
}
Also used : SearchQuery(org.sagebionetworks.repo.model.search.query.SearchQuery) KeyValue(org.sagebionetworks.repo.model.search.query.KeyValue) ArrayList(java.util.ArrayList) SearchResults(org.sagebionetworks.repo.model.search.SearchResults) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with KeyValue

use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.

the class IT510SynapseJavaClientSearchTest method testDescription.

/**
 * @throws Exception
 */
@Test
public void testDescription() throws Exception {
    // When descriptions are not null, make sure they are not just an empty
    // json array (this was an old bug)
    SearchQuery searchQuery = new SearchQuery();
    List<String> returnFields = new ArrayList<String>();
    returnFields.add("description");
    searchQuery.setReturnFields(returnFields);
    KeyValue booleanQueryClause = new KeyValue();
    booleanQueryClause.setKey("node_type");
    booleanQueryClause.setValue("*");
    List<KeyValue> booleanQuery = new ArrayList<KeyValue>();
    booleanQuery.add(booleanQueryClause);
    searchQuery.setBooleanQuery(booleanQuery);
    SearchResults results = synapse.search(searchQuery);
    assertTrue(1 <= results.getFound());
    for (Hit hit : results.getHits()) {
        String description = hit.getDescription();
        if (null != description) {
            assertFalse("[]".equals(description));
        }
    }
}
Also used : SearchQuery(org.sagebionetworks.repo.model.search.query.SearchQuery) Hit(org.sagebionetworks.repo.model.search.Hit) KeyValue(org.sagebionetworks.repo.model.search.query.KeyValue) ArrayList(java.util.ArrayList) SearchResults(org.sagebionetworks.repo.model.search.SearchResults) Test(org.junit.Test)

Example 5 with KeyValue

use of org.sagebionetworks.repo.model.search.query.KeyValue in project Synapse-Repository-Services by Sage-Bionetworks.

the class IT510SynapseJavaClientSearchTest method testBadSearch.

@Test
public void testBadSearch() throws ServletException, IOException, JSONException, JSONObjectAdapterException, InterruptedException {
    // First run query
    SearchQuery query = new SearchQuery();
    query.setBooleanQuery(new LinkedList<KeyValue>());
    KeyValue kv = new KeyValue();
    kv.setKey("ugh");
    kv.setValue(project.getId());
    query.getBooleanQuery().add(kv);
    // this should throw an error
    try {
        synapse.search(query);
        fail("This was a bad query");
    } catch (SynapseException e) {
        // did we get the expected message.
        assertTrue(e.getMessage().indexOf("'ugh' is not defined in the metadata for this collection") > 0);
        assertFalse("The error message contains the URL of the search index", e.getMessage().indexOf("http://search") > 0);
    }
}
Also used : SearchQuery(org.sagebionetworks.repo.model.search.query.SearchQuery) KeyValue(org.sagebionetworks.repo.model.search.query.KeyValue) SynapseException(org.sagebionetworks.client.exceptions.SynapseException) Test(org.junit.Test)

Aggregations

KeyValue (org.sagebionetworks.repo.model.search.query.KeyValue)12 SearchQuery (org.sagebionetworks.repo.model.search.query.SearchQuery)11 Test (org.junit.Test)10 SearchResults (org.sagebionetworks.repo.model.search.SearchResults)9 ArrayList (java.util.ArrayList)7 Hit (org.sagebionetworks.repo.model.search.Hit)4 InvalidArgumentException (com.amazonaws.services.cloudfront.model.InvalidArgumentException)2 FacetSort (org.sagebionetworks.repo.model.search.query.FacetSort)2 FacetTopN (org.sagebionetworks.repo.model.search.query.FacetTopN)2 KeyList (org.sagebionetworks.repo.model.search.query.KeyList)2 Ignore (org.junit.Ignore)1 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)1 EntityPath (org.sagebionetworks.repo.model.EntityPath)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1