Search in sources :

Example 11 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class GeneCoreServiceImpl method searchGenes.

/**
 * Search for genes (by name or symbol)
 *
 * @param taxonId, can be null to not constrain by taxon
 * @return Collection of Gene entity objects
 */
@Override
public Collection<GeneValueObject> searchGenes(String query, Long taxonId) {
    Taxon taxon = null;
    if (taxonId != null) {
        taxon = this.taxonService.load(taxonId);
    }
    SearchSettings settings = SearchSettingsImpl.geneSearch(query, taxon);
    List<SearchResult> geneSearchResults = this.searchService.search(settings).get(Gene.class);
    Collection<Gene> genes = new HashSet<>();
    if (geneSearchResults == null || geneSearchResults.isEmpty()) {
        GeneCoreServiceImpl.log.info("No Genes for search: " + query + " taxon=" + taxonId);
        return new HashSet<>();
    }
    GeneCoreServiceImpl.log.info("Gene search: " + query + " taxon=" + taxonId + ", " + geneSearchResults.size() + " found");
    for (SearchResult sr : geneSearchResults) {
        Gene g = (Gene) sr.getResultObject();
        g = geneService.thaw(g);
        genes.add(g);
        GeneCoreServiceImpl.log.debug("Gene search result: " + g.getOfficialSymbol());
    }
    Collection<GeneValueObject> geneValueObjects = geneService.loadValueObjects(genes);
    GeneCoreServiceImpl.log.debug("Gene search: " + geneValueObjects.size() + " value objects returned.");
    return geneValueObjects;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) 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) HashSet(java.util.HashSet)

Example 12 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class OntologyServiceImpl method searchForGenes.

/**
 * Look for genes, but only for certain category Uris (genotype, etc.)
 *
 * @param taxon         okay if null, but then all matches returned.
 * @param searchResults added to this
 */
private void searchForGenes(String queryString, Taxon taxon, Collection<CharacteristicValueObject> searchResults) {
    SearchSettings ss = SearchSettings.Factory.newInstance();
    ss.setQuery(queryString);
    ss.noSearches();
    ss.setTaxon(taxon);
    ss.setSearchGenes(true);
    Map<Class<?>, List<SearchResult>> geneResults = this.searchService.search(ss, true, false);
    if (geneResults.containsKey(Gene.class)) {
        for (SearchResult sr : geneResults.get(Gene.class)) {
            Gene g = (Gene) sr.getResultObject();
            if (OntologyServiceImpl.log.isDebugEnabled())
                OntologyServiceImpl.log.debug("Search for " + queryString + " returned: " + g);
            searchResults.add(new CharacteristicValueObject(this.gene2Characteristic(g)));
        }
    }
}
Also used : Gene(ubic.gemma.model.genome.Gene) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult)

Example 13 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class ExpressionExperimentSearchServiceImpl method getExpressionExperimentResults.

private List<SearchResultDisplayObject> getExpressionExperimentResults(Map<Class<?>, List<SearchResult>> results) {
    // get all expressionExperiment results and convert result object into a value object
    List<SearchResult> srEEs = results.get(ExpressionExperiment.class);
    if (srEEs == null) {
        srEEs = new ArrayList<>();
    }
    List<Long> eeIds = new ArrayList<>();
    for (SearchResult sr : srEEs) {
        eeIds.add(sr.getId());
    }
    Collection<ExpressionExperimentValueObject> eevos = expressionExperimentService.loadValueObjects(eeIds, true);
    List<SearchResultDisplayObject> experiments = new ArrayList<>();
    for (ExpressionExperimentValueObject eevo : eevos) {
        experiments.add(new SearchResultDisplayObject(eevo));
    }
    return experiments;
}
Also used : ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) SearchResult(ubic.gemma.core.search.SearchResult) SearchResultDisplayObject(ubic.gemma.core.search.SearchResultDisplayObject)

