use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.
the class ArrayDesignControllerImpl method filter.
@Override
@RequestMapping("/filterArrayDesigns.html")
public ModelAndView filter(HttpServletRequest request, HttpServletResponse response) {
StopWatch overallWatch = new StopWatch();
overallWatch.start();
String filter = request.getParameter("filter");
// Validate the filtering search criteria.
if (StringUtils.isBlank(filter)) {
return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("message", "No search criteria provided");
}
Collection<SearchResult> searchResults = searchService.search(SearchSettingsImpl.arrayDesignSearch(filter)).get(ArrayDesign.class);
if ((searchResults == null) || (searchResults.size() == 0)) {
return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("message", "No search criteria provided");
}
StringBuilder list = new StringBuilder();
if (searchResults.size() == 1) {
ArrayDesign arrayDesign = arrayDesignService.load(searchResults.iterator().next().getId());
return new ModelAndView(new RedirectView("/arrays/showArrayDesign.html?id=" + arrayDesign.getId(), true)).addObject("message", "Matched one : " + arrayDesign.getName() + "(" + arrayDesign.getShortName() + ")");
}
for (SearchResult ad : searchResults) {
list.append(ad.getId()).append(",");
}
overallWatch.stop();
Long overallElapsed = overallWatch.getTime();
log.info("Generating the AD list: (" + list + ") took: " + overallElapsed / 1000 + "s ");
return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html?id=" + list, true)).addObject("message", searchResults.size() + " Platforms matched your search.");
}
use of ubic.gemma.core.search.SearchResult 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;
}
use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.
the class ExpressionExperimentManipulatingCLI method findExpressionExperimentsByQuery.
/**
* Use the search engine to locate expression experiments.
*/
private Set<BioAssaySet> findExpressionExperimentsByQuery(String query) {
Set<BioAssaySet> ees = new HashSet<>();
Collection<SearchResult> eeSearchResults = searchService.search(SearchSettingsImpl.expressionExperimentSearch(query)).get(ExpressionExperiment.class);
AbstractCLI.log.info(ees.size() + " Expression experiments matched '" + query + "'");
// Filter out all the ee that are not of correct taxon
for (SearchResult sr : eeSearchResults) {
ExpressionExperiment ee = (ExpressionExperiment) sr.getResultObject();
Taxon t = eeService.getTaxon(ee);
if (t != null && t.getCommonName().equalsIgnoreCase(taxon.getCommonName())) {
ees.add(ee);
}
}
return ees;
}
use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.
the class GeneralSearchControllerImpl method fillValueObjects.
@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
StopWatch timer = new StopWatch();
timer.start();
Collection<?> vos;
if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
}
} else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
}
} else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
Collection<CompositeSequenceValueObject> css = new ArrayList<>();
for (SearchResult sr : results) {
CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
css.add(csvo);
}
vos = css;
} else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
bss = bibliographicReferenceService.thaw(bss);
vos = bibliographicReferenceService.loadValueObjects(bss);
} else if (Gene.class.isAssignableFrom(entityClass)) {
Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
genes = geneService.thawLite(genes);
vos = geneService.loadValueObjects(genes);
} else if (Characteristic.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
Characteristic ch = (Characteristic) sr.getResultObject();
cvos.add(new CharacteristicValueObject(ch));
}
vos = cvos;
} else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
cvos.add(ch);
}
vos = cvos;
} else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
return;
} else if (GeneSet.class.isAssignableFrom(entityClass)) {
vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
} else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
} else if (FactorValue.class.isAssignableFrom(entityClass)) {
Collection<FactorValueValueObject> fvo = new ArrayList<>();
for (SearchResult sr : results) {
fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
}
vos = fvo;
} else {
throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
}
if (vos == null || vos.isEmpty()) {
// it causing front end errors, if vos is empty make sure to get rid of all search results
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
return;
}
// retained objects...
Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
SearchResult sr = it.next();
if (!idMap.containsKey(sr.getId())) {
it.remove();
continue;
}
sr.setResultObject(idMap.get(sr.getId()));
}
if (timer.getTime() > 1000) {
BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
}
}
use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.
the class ExpressionExperimentServiceImpl method filter.
/**
* returns ids of search results
*
* @return collection of ids or an empty collection
*/
@Override
@Transactional(readOnly = true)
public Collection<Long> filter(String searchString) {
Map<Class<?>, List<SearchResult>> searchResultsMap = searchService.search(SearchSettingsImpl.expressionExperimentSearch(searchString));
assert searchResultsMap != null;
Collection<SearchResult> searchResults = searchResultsMap.get(ExpressionExperiment.class);
Collection<Long> ids = new ArrayList<>(searchResults.size());
for (SearchResult s : searchResults) {
ids.add(s.getId());
}
return ids;
}
Aggregations