use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.
the class SearchServiceImpl method searchForNewlyCreatedUserQueryResults.
@Override
public Map<Class<?>, List<SearchResult>> searchForNewlyCreatedUserQueryResults(UserQuery query) {
Map<Class<?>, List<SearchResult>> searchResults;
Map<Class<?>, List<SearchResult>> finalResults = new HashMap<>();
SearchSettings settings = query.getSearchSettings();
if (StringUtils.isBlank(settings.getTermUri()) && !settings.getQuery().startsWith("http://")) {
// fill objects=true, speedySearch=false
searchResults = this.generalSearch(settings, true, false);
} else {
// we only attempt an ontology search if the uri looks remotely like a url.
searchResults = this.ontologyUriSearch(settings);
}
if (searchResults == null) {
return finalResults;
}
for (Class<?> clazz : searchResults.keySet()) {
List<SearchResult> results = searchResults.get(clazz);
List<SearchResult> updatedResults = new ArrayList<>();
if (results.size() == 0)
continue;
SearchServiceImpl.log.info("Search for newly createdQuery with settings: " + settings + "; result: " + results.size() + " " + clazz.getSimpleName() + "s");
for (SearchResult sr : results) {
// Are SearchResults always auditable? maybe put in some error handling in case they are not or
// enforce searchSettings object to be of a certain form
Auditable auditableResult = (Auditable) sr.getResultObject();
// this list is ordered by date (not descending)
List<AuditEvent> eventList = auditTrailService.getEvents(auditableResult);
if (eventList == null || eventList.isEmpty())
continue;
for (AuditEvent ae : eventList) {
// assuming there is only one create event
if (ae.getAction() == AuditAction.CREATE && ae.getDate().after(query.getLastUsed())) {
updatedResults.add(sr);
break;
}
}
}
if (!updatedResults.isEmpty()) {
finalResults.put(clazz, updatedResults);
}
}
return finalResults;
}
use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.
the class SearchServiceTest method testURISearch.
/**
* Does the search engine correctly match the spinal cord URI and find objects directly tagged with that URI
*/
@Test
public void testURISearch() {
try {
this.setup();
} catch (Exception e) {
e.printStackTrace();
}
SearchSettings settings = SearchSettings.Factory.newInstance();
settings.setQuery(SearchServiceTest.SPINAL_CORD);
settings.setSearchExperiments(true);
settings.setUseDatabase(false);
settings.setUseIndices(false);
settings.setUseCharacteristics(true);
Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
assertTrue(!found.isEmpty());
for (SearchResult sr : found.get(ExpressionExperiment.class)) {
if (sr.getResultObject().equals(ee)) {
this.tearDown();
return;
}
}
this.tearDown();
fail("Didn't get expected result from search");
}
use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.
the class SearchServiceTest method testGeneralSearch4Brain.
/**
* Tests that general search terms are resolved to their proper ontology terms and objects tagged with those terms
* are found, -- requires LARQ index.
*/
@Test
public void testGeneralSearch4Brain() {
try {
this.setup();
} catch (Exception e) {
e.printStackTrace();
}
SearchSettings settings = SearchSettings.Factory.newInstance();
settings.noSearches();
// should hit 'cavity of brain'.
settings.setQuery("Brain");
settings.setSearchExperiments(true);
settings.setUseCharacteristics(true);
settings.setUseDatabase(false);
settings.setUseIndices(false);
Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
assertTrue(!found.isEmpty());
for (SearchResult sr : found.get(ExpressionExperiment.class)) {
if (sr.getResultObject().equals(ee)) {
this.tearDown();
return;
}
}
this.tearDown();
fail("Didn't get expected result from search");
}
use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.
the class SearchServiceTest method testSearchByBibRefId.
@Test
public void testSearchByBibRefId() {
try {
this.setup();
} catch (Exception e) {
e.printStackTrace();
}
String id;
if (ee.getPrimaryPublication() == null) {
PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
BibliographicReference bibref = fetcher.retrieveByHTTP(21878914);
bibref = (BibliographicReference) persisterHelper.persist(bibref);
ee.setPrimaryPublication(bibref);
eeService.update(ee);
id = "21878914";
} else {
id = ee.getPrimaryPublication().getPubAccession().getAccession();
}
log.info("indexing ...");
IndexerTaskCommand c = new IndexerTaskCommand();
c.setIndexBibRef(true);
indexerTask.setTaskCommand(c);
indexerTask.execute();
SearchSettings settings = SearchSettings.Factory.newInstance();
settings.noSearches();
settings.setQuery(id);
settings.setSearchExperiments(true);
settings.setUseCharacteristics(false);
Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
assertTrue(!found.isEmpty());
for (SearchResult sr : found.get(ExpressionExperiment.class)) {
if (sr.getResultObject().equals(ee)) {
this.tearDown();
return;
}
}
this.tearDown();
fail("Didn't get expected result from search");
}
use of ubic.gemma.model.common.search.SearchSettings 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;
}
Aggregations