Exemplo n.º 1
0
    def search(self):
        if not self.is_valid():
            return self.no_query_found()

        if not self.cleaned_data.get('q'):
            return self.no_query_found()

        q = self.cleaned_data['q']
        sqs = self.searchqueryset.filter(
            SQ(name=AutoQuery(q)) | SQ(text=AutoQuery(q)))

        if self.load_all:
            sqs = sqs.load_all()

        return sqs.highlight()
Exemplo n.º 2
0
def search_title(request):
    "Handles title searches"
    q = request.GET.get('q', '')

    content = AutoQuery(q)
    results = SearchQuerySet().filter(content=content).highlight()[:50]

    items = []
    for row in results:
        try:
            ob = row.object

            # Why can this happen?
            if not ob:
                continue
            context = join_highlights(row)
            context = context or slow_highlight(query=q, text=row.content)
            text = "%s" % row.title
            items.append(
                dict(id=ob.get_absolute_url(),
                     text=text,
                     context=context,
                     author=row.author,
                     url=ob.get_absolute_url()), )
        except Exception, exc:
            logger.error(content)
            logger.error(exc)
            pass
Exemplo n.º 3
0
    def get_queryset(self):
        self.q = self.request.GET.get('q', '')

        if not self.q:
            return []

        content = AutoQuery(self.q)
        query = SearchQuerySet().filter(content=content).highlight()[:50]
        for row in query:
            context = join_highlights(row)
            context = context or slow_highlight(query=self.q, text=row.content)
            row.context = context
        return query
Exemplo n.º 4
0
    def get_queryset(self, *args, **kwargs):
        request = self.request
        queryset = EmptySearchQuerySet()

        q = request.query_params.get('q')
        # form = BuscarRestForm(request.GET)
        # if form.is_valid():
        #     query = strip_tags(form.cleaned_data['q'])
        #     # tipo = strip_tags(form.cleaned_data['tipo'])
        #     # queryset = SearchQuerySet().filter(content=query).filter(tipo=tipo)
        #     queryset = SearchQuerySet().filter(content=query)
        # queryset = SearchQuerySet().filter(content=q)
        queryset = SearchQuerySet().filter(
            SQ(content=AutoQuery(q)) | SQ(titulo=Exact(q)))
        # queryset = SearchQuerySet().filter(SQ(content=AutoQuery(q)) | SQ(titulo=AutoQuery(q)))

        return queryset
Exemplo n.º 5
0
    def build_filters(self, filters=None, stem_lang=''):
        if filters is None:
            filters = {}

        applicable_filters = {}
        for filter_expr, value in filters.items():
            lookup_bits = filter_expr.split(LOOKUP_SEP)
            field_name = lookup_bits.pop(0)
            filter_type = lookup_bits.pop() if lookup_bits else 'contains'
            filter_expr = LOOKUP_SEP.join([field_name, filter_type])
            filter_value = self.filter_value_to_python(filter_type, value)

            if field_name in self._meta.stem_fields and stem_lang:
                filter_value = stemmer.stem(filter_value, stem_lang)

            if field_name in self._meta.autoquery_fields:
                filter_value = AutoQuery(filter_value)

            if self.check_filtering(field_name, filter_type):
                applicable_filters[filter_expr] = filter_value

        return applicable_filters