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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations