Search in sources :

Example 1 with SearchSettingsImpl

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

the class SearchServiceImpl method performSearch.

/**
 * Runs inside Compass transaction
 */
private Collection<SearchResult> performSearch(SearchSettings settings, CompassSession session) {
    StopWatch watch = this.startTiming();
    String enhancedQuery = settings.getQuery().trim();
    // noinspection ConstantConditions // Not obvious to me why that would have to be false.
    if (StringUtils.isBlank(enhancedQuery) || enhancedQuery.length() < SearchServiceImpl.MINIMUM_STRING_LENGTH_FOR_FREE_TEXT_SEARCH || enhancedQuery.equals("*"))
        return new ArrayList<>();
    CompassQuery compassQuery = session.queryBuilder().queryString(enhancedQuery).toQuery();
    SearchServiceImpl.log.debug("Parsed query: " + compassQuery);
    CompassHits hits = compassQuery.hits();
    // highlighting.
    if (((SearchSettingsImpl) settings).getDoHighlighting()) {
        if (session instanceof InternalCompassSession) {
            // always ...
            CompassMapping mapping = ((InternalCompassSession) session).getMapping();
            ResourceMapping[] rootMappings = mapping.getRootMappings();
            // should only be one rootMapping.
            this.process(rootMappings, hits);
        }
    }
    watch.stop();
    if (watch.getTime() > 100) {
        SearchServiceImpl.log.info("Getting " + hits.getLength() + " lucene hits for " + enhancedQuery + " took " + watch.getTime() + " ms");
    }
    if (watch.getTime() > 5000) {
        SearchServiceImpl.log.info("*****Extremely long Lucene Index Search!  " + hits.getLength() + " lucene hits for " + enhancedQuery + " took " + watch.getTime() + " ms");
    }
    return this.getSearchResults(hits);
}
Also used : SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) InternalCompassSession(org.compass.core.spi.InternalCompassSession) CompassMapping(org.compass.core.mapping.CompassMapping) ResourceMapping(org.compass.core.mapping.ResourceMapping) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 2 with SearchSettingsImpl

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

the class GeneralSearchControllerImpl method formBackingObject.

/**
 * This is needed or you will have to specify a commandClass in the DispatcherServlet's context
 */
@Override
protected Object formBackingObject(HttpServletRequest request) {
    SearchSettingsImpl searchSettings = new SearchSettingsImpl();
    // Reset default settings.
    searchSettings.noSearches();
    return searchSettings;
}
Also used : SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl)

Example 3 with SearchSettingsImpl

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

the class GeneServiceImpl method loadFullyPopulatedValueObject.

@Override
@Transactional(readOnly = true)
public GeneValueObject loadFullyPopulatedValueObject(Long id) {
    Gene gene = this.geneDao.load(id);
    if (gene == null) {
        return null;
    }
    gene = this.geneDao.thaw(gene);
    GeneValueObject gvo = GeneValueObject.convert2ValueObject(gene);
    Collection<GeneAlias> aliasObjects = gene.getAliases();
    Collection<String> aliasStrings = new ArrayList<>();
    for (GeneAlias ga : aliasObjects) {
        aliasStrings.add(ga.getAlias());
    }
    gvo.setAliases(aliasStrings);
    if (gene.getMultifunctionality() != null) {
        gvo.setMultifunctionalityRank(gene.getMultifunctionality().getRank());
    }
    Long compositeSequenceCount = this.getCompositeSequenceCountById(id);
    gvo.setCompositeSequenceCount(compositeSequenceCount.intValue());
    Integer platformCount = this.geneDao.getPlatformCountById(id);
    gvo.setPlatformCount(platformCount);
    Collection<GeneSet> geneSets = this.geneSetSearch.findByGene(gene);
    Collection<GeneSetValueObject> gsVos = new ArrayList<>();
    // noinspection CollectionAddAllCanBeReplacedWithConstructor // Constructor can't handle subclasses
    gsVos.addAll(geneSetValueObjectHelper.convertToLightValueObjects(geneSets, false));
    gvo.setGeneSets(gsVos);
    Collection<Gene> geneHomologues = this.homologeneService.getHomologues(gene);
    geneHomologues = this.thawLite(geneHomologues);
    Collection<GeneValueObject> homologues = this.loadValueObjects(geneHomologues);
    gvo.setHomologues(homologues);
    Collection<PhenotypeAssociation> pas = gene.getPhenotypeAssociations();
    Collection<CharacteristicValueObject> cVos = new HashSet<>();
    for (PhenotypeAssociation pa : pas) {
        cVos.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(pa.getPhenotypes()));
    }
    gvo.setPhenotypes(cVos);
    if (gvo.getNcbiId() != null) {
        SearchSettingsImpl s = new SearchSettingsImpl();
        s.setTermUri("http://purl.org/commons/record/ncbi_gene/" + gvo.getNcbiId());
        s.noSearches();
        s.setSearchExperiments(true);
        Map<Class<?>, List<SearchResult>> r = searchService.search(s);
        if (r.containsKey(ExpressionExperiment.class)) {
            List<SearchResult> hits = r.get(ExpressionExperiment.class);
            gvo.setAssociatedExperimentCount(hits.size());
        }
    }
    GeneCoexpressionNodeDegreeValueObject nodeDegree = coexpressionService.getNodeDegree(gene);
    if (nodeDegree != null) {
        gvo.setNodeDegreesPos(nodeDegree.asIntArrayPos());
        gvo.setNodeDegreesNeg(nodeDegree.asIntArrayNeg());
        gvo.setNodeDegreePosRanks(nodeDegree.asDoubleArrayPosRanks());
        gvo.setNodeDegreeNegRanks(nodeDegree.asDoubleArrayNegRanks());
    }
    return gvo;
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) Gene(ubic.gemma.model.genome.Gene) SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) SearchResult(ubic.gemma.core.search.SearchResult) GeneCoexpressionNodeDegreeValueObject(ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SearchSettingsImpl

use of ubic.gemma.model.common.search.SearchSettingsImpl 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)

Aggregations

SearchSettingsImpl (ubic.gemma.model.common.search.SearchSettingsImpl)4 StopWatch (org.apache.commons.lang3.time.StopWatch)2 SearchResult (ubic.gemma.core.search.SearchResult)2 CompassMapping (org.compass.core.mapping.CompassMapping)1 ResourceMapping (org.compass.core.mapping.ResourceMapping)1 InternalCompassSession (org.compass.core.spi.InternalCompassSession)1 Transactional (org.springframework.transaction.annotation.Transactional)1 GeneCoexpressionNodeDegreeValueObject (ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject)1 PhenotypeAssociation (ubic.gemma.model.association.phenotype.PhenotypeAssociation)1 SearchSettings (ubic.gemma.model.common.search.SearchSettings)1 Gene (ubic.gemma.model.genome.Gene)1 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)1 JsonReaderResponse (ubic.gemma.web.remote.JsonReaderResponse)1