Ejemplo n.º 1
0
    def search(self):
        from haystack.query import EmptySearchQuerySet
        from openPLM.plmapp.search import SmartSearchQuerySet

        if self.is_valid():
            type_ = self.cleaned_data["type"]
            query = self.cleaned_data["q"].strip()
            if type_ != "all":
                cls = m.get_all_users_and_plmobjects()[type_]
                d = {}
                m.get_all_subclasses(cls, d)
                mods = d.values()
                if issubclass(cls, m.Document) and query not in ("", "*"):
                # include documentfiles if we search for a document and
                # if the query does not retrieve all documents
                    mods.append(m.DocumentFile)

                sqs = SmartSearchQuerySet().models(*mods)
            else:
                sqs = SmartSearchQuerySet()
            if self.cleaned_data["search_official"]:
                sqs = sqs.filter(state_class="official")
            if not query or query == "*":
                return sqs.exclude(state_class="cancelled")
            results = sqs.highlight().auto_query(query)
            return results
        else:
            return EmptySearchQuerySet()
Ejemplo n.º 2
0
    def search(self):
        from haystack.query import EmptySearchQuerySet
        from openPLM.plmapp.search import SmartSearchQuerySet

        if self.is_valid():
            type_ = self.cleaned_data["type"]
            query = self.cleaned_data["q"].strip()
            if type_ != "all":
                cls = m.get_all_users_and_plmobjects()[type_]
                d = {}
                m.get_all_subclasses(cls, d)
                mods = d.values()
                if issubclass(cls, m.Document) and query not in ("", "*"):
                    # include documentfiles if we search for a document and
                    # if the query does not retrieve all documents
                    mods.append(m.DocumentFile)

                sqs = SmartSearchQuerySet().models(*mods)
            else:
                sqs = SmartSearchQuerySet()
            if self.cleaned_data["search_official"]:
                sqs = sqs.filter(state_class="official")
            if not query or query == "*":
                return sqs.exclude(state_class="cancelled")
            results = sqs.highlight().auto_query(query)
            return results
        else:
            return EmptySearchQuerySet()