Search in sources :

Example 1 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class SearchServiceImpl method searchForNewlyCreatedUserQueryResults.

@Override
public Map<Class<?>, List<SearchResult>> searchForNewlyCreatedUserQueryResults(UserQuery query) {
    Map<Class<?>, List<SearchResult>> searchResults;
    Map<Class<?>, List<SearchResult>> finalResults = new HashMap<>();
    SearchSettings settings = query.getSearchSettings();
    if (StringUtils.isBlank(settings.getTermUri()) && !settings.getQuery().startsWith("http://")) {
        // fill objects=true, speedySearch=false
        searchResults = this.generalSearch(settings, true, false);
    } else {
        // we only attempt an ontology search if the uri looks remotely like a url.
        searchResults = this.ontologyUriSearch(settings);
    }
    if (searchResults == null) {
        return finalResults;
    }
    for (Class<?> clazz : searchResults.keySet()) {
        List<SearchResult> results = searchResults.get(clazz);
        List<SearchResult> updatedResults = new ArrayList<>();
        if (results.size() == 0)
            continue;
        SearchServiceImpl.log.info("Search for newly createdQuery with settings: " + settings + "; result: " + results.size() + " " + clazz.getSimpleName() + "s");
        for (SearchResult sr : results) {
            // Are SearchResults always auditable? maybe put in some error handling in case they are not or
            // enforce searchSettings object to be of a certain form
            Auditable auditableResult = (Auditable) sr.getResultObject();
            // this list is ordered by date (not descending)
            List<AuditEvent> eventList = auditTrailService.getEvents(auditableResult);
            if (eventList == null || eventList.isEmpty())
                continue;
            for (AuditEvent ae : eventList) {
                // assuming there is only one create event
                if (ae.getAction() == AuditAction.CREATE && ae.getDate().after(query.getLastUsed())) {
                    updatedResults.add(sr);
                    break;
                }
            }
        }
        if (!updatedResults.isEmpty()) {
            finalResults.put(clazz, updatedResults);
        }
    }
    return finalResults;
}
Also used : Auditable(ubic.gemma.model.common.Auditable) SearchSettings(ubic.gemma.model.common.search.SearchSettings) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 2 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class SearchServiceTest method testURISearch.

/**
 * Does the search engine correctly match the spinal cord URI and find objects directly tagged with that URI
 */
@Test
public void testURISearch() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.setQuery(SearchServiceTest.SPINAL_CORD);
    settings.setSearchExperiments(true);
    settings.setUseDatabase(false);
    settings.setUseIndices(false);
    settings.setUseCharacteristics(true);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(ExpressionExperiment.class)) {
        if (sr.getResultObject().equals(ee)) {
            this.tearDown();
            return;
        }
    }
    this.tearDown();
    fail("Didn't get expected result from search");
}
Also used : SearchSettings(ubic.gemma.model.common.search.SearchSettings) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 3 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class SearchServiceTest method testGeneralSearch4Brain.

/**
 * Tests that general search terms are resolved to their proper ontology terms and objects tagged with those terms
 * are found, -- requires LARQ index.
 */
@Test
public void testGeneralSearch4Brain() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.noSearches();
    // should hit 'cavity of brain'.
    settings.setQuery("Brain");
    settings.setSearchExperiments(true);
    settings.setUseCharacteristics(true);
    settings.setUseDatabase(false);
    settings.setUseIndices(false);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(ExpressionExperiment.class)) {
        if (sr.getResultObject().equals(ee)) {
            this.tearDown();
            return;
        }
    }
    this.tearDown();
    fail("Didn't get expected result from search");
}
Also used : SearchSettings(ubic.gemma.model.common.search.SearchSettings) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 4 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class SearchServiceTest method testSearchByBibRefId.

@Test
public void testSearchByBibRefId() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    String id;
    if (ee.getPrimaryPublication() == null) {
        PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
        BibliographicReference bibref = fetcher.retrieveByHTTP(21878914);
        bibref = (BibliographicReference) persisterHelper.persist(bibref);
        ee.setPrimaryPublication(bibref);
        eeService.update(ee);
        id = "21878914";
    } else {
        id = ee.getPrimaryPublication().getPubAccession().getAccession();
    }
    log.info("indexing ...");
    IndexerTaskCommand c = new IndexerTaskCommand();
    c.setIndexBibRef(true);
    indexerTask.setTaskCommand(c);
    indexerTask.execute();
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.noSearches();
    settings.setQuery(id);
    settings.setSearchExperiments(true);
    settings.setUseCharacteristics(false);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(ExpressionExperiment.class)) {
        if (sr.getResultObject().equals(ee)) {
            this.tearDown();
            return;
        }
    }
    this.tearDown();
    fail("Didn't get expected result from search");
}
Also used : IndexerTaskCommand(ubic.gemma.core.tasks.maintenance.IndexerTaskCommand) SearchSettings(ubic.gemma.model.common.search.SearchSettings) PubMedXMLFetcher(ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 5 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class PhenotypeAssociationManagerServiceImpl method findGenesWithEvidence.

@Override
@Transactional(readOnly = true)
public Collection<GeneEvidenceValueObject> findGenesWithEvidence(String query, Long taxonId) {
    if (query == null || query.length() == 0) {
        throw new IllegalArgumentException("No search query provided");
    }
    // make sure it does an inexact search
    String newQuery = query + "%";
    Taxon taxon = null;
    if (taxonId != null) {
        taxon = this.taxonService.load(taxonId);
    }
    SearchSettings settings = SearchSettingsImpl.geneSearch(newQuery, taxon);
    List<SearchResult> geneSearchResults = this.searchService.search(settings).get(Gene.class);
    Collection<Gene> genes = new HashSet<>();
    if (geneSearchResults == null || geneSearchResults.isEmpty()) {
        return new HashSet<>();
    }
    for (SearchResult sr : geneSearchResults) {
        genes.add((Gene) sr.getResultObject());
    }
    Collection<GeneEvidenceValueObject> geneEvidenceValueObjects = new HashSet<>();
    for (Gene g : genes) {
        GeneEvidenceValueObject geneEvidenceValueObject = new GeneEvidenceValueObject(g, this.convert2ValueObjects(g.getPhenotypeAssociations()));
        geneEvidenceValueObjects.add(geneEvidenceValueObject);
    }
    Collection<GeneEvidenceValueObject> geneValueObjectsFilter = new ArrayList<>();
    for (GeneEvidenceValueObject gene : geneEvidenceValueObjects) {
        if (gene.getEvidence() != null && gene.getEvidence().size() != 0) {
            geneValueObjectsFilter.add(gene);
        }
    }
    return geneValueObjectsFilter;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SearchSettings (ubic.gemma.model.common.search.SearchSettings)19 Test (org.junit.Test)7 SearchResult (ubic.gemma.core.search.SearchResult)7 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)7 Gene (ubic.gemma.model.genome.Gene)5 Taxon (ubic.gemma.model.genome.Taxon)5 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)4 PubMedXMLFetcher (ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher)3 IndexerTaskCommand (ubic.gemma.core.tasks.maintenance.IndexerTaskCommand)3 Transactional (org.springframework.transaction.annotation.Transactional)2 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 SearchResultDisplayObject (ubic.gemma.core.search.SearchResultDisplayObject)1 Auditable (ubic.gemma.model.common.Auditable)1 AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)1 BibliographicReferenceValueObject (ubic.gemma.model.common.description.BibliographicReferenceValueObject)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1