-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor organism part endpoint (#352)
* Pull and update latest submodule changes * Add organism part and cell type search to analytics search DAO * Clean variable naming * Add cell types as an input parameter to OrganismPartSearchDao * Add cell types as an input parameter to OrganismPartSearchService * clean code in JsonGeneSearchController * Add cell type query parameter to the JsonGeneSearchController - WIP * Rename test method name and remove unneeded test case * Clean the code that gets the matching gene ids * Update submodules * Update atlas-web-core to the latest version
- Loading branch information
Showing
10 changed files
with
357 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/uk/ac/ebi/atlas/solr/SingleCellSolrUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package uk.ac.ebi.atlas.solr; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import org.apache.solr.common.SolrDocumentList; | ||
import org.springframework.stereotype.Component; | ||
import uk.ac.ebi.atlas.solr.cloud.SolrCloudCollectionProxyFactory; | ||
import uk.ac.ebi.atlas.solr.cloud.collections.SingleCellAnalyticsCollectionProxy; | ||
import uk.ac.ebi.atlas.solr.cloud.search.SolrQueryBuilder; | ||
|
||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
import static uk.ac.ebi.atlas.solr.cloud.collections.SingleCellAnalyticsCollectionProxy.CELL_ID; | ||
import static uk.ac.ebi.atlas.solr.cloud.collections.SingleCellAnalyticsCollectionProxy.CTW_CELL_TYPE; | ||
|
||
@Component | ||
public class SingleCellSolrUtils { | ||
|
||
private final SingleCellAnalyticsCollectionProxy singleCellAnalyticsCollectionProxy; | ||
|
||
private static final int MAX_ROWS = 10000; | ||
|
||
public SingleCellSolrUtils(SolrCloudCollectionProxyFactory solrCloudCollectionProxyFactory) { | ||
singleCellAnalyticsCollectionProxy = | ||
solrCloudCollectionProxyFactory.create(SingleCellAnalyticsCollectionProxy.class); | ||
} | ||
|
||
public ImmutableSet<String> fetchedRandomCellTypesByCellIDs(ImmutableSet<String> cellIDs, int numberOfCellTypes) { | ||
SolrQueryBuilder<SingleCellAnalyticsCollectionProxy> queryBuilder = new SolrQueryBuilder<>(); | ||
queryBuilder | ||
.addQueryFieldByTerm(CELL_ID, cellIDs) | ||
.setFieldList(CTW_CELL_TYPE) | ||
.setRows(MAX_ROWS); | ||
|
||
return getRandomCellTypesFromQueryResult(singleCellAnalyticsCollectionProxy.query(queryBuilder).getResults(), numberOfCellTypes); | ||
} | ||
|
||
private ImmutableSet<String> getRandomCellTypesFromQueryResult(SolrDocumentList solrDocumentList, int numberOfCellTypes) { | ||
return Arrays.stream(new Random().ints(numberOfCellTypes, 0, solrDocumentList.size()).toArray()) | ||
.mapToObj(index -> solrDocumentList.get(index).getFieldValue(CTW_CELL_TYPE.name()).toString()) | ||
.collect(toImmutableSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.