use of org.jbei.ice.lib.dto.search.SearchResults in project ice by JBEI.
the class SearchIndexesTest method testRunSearch.
@Test
public void testRunSearch() throws Exception {
Account account = AccountCreator.createTestAccount("testRunSearch", false);
Assert.assertNotNull(account);
// create entry
PlasmidData plasmidData = new PlasmidData();
plasmidData.setCircular(true);
plasmidData.setPromoters("pTet");
plasmidData.setOriginOfReplication("oRep");
PartData partData = new PartData(EntryType.PLASMID);
partData.setBioSafetyLevel(BioSafetyOption.LEVEL_ONE.ordinal());
partData.setStatus("Complete");
partData.setName("testPlasmid");
partData.setFundingSource("DOE");
partData.setPrincipalInvestigator("Nathan");
partData.setPlasmidData(plasmidData);
partData = new Entries(account.getEmail()).create(partData);
Entry entry = DAOFactory.getEntryDAO().get(partData.getId());
Assert.assertNotNull(entry);
Assert.assertTrue(entry.getId() > 0);
// commit triggers indexing
HibernateUtil.commitTransaction();
HibernateUtil.beginTransaction();
SearchQuery query = new SearchQuery();
query.setQueryString("testPlasmid");
SearchResults results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// case insensentive
results = controller.runSearch(account.getEmail().toLowerCase(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// search for promoters
query.setQueryString("pTet");
results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// search email
query.setQueryString(account.getEmail());
results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// fake search
query.setQueryString("FAKE_SEARCH");
results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(0, results.getResultCount());
}
use of org.jbei.ice.lib.dto.search.SearchResults in project ice by JBEI.
the class WebSearch method run.
/**
* Searches all registries in the web of registries configuration with this
* registry. Without some sort of indexing locally or in some central location,
* this will be slow for large numbers of results
*
* @param query wrapper around search query
* @param includeThisInstance whether to include results from this instance of ICE
* @return list of search results
*/
public WebSearchResults run(SearchQuery query, boolean includeThisInstance) {
List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
if (partners == null)
return null;
List<SearchTask> searchTasks = new LinkedList<>();
// for each approved partner run the search task
for (RemotePartner partner : partners) {
if (partner.getUrl() == null || partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
continue;
SearchTask task = runSearchThread(partner, query);
searchTasks.add(task);
}
WebSearchResults searchResults = new WebSearchResults(searchTasks.size() + 1);
// String inWWoR = Utils.getConfigValue(ConfigurationKey.JOIN_WEB_OF_REGISTRIES);
if (includeThisInstance) {
SearchIndexes searchIndexes = new SearchIndexes();
SearchResults results = searchIndexes.runSearch(null, query);
searchResults.setQuery(query);
WebResult thisResult = new WebResult();
thisResult.getResults().addAll(results.getResults());
thisResult.setCount(results.getResultCount());
String url = Utils.getConfigValue(ConfigurationKey.URI_PREFIX);
String projectName = Utils.getConfigValue(ConfigurationKey.PROJECT_NAME);
RegistryPartner thisPartner = new RegistryPartner();
thisPartner.setUrl(url);
thisPartner.setName(projectName);
thisResult.setPartner(thisPartner);
searchResults.getResults().add(thisResult);
searchResults.setTotalCount(thisResult.getCount());
}
// go through tasks and check if completed
while (!searchTasks.isEmpty()) {
Iterator<SearchTask> iterator = searchTasks.iterator();
// todo : set time limit and abandon task (shutdown) if exceeded (or after give it till after this instance is searched)
while (iterator.hasNext()) {
SearchTask task = iterator.next();
TaskStatus status = task.getStatus();
if (status == TaskStatus.COMPLETED || status == TaskStatus.EXCEPTION) {
iterator.remove();
if (status == TaskStatus.COMPLETED) {
WebResult webResult = new WebResult();
webResult.setPartner(task.getPartner().toDataTransferObject());
SearchResults partnerResults = task.getResults();
webResult.setCount(partnerResults.getResultCount());
webResult.getResults().addAll(partnerResults.getResults());
searchResults.getResults().add(webResult);
searchResults.setTotalCount(searchResults.getTotalCount() + partnerResults.getResultCount());
}
}
}
}
return searchResults;
}
use of org.jbei.ice.lib.dto.search.SearchResults in project ice by JBEI.
the class HibernateSearch method filterBlastResults.
/**
* Intended to be called after running a blast search to filter the results. Blast search runs
* on a fasta file which contains all the sequences. Hibernate search has a security filter for permissions
* and is therefore used to filter out the blast results, as well as to filter based on the entry
* attributes not handled by blast; such as "has sequence" and "bio-safety level"
*
* @param userId identifier for account of user performing search
* @param start paging start
* @param count maximum number of results to return
* @param blastResults raw results of the blast search
* @return wrapper around list of filtered results
*/
public SearchResults filterBlastResults(String userId, int start, int count, SearchQuery searchQuery, final HashMap<String, SearchResult> blastResults) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Entry.class).get();
Query query = qb.keyword().onField("visibility").matching(Visibility.OK.getValue()).createQuery();
// todo : there is a limit of 1024 boolean clauses so return only return top blast results
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.add(query, BooleanClause.Occur.FILTER);
// wrap Lucene query in a org.hibernate.Query
Class<?>[] classes = SearchFieldFactory.classesForTypes(searchQuery.getEntryTypes());
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), classes);
// enable security filter if an admin
checkEnableSecurityFilter(userId, fullTextQuery);
// enable has attachment/sequence/sample (if needed)
checkEnableHasAttribute(fullTextQuery, searchQuery.getParameters());
// bio-safety level
if (searchQuery.getBioSafetyOption() != null) {
TermContext levelContext = qb.keyword();
Query biosafetyQuery = levelContext.onField("bioSafetyLevel").ignoreFieldBridge().matching(searchQuery.getBioSafetyOption().getValue()).createQuery();
builder.add(biosafetyQuery, BooleanClause.Occur.MUST);
}
// execute search
fullTextQuery.setProjection("id");
// list contains an object array with one Long object
List<?> luceneResult = fullTextQuery.list();
HashSet<String> resultSet = new HashSet<>();
// page
for (Object object : luceneResult) {
Long result = (Long) ((Object[]) object)[0];
resultSet.add(result.toString());
}
blastResults.keySet().removeIf(key -> !resultSet.contains(key));
SearchResult[] searchResults = new SearchResult[count];
int limit = Math.min((start + count), blastResults.size());
LinkedList<SearchResult> list = new LinkedList<>(Arrays.asList(blastResults.values().toArray(searchResults)).subList(start, limit));
SearchResults results = new SearchResults();
results.setResultCount(blastResults.size());
results.setResults(list);
return results;
}
use of org.jbei.ice.lib.dto.search.SearchResults in project ice by JBEI.
the class SearchControllerTest method testRunSearch.
@Test
public void testRunSearch() throws Exception {
Account account = AccountCreator.createTestAccount("testRunSearch", false);
Assert.assertNotNull(account);
// create entry
PlasmidData plasmidData = new PlasmidData();
plasmidData.setCircular(true);
plasmidData.setPromoters("pTet");
plasmidData.setOriginOfReplication("oRep");
PartData partData = new PartData(EntryType.PLASMID);
partData.setBioSafetyLevel(BioSafetyOption.LEVEL_ONE.ordinal());
partData.setStatus("Complete");
partData.setName("testPlasmid");
partData.setFundingSource("DOE");
partData.setPrincipalInvestigator("Nathan");
partData.setPlasmidData(plasmidData);
Entry entry = InfoToModelFactory.infoToEntry(partData);
entry = new EntryCreator().createEntry(account, entry, null);
Assert.assertNotNull(entry);
Assert.assertTrue(entry.getId() > 0);
// commit triggers indexing
HibernateUtil.commitTransaction();
HibernateUtil.beginTransaction();
SearchQuery query = new SearchQuery();
query.setQueryString("testPlasmid");
SearchResults results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// search for promoters
query.setQueryString("pTet");
results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// search email
query.setQueryString(account.getEmail());
results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(1, results.getResultCount());
// fake search
query.setQueryString("FAKE_SEARCH");
results = controller.runSearch(account.getEmail(), query);
Assert.assertNotNull(results);
Assert.assertEquals(0, results.getResultCount());
}
use of org.jbei.ice.lib.dto.search.SearchResults in project ice by JBEI.
the class Entries method getSearchResults.
private List<Long> getSearchResults(SearchQuery searchQuery) {
SearchIndexes searchIndexes = new SearchIndexes();
SearchResults searchResults = searchIndexes.runSearch(userId, searchQuery);
// todo : inefficient: have search return ids only
List<Long> results = new LinkedList<>();
for (SearchResult result : searchResults.getResults()) {
results.add(result.getEntryInfo().getId());
}
return results;
}
Aggregations