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;
}
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)));
}
}
}
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;
}
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);
}
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);
}
Aggregations