Add a new Solr search facet - fli-iam/shanoir-ng GitHub Wiki
Faceting is the arrangement of search results into categories based on indexed terms.
Searchers are presented with the indexed terms, along with numerical counts of how many matching documents were found for each term. Faceting makes it easy for users to explore search results, narrowing in on exactly the results they are looking for.
In this example, we add a new boolean processed field, that will allow users to filter processed / non-processed dataset (see PR #2146)
Add a new <field> element into docker-compose/solr/core/schema.xml (starting from line 441)
...
<field name="processed" type="boolean" indexed="true" stored="true" required="true" />
...📖 Check Solr documentation for properties description
Add the new property into the ShanoirMetadata class
- new property
- accessors
- constructor parameter
- new
@ColumnResultannotation
@Entity
@SqlResultSetMapping(name = "SolrResult", classes = {@ConstructorResult(targetClass = ShanoirMetadata.class,
columns = {...,
@ColumnResult(name="processed", type = Boolean.class)
})
})
...
private boolean processed;
...
public ShanoirMetadata (..., boolean processed) {
...
this.processed = processed;
}
...
public boolean isProcessed() {
return processed;
}
public void setProcessed(boolean processed) {
this.processed = processed;
}
...
}Add the new property into the ShanoirSolrDocument class
- new
@Fieldproperty - accessors
- constructor parameter
...
@Field
private boolean processed;
...
public ShanoirSolrDocument (..., boolean processed) {
...
this.processed = processed;
}
...
public boolean isProcessed() {
return processed;
}
public void setProcessed(boolean processed) {
this.processed = processed;
}
...Add the new Collection property into the ShanoirSolrQuery class
- new property
- accessors
...
private Collection<Boolean> processed;
...
public Collection<Boolean> getProcessed() {
return processed;
}
public void setProcessed(Collection<Boolean> processed) {
this.processed = processed;
}Add the new property into the SQL SELECT clause of the String constants of the ShanoirMetadataRepositoryImpl class
- MR_QUERY
- PET_QUERY
- CT_QUERY
- GENERIC_QUERY
- EEG_QUERY
- BIDS_QUERY
- PROCESSED_QUERY
- MEASUREMENT_QUERY
- XA_QUERY
...
public static final String MR_QUERY = "SELECT d.id as datasetId, " +
...
"0 as processed"
+ " FROM dataset d"
+ " LEFT JOIN dataset_acquisition da on da.id = d.dataset_acquisition_id"
...
+ " WHERE d.updated_metadata_id = dm.id AND md.id = d.id";
...- Add the new property as parameter of the
ShanoirSolrDocumentclass constructor in thegetShanoirSolrDocument()method of theSolrServiceImplclass
...
private ShanoirSolrDocument getShanoirSolrDocument(ShanoirMetadata shanoirMetadata) {
return new ShanoirSolrDocument(..., shanoirMetadata.isProcessed());
}
...- Add a new
ORcondition on the new property to theprepareTextFields()method of theSolrServiceImplclass
private Pageable prepareTextFields(Pageable pageable) {
for (Sort.Order order : pageable.getSort()) {
if (...
|| order.getProperty().equals("processed")
) {
...- Add a new
[property]_FACETconstant toSolrJWrapperImplclass
...
private static final String PROCESSED_FACET = "processed";
...- Add the new constant to the
DOCUMENT_FACET_LISTandTEXTUAL_FACET_LISTString arrays in theSolrJWrapperImplclass
...
private static final String[] DOCUMENT_FACET_LIST = {
...
PROCESSED_FACET
};
private static final String[] TEXTUAL_FACET_LIST = {
...
PROCESSED_FACET
};
...- Add a call to the relevant
addFilterQuery*(...)method in theaddUserFiltering()method in theSolrJWrapperImplclass, based on the new property type
...
private void addUserFiltering(SolrQuery query, ShanoirSolrQuery shanoirQuery) {
/* add user's filtering */
...
addFilterQueryFromBoolean(query, PROCESSED_FACET, shanoirQuery.getProcessed());
...
}
...Create a new SQL script into docker-compose/database/db-changes/datasets to add the new field into datasets.shanoir_metadata table
alter table shanoir_metadata add column processed bit(1);Add the new property into SolrDocument and SolrQuery classes
export class SolrDocument {
...
processed: boolean;
...
}
export class SolrRequest {
...
processed: boolean[];
...
}
...Add a new solr-paging-criterion element to the Solr view
...
<solr-paging-criterion
label="Processed Dataset"
awesome="fa-solid fa-gears"
facetName="processed"
[getPage]="getFacetFieldPage.bind(this)"
[(ngModel)]="solrRequest.processed"
[ngModelOptions]="{standalone: true}"
(onChange)="updateSelections(); refreshTable('processed')">
</solr-paging-criterion>
...- Add the new property to the
TextualFacetNames(orRangeFacetNames) array
const TextualFacetNames: string[] = [..., 'processed'];
const RangeFacetNames: string[] = ['sliceThickness', 'pixelBandwidth', 'magneticFieldStrength'];- If you want to display the new property into the Solr search result table, add a new
ColumnDefinitioninto thecolumnDefsarray
let columnDefs: ColumnDefinition[] = [...
{headerName: "", type: "boolean", cellRenderer: row => row.data.processed, awesome: "fa-solid fa-gears", color: "dimgrey", disableSorting: true, tip: item => { return item.processed ? "processed dataset" : "" }},...];Add the new field to the expert info block
...
<p>The present field names are :
<code>centerName, datasetCreationDate, studyName, subjectName, subjectType, acquisitionEquipmentName, datasetId, datasetName, datasetNature, datasetType, processed, examinationComment, examinationDate, tags, magneticFieldStrength, pixelBandwidth, sliceThickness, studyId, </code>
....
For the change to be taken into account, Solr docker volume need to be recreated.
docker exec solr rm -rf /var/solr/dataThen, as administrator, launch a manual indexation through the Shanoir webpage (Administration / Index to Solr)
Or
On your local environment, you can recreate said volume either by executing
./bootstrap.sh --cleanOn qualif server, after having deployed your branch, you need to remove the volume with
dk exec ofsep-qualif-solr rm -rf /var/solr/dataThen restart the Solr docker (and its dependences)
dk stop ofsep-qualif-nginx ofsep-qualif-nifti-conversion ofsep-qualif-datasets ofsep-qualif-solr
...
dk start ofsep-qualif-nifti-conversion ofsep-qualif-datasets ofsep-qualif-solr ofsep-qualif-nginx
...Then, as administrator, launch a manual indexation through the Shanoir webpage (Administration / Index to Solr)

