Hi everyone,
I am using listing to add additional custom fields to samples grid. However, I am stuck as I am not able to add these extra columns to ‘search’ using listing_searchable_text. I have tried below approaches, but listing_searchable_text doesn’t add extra field. I’d appreciate any help.
-
Using an adapter that implements
``IListingSearchableTextProvider``.
# @adapter(IAnalysisRequest, IBikaCatalogAnalysisRequestListing) # object type + catalog (None is fine)
# @adapter(IAnalysisRequest, IBikaCatalogListing)
@adapter(IAnalysisRequest, ISampleCatalog)
@implementer(IListingSearchableTextProvider)
class ARListingSearchableTextProvider(object):
"""Include PatientFirstName and PatientLastName in listing_searchable_text"""
def __init__(self, context, catalog=None):
# def __init__(self, context):
logger.info("Initializing ARListingSearchableTextProvider")
self.context = context
self.catalog = catalog
# self.PatientFirstName = context.getField('PatientFirstName').get(self.context)
def __call__(self):
tokens = []
logger.info("ARListingSearchableTextProvider: __call__ invoked")
# Patient First Name
if getattr(self.context, "getPatientFirstName", None):
logger.info("Getting Patient First Name")
val = self.context.getPatientFirstName()
if val:
tokens.append(val)
# Patient Last Name
if getattr(self.context, "getPatientLastName", None):
logger.info("Getting Patient Last Name")
val = self.context.getPatientLastName()
if val:
tokens.append(val)
return tokens
-
by simply calling the function
`get_searchable_text_tokens`
-
# @indexer(IAnalysisRequest, ISenaiteCatalogSample) @indexer(IAnalysisRequest) def ar_listing_searchable_text(instance): """Indexer for listing_searchable_text on AnalysisRequests""" logger.info("Indexing listing_searchable_text for %s", instance.getId()) exclude = [] include = ["PatientFirstName"] tokens = get_searchable_text_tokens( instance, "senaite_catalog_sample", exclude_field_names=exclude, include_field_names=include, ) logger.info("Indexer tokens for %s: %s", instance.getId(), tokens) return u" ".join(tokens)
Thanks,