Search in sources :

Example 1 with SearchResults

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

the class SearchServiceImpl method proxySearch.

/**
 * @param userInfo
 * @param searchQuery
 * @return
 * @throws UnsupportedEncodingException
 * @throws ClientProtocolException
 * @throws IOException
 * @throws HttpClientHelperException
 */
public SearchResults proxySearch(UserInfo userInfo, SearchQuery searchQuery) throws UnsupportedEncodingException, ClientProtocolException, IOException, HttpClientHelperException {
    boolean includePath = false;
    if (searchQuery.getReturnFields() != null && searchQuery.getReturnFields().contains(SearchConstants.FIELD_PATH)) {
        includePath = true;
        // We do not want to pass path along to the search index as it is not there.
        searchQuery.getReturnFields().remove(SearchConstants.FIELD_PATH);
    }
    // Create the query string
    String cleanedSearchQuery = createQueryString(userInfo, searchQuery);
    SearchResults results = searchDao.executeSearch(cleanedSearchQuery);
    // Add any extra return results to the hits
    if (results != null && results.getHits() != null) {
        addReturnDataToHits(results.getHits(), includePath);
    }
    return results;
}
Also used : SearchResults(org.sagebionetworks.repo.model.search.SearchResults)

Example 2 with SearchResults

use of org.sagebionetworks.repo.model.search.SearchResults 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 3 with SearchResults

use of org.sagebionetworks.repo.model.search.SearchResults 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 4 with SearchResults

use of org.sagebionetworks.repo.model.search.SearchResults 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 5 with SearchResults

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

the class IT510SynapseJavaClientSearchTest method testMultiWordFreeTextSearch.

/**
 * @throws Exception
 */
@Test
public void testMultiWordFreeTextSearch() throws Exception {
    SearchQuery searchQuery = new SearchQuery();
    List<String> queryTerms = new ArrayList<String>();
    queryTerms.add(distictValue1 + " " + distictValue2);
    searchQuery.setQueryTerm(queryTerms);
    List<String> returnFields = new ArrayList<String>();
    returnFields.add("name");
    searchQuery.setReturnFields(returnFields);
    SearchResults results = synapse.search(searchQuery);
    assertTrue(1 <= results.getFound());
    // try url-escaped space too
    queryTerms = new ArrayList<String>();
    queryTerms.add(distictValue1 + "+" + distictValue2);
    searchQuery.setQueryTerm(queryTerms);
    results = synapse.search(searchQuery);
    assertTrue(1 <= results.getFound());
}
Also used : SearchQuery(org.sagebionetworks.repo.model.search.query.SearchQuery) ArrayList(java.util.ArrayList) SearchResults(org.sagebionetworks.repo.model.search.SearchResults) Test(org.junit.Test)

Aggregations

SearchResults (org.sagebionetworks.repo.model.search.SearchResults)22 Test (org.junit.Test)17 SearchQuery (org.sagebionetworks.repo.model.search.query.SearchQuery)16 ArrayList (java.util.ArrayList)13 KeyValue (org.sagebionetworks.repo.model.search.query.KeyValue)9 Hit (org.sagebionetworks.repo.model.search.Hit)7 Ignore (org.junit.Ignore)3 Document (org.sagebionetworks.repo.model.search.Document)2 DocumentFields (org.sagebionetworks.repo.model.search.DocumentFields)2 HashSet (java.util.HashSet)1 JSONObject (org.json.JSONObject)1 EntityPath (org.sagebionetworks.repo.model.EntityPath)1 UserProfile (org.sagebionetworks.repo.model.UserProfile)1 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)1 JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1