Search in sources :

Example 16 with SearchSettings

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

the class SearchServiceTest method testSearchByBibRefIdProblems.

@Test
public void testSearchByBibRefIdProblems() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
    BibliographicReference bibref = fetcher.retrieveByHTTP(9600966);
    bibref = (BibliographicReference) persisterHelper.persist(bibref);
    assertTrue(bibref.getAbstractText().contains("ase proved to be a de novo mutation. In the third kindred, affected brothers both have a"));
    IndexerTaskCommand c = new IndexerTaskCommand();
    c.setIndexBibRef(true);
    indexerTask.setTaskCommand(c);
    indexerTask.execute();
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.noSearches();
    settings.setQuery("de novo mutation");
    settings.setSearchBibrefs(true);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(BibliographicReference.class)) {
        if (sr.getResultObject().equals(bibref)) {
            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 17 with SearchSettings

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

the class BibliographicReferenceServiceImpl method search.

@Override
@Transactional(readOnly = true)
public List<BibliographicReferenceValueObject> search(SearchSettingsValueObject settings) {
    SearchSettings ss = SearchSettingsImpl.bibliographicReferenceSearch(settings.getQuery());
    // noinspection unchecked
    List<BibliographicReference> resultEntities = (List<BibliographicReference>) searchService.search(ss, BibliographicReference.class);
    List<BibliographicReferenceValueObject> results = new ArrayList<>();
    // only return associations with the selected entity types.
    for (BibliographicReference entity : resultEntities) {
        BibliographicReferenceValueObject vo = new BibliographicReferenceValueObject(entity);
        if (settings.getSearchPhenotypes() || settings.getSearchBibrefs()) {
            this.populateBibliographicPhenotypes(vo);
            if (!vo.getBibliographicPhenotypes().isEmpty() || settings.getSearchBibrefs()) {
                results.add(vo);
            }
        }
        if (settings.getSearchExperiments() || settings.getSearchBibrefs()) {
            this.populateRelatedExperiments(entity, vo);
            if (!vo.getExperiments().isEmpty() || settings.getSearchBibrefs()) {
                results.add(vo);
            }
        }
        if (settings.getSearchBibrefs() && !settings.getSearchPhenotypes() && !settings.getSearchExperiments()) {
            results.add(vo);
        }
    }
    return results;
}
Also used : SearchSettings(ubic.gemma.model.common.search.SearchSettings) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings 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 19 with SearchSettings

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

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