Example 14 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class GeneralSearchControllerImpl method ajaxSearch.

@Override
public JsonReaderResponse<SearchResult> ajaxSearch(SearchSettingsValueObject settingsValueObject) {
    SearchSettings settings = SearchSettingsValueObject.toEntity(settingsValueObject);
    List<SearchResult> finalResults = new ArrayList<>();
    if (settings == null || StringUtils.isBlank(settings.getQuery()) || StringUtils.isBlank(settings.getQuery().replaceAll("\\*", ""))) {
        // FIXME validate input better, and return error.
        BaseFormController.log.info("No query or invalid.");
        // return new ListRange( finalResults );
        throw new IllegalArgumentException("Query '" + settings + "' was invalid");
    }
    StopWatch watch = new StopWatch();
    watch.start();
    ((SearchSettingsImpl) settings).setDoHighlighting(true);
    Map<Class<?>, List<SearchResult>> searchResults = searchService.search(settings);
    watch.stop();
    if (watch.getTime() > 500) {
        BaseFormController.log.info("Search service work on: " + settings + " took " + watch.getTime() + " ms");
    }
    /*
         * FIXME sort by the number of hits per class, so smallest number of hits is at the top.
         */
    watch.reset();
    watch.start();
    if (searchResults != null) {
        for (Class<?> clazz : searchResults.keySet()) {
            List<SearchResult> results = searchResults.get(clazz);
            if (results.size() == 0)
                continue;
            BaseFormController.log.info("Search for: " + settings + "; result: " + results.size() + " " + clazz.getSimpleName() + "s");
            /*
                 * Now put the valueObjects inside the SearchResults in score order.
                 */
            Collections.sort(results);
            this.fillValueObjects(clazz, results, settings);
            finalResults.addAll(results);
        }
    }
    if (watch.getTime() > 500) {
        BaseFormController.log.info("Final unpacking of results for query:" + settings + " took " + watch.getTime() + " ms");
    }
    return new JsonReaderResponse<>(finalResults);
}
Also used : SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 15 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class CompositeSequenceController method search.

public Collection<CompositeSequenceMapValueObject> search(String searchString, String arrayDesignId) {
    if (StringUtils.isBlank(searchString)) {
        return new HashSet<>();
    }
    /*
         * There have to be a few ways of searching: - by ID, by bioSequence, by Gene name. An array design may or may
         * not be given.
         */
    ArrayDesign arrayDesign = loadArrayDesign(arrayDesignId);
    Map<Class<?>, List<SearchResult>> search = searchService.search(SearchSettingsImpl.compositeSequenceSearch(searchString, arrayDesign));
    Collection<CompositeSequence> css = new HashSet<>();
    if (search.containsKey(CompositeSequence.class)) {
        Collection<SearchResult> searchResults = search.get(CompositeSequence.class);
        for (SearchResult sr : searchResults) {
            CompositeSequence cs = (CompositeSequence) sr.getResultObject();
            if (arrayDesign == null || cs.getArrayDesign().equals(arrayDesign)) {
                css.add(cs);
            }
        }
    }
    return getSummaries(css);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) SearchResult(ubic.gemma.core.search.SearchResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Aggregations

SearchResult (ubic.gemma.core.search.SearchResult)15 SearchSettings (ubic.gemma.model.common.search.SearchSettings)7 Gene (ubic.gemma.model.genome.Gene)7 Taxon (ubic.gemma.model.genome.Taxon)5 StopWatch (org.apache.commons.lang3.time.StopWatch)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)3 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)3 HashSet (java.util.HashSet)2 SearchResultDisplayObject (ubic.gemma.core.search.SearchResultDisplayObject)2 SearchSettingsImpl (ubic.gemma.model.common.search.SearchSettingsImpl)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)1 GeneCoexpressionNodeDegreeValueObject (ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject)1 PhenotypeAssociation (ubic.gemma.model.association.phenotype.PhenotypeAssociation)1 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1