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