def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.index_id operator = 'or' if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') value = atdx_normalize(value) if not value: return query # When getting Files, we also want to get FileAttachments. if not isinstance(value, list): value = [value] if 'File' in value: value.append('FileAttachment') query[index] = {'query': value, 'operator': operator} return query
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get('index', '') index = index.encode('utf-8', 'replace') if not self.operator_visible: operator = self.operator else: operator = form.get(self.data.getId() + '-operator', self.operator) operator = operator.encode('utf-8', 'replace') if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') value = atdx_normalize(value) if not value: return query query[index] = {'query': value, 'operator': operator} return query
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get('index', '') index = index.encode('utf-8', 'replace') if not self.operator_visible: operator = self.operator else: operator = form.get(self.data.getId() + '-operator', self.operator) operator = operator.encode('utf-8', 'replace') if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') value = atdx_normalize(value) if not value: return query query[index] = {'query': value, 'operator': operator} return query
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get('index', '') index = index.encode('utf-8', 'replace') if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') if not value: return query value = atdx_normalize(value) query[index] = value return query
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get('index', '') index = index.encode('utf-8', 'replace') if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') if not value: return query value = atdx_normalize(value) query[index] = value return query
def count(self, brains, sequence=None): """ Intersect results """ res = {} if not sequence: sequence = [key for key, value in self.vocabulary()] if not sequence: return res index_id = self.data.get('index') if not index_id: return res ctool = getToolByName(self.context, 'portal_catalog') index = ctool._catalog.getIndex(index_id) ctool = queryUtility(IFacetedCatalog) if not ctool: return res brains = IISet(brain.getRID() for brain in brains) res[""] = res['all'] = len(brains) for value in sequence: if not value: res[value] = len(brains) continue normalized_value = atdx_normalize(value) rset = ctool.apply_index(self.context, index, normalized_value)[0] rset = IISet(rset) rset = weightedIntersection(brains, rset)[1] if isinstance(value, unicode): res[value] = len(rset) elif isinstance(normalized_value, unicode): res[normalized_value] = len(rset) else: unicode_value = value.decode('utf-8') res[unicode_value] = len(rset) return res
def count(self, brains, sequence=None): """ Intersect results """ res = {} if not sequence: sequence = [key for key, value in self.vocabulary()] if not sequence: return res index_id = self.data.get('index') if not index_id: return res ctool = getToolByName(self.context, 'portal_catalog') index = ctool._catalog.getIndex(index_id) ctool = queryUtility(IFacetedCatalog) if not ctool: return res brains = IISet(brain.getRID() for brain in brains) res[""] = res['all'] = len(brains) for value in sequence: if not value: res[value] = len(brains) continue normalized_value = atdx_normalize(value) rset = ctool.apply_index(self.context, index, normalized_value)[0] rset = IISet(rset) rset = weightedIntersection(brains, rset)[1] if isinstance(value, unicode): res[value] = len(rset) elif isinstance(normalized_value, unicode): res[normalized_value] = len(rset) else: unicode_value = value.decode('utf-8') res[unicode_value] = len(rset) return res
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get("index", "") index = index.encode("utf-8", "replace") if not self.operator_visible: operator = self.operator else: operator = form.get(self.data.getId() + "-operator", self.operator) operator = operator.encode("utf-8", "replace") if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), "") value = atdx_normalize(value) if not value: return query catalog = getToolByName(self.context, "portal_catalog") if index in catalog.Indexes: if catalog.Indexes[index].meta_type == "BooleanIndex": if value == "False": value = False elif value == "True": value = True query[index] = {"query": value, "operator": operator} return query
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get('index', '') index = index.encode('utf-8', 'replace') if not self.operator_visible: operator = self.operator else: operator = form.get(self.data.getId() + '-operator', self.operator) operator = operator.encode('utf-8', 'replace') if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') value = atdx_normalize(value) if not value: return query catalog = getToolByName(self.context, 'portal_catalog') if index in catalog.Indexes: if catalog.Indexes[index].meta_type == 'BooleanIndex': if value == 'False': value = False elif value == 'True': value = True query[index] = {'query': value, 'operator': operator} return query
def query(self, form): """ Get value from form and return a catalog dict query """ query = {} index = self.data.get('index', '') index = index.encode('utf-8', 'replace') if not self.operator_visible: operator = self.operator else: operator = form.get(self.data.getId() + '-operator', self.operator) operator = operator.encode('utf-8', 'replace') if not index: return query if self.hidden: value = self.default else: value = form.get(self.data.getId(), '') value = atdx_normalize(value) if not value: return query catalog = getToolByName(self.context, 'portal_catalog') if index in catalog.Indexes: if catalog.Indexes[index].meta_type == 'BooleanIndex': if value == 'False': value = False elif value == 'True': value = True query[index] = {'query': value, 'operator': operator} return query
def count(self, brains, sequence=None): """ Intersect results """ res = {} # by checking for facet_counts we assume this is a SolrResponse # from collective.solr if hasattr(brains, 'facet_counts'): facet_fields = brains.facet_counts.get('facet_fields') if facet_fields: index_id = self.data.get('index') facet_field = facet_fields.get(index_id, {}) for value, num in facet_field.items(): normalized_value = atdx_normalize(value) if isinstance(value, unicode): res[value] = num elif isinstance(normalized_value, unicode): res[normalized_value] = num else: unicode_value = value.decode('utf-8') res[unicode_value] = num else: # no facet counts were returned. we exit anyway because # zcatalog methods throw an error on solr responses return res res[""] = res['all'] = len(brains) return res else: # this is handled by the zcatalog. see below pass if not sequence: sequence = [key for key, value in self.vocabulary()] if not sequence: return res index_id = self.data.get('index') if not index_id: return res ctool = getToolByName(self.context, 'portal_catalog') index = ctool._catalog.getIndex(index_id) ctool = queryUtility(IFacetedCatalog) if not ctool: return res if isinstance(brains, LazyMap): values = brains._seq # 75384 seq might be a pair of tuples instead of ints # if you upgrade to ZCatalog 3 if isinstance(values[0], tuple): values = [v[1] for v in values] brains = IISet(values) else: brains = IISet(brain.getRID() for brain in brains) res[""] = res['all'] = len(brains) for value in sequence: if not value: res[value] = len(brains) continue normalized_value = atdx_normalize(value) rset = ctool.apply_index(self.context, index, normalized_value)[0] rset = IISet(rset) rset = weightedIntersection(brains, rset)[1] if isinstance(value, unicode): res[value] = len(rset) elif isinstance(normalized_value, unicode): res[normalized_value] = len(rset) else: unicode_value = value.decode('utf-8') res[unicode_value] = len(rset) return res
def count(self, brains, sequence=None): """ Intersect results """ res = {} # by checking for facet_counts we assume this is a SolrResponse # from collective.solr if hasattr(brains, 'facet_counts'): facet_fields = brains.facet_counts.get('facet_fields') if facet_fields: index_id = self.data.get('index') facet_field = facet_fields.get(index_id, {}) for value, num in facet_field.items(): normalized_value = atdx_normalize(value) if isinstance(value, unicode): res[value] = num elif isinstance(normalized_value, unicode): res[normalized_value] = num else: unicode_value = value.decode('utf-8') res[unicode_value] = num else: # no facet counts were returned. we exit anyway because # zcatalog methods throw an error on solr responses return res res[""] = res['all'] = len(brains) return res else: # this is handled by the zcatalog. see below pass if not sequence: sequence = [key for key, value in self.vocabulary()] if not sequence: return res index_id = self.data.get('index') if not index_id: return res ctool = getToolByName(self.context, 'portal_catalog') index = ctool._catalog.getIndex(index_id) ctool = queryUtility(IFacetedCatalog) if not ctool: return res brains = IISet(brain.getRID() for brain in brains) res[""] = res['all'] = len(brains) for value in sequence: if not value: res[value] = len(brains) continue normalized_value = atdx_normalize(value) rset = ctool.apply_index(self.context, index, normalized_value)[0] rset = IISet(rset) rset = weightedIntersection(brains, rset)[1] if isinstance(value, unicode): res[value] = len(rset) elif isinstance(normalized_value, unicode): res[normalized_value] = len(rset) else: unicode_value = value.decode('utf-8') res[unicode_value] = len(rset) return res