Search in sources :

Example 1 with SearchResult

use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.

the class SearchServiceImpl method sortAccessions.

@Override
public List<String> sortAccessions(QueryRequest queryRequest, Set<String> accessions) {
    List<String> sortedAccessions = new ArrayList<String>();
    try {
        String queryString = "id:" + (accessions.size() > 1 ? "(" + Joiner.on(" ").join(accessions) + ")" : accessions.iterator().next());
        queryRequest.setQuery(queryString);
        Query query = queryBuilderService.buildQueryForSearchIndexes("entry", "pl_search", queryRequest);
        SearchResult result = this.solrService.executeQuery(query);
        List<Map<String, Object>> results = result.getResults();
        for (Map<String, Object> res : results) {
            String entry = (String) res.get("id");
            sortedAccessions.add(entry);
        }
    } catch (SearchQueryException e) {
        e.printStackTrace();
        throw new NextProtException("Error when retrieving accessions");
    }
    return sortedAccessions;
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) NextProtException(org.nextprot.api.commons.exception.NextProtException) Query(org.nextprot.api.solr.Query) UserQuery(org.nextprot.api.user.domain.UserQuery) SearchResult(org.nextprot.api.solr.SearchResult)

Example 2 with SearchResult

use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.

the class SolrServiceTest method shouldReturnResultsFromSparqlQuery.

@Test
public void shouldReturnResultsFromSparqlQuery() throws Exception {
    QueryRequest qr = new QueryRequest();
    qr.setMode("advanced");
    qr.setQuality("gold");
    qr.setSparqlEngine("Jena");
    qr.setSparql("#Proteins phosphorylated and located in the cytoplasm\nselect distinct ?entry where {\n  ?entry :isoform ?iso.\n  ?iso :keyword / :term cv:KW-0597.\n  ?iso :cellularComponent /:term /:childOf cv:SL-0086.\n}");
    Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
    SearchResult result = service.executeQuery(q);
    assertTrue(result.getFound() >= 5636);
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 3 with SearchResult

use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.

the class SolrServiceTest method shouldReturnResultsFromSharedProteinList.

@Test
public void shouldReturnResultsFromSharedProteinList() throws Exception {
    QueryRequest qr = new QueryRequest();
    qr.setQuality("gold");
    qr.setListId("Y7JPIEVH");
    qr.setListOwner("Guest");
    Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
    SearchResult result = service.executeQuery(q);
    assertEquals(1, result.getFound());
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 4 with SearchResult

use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.

the class SolrServiceTest method shouldReturnResultsFromSharedQueryList.

@Test
public void shouldReturnResultsFromSharedQueryList() throws Exception {
    QueryRequest qr = new QueryRequest();
    qr.setQuality("gold");
    qr.setMode("advanced");
    qr.setQueryId("3K8W9PJT");
    Query q = queryBuilderService.buildQueryForSearch(qr, "entry");
    SearchResult result = service.executeQuery(q);
    assertTrue(result.getFound() >= 5636);
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 5 with SearchResult

use of org.nextprot.api.solr.SearchResult in project nextprot-api by calipho-sib.

the class SolrServiceTest method shoulReturnSomeEntriesWhenStopWordsAreIncludedInQuery.

@Test
public void shoulReturnSomeEntriesWhenStopWordsAreIncludedInQuery() throws Exception {
    QueryRequest qr;
    Query q;
    SearchResult result;
    long numFound;
    qr = new QueryRequest();
    qr.setQuery("insulin");
    q = queryBuilderService.buildQueryForSearch(qr, "entry");
    result = service.executeQuery(q);
    numFound = result.getFound();
    // we should get some results
    assertTrue(numFound > 0);
    qr = new QueryRequest();
    qr.setQuery("insulin in the of");
    q = queryBuilderService.buildQueryForSearch(qr, "entry");
    result = service.executeQuery(q);
    numFound = result.getFound();
    // we should ALSO get some results
    assertTrue(numFound > 0);
}
Also used : QueryRequest(org.nextprot.api.solr.QueryRequest) Query(org.nextprot.api.solr.Query) SearchResult(org.nextprot.api.solr.SearchResult) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Aggregations

Query (org.nextprot.api.solr.Query)20 SearchResult (org.nextprot.api.solr.SearchResult)20 QueryRequest (org.nextprot.api.solr.QueryRequest)16 Test (org.junit.Test)14 WebUnitBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest)14 NextProtException (org.nextprot.api.commons.exception.NextProtException)4 SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)4 UserQuery (org.nextprot.api.user.domain.UserQuery)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HashSet (java.util.HashSet)2 AutocompleteSearchResult (org.nextprot.api.solr.AutocompleteSearchResult)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)1 Ignore (org.junit.Ignore)1 UserProteinList (org.nextprot.api.user.domain.UserProteinList)1