예제 #1
0
 def search(self, query, *or_query):
     q = reduce(
         lambda a, b: a | Q(search=PrefixSearchQuery(b, config="simple_unaccented")),
         or_query,
         Q(search=PrefixSearchQuery(query, config="simple_unaccented")),
     )
     try:
         phonenumbers.parse(query, "FR")
     except phonenumbers.phonenumberutil.NumberParseException:
         return self.filter(q)
     else:
         return self.filter(q | Q(contact_phone__icontains=query[1:]))
예제 #2
0
    def search(self, query):

        if NUMERO_RE.match(query):
            return self.filter(numero__startswith=query)

        vector = self.model.search_vector()

        query = PrefixSearchQuery(
            query, config="french_unaccented") | PrefixSearchQuery(
                query, config="simple_unaccented")

        return (self.annotate(search=vector).filter(search=query).annotate(
            rank=SearchRank(vector, query)).order_by("-rank"))
예제 #3
0
    def search(self, query):
        vector = (
            SearchVector(models.F("name"), config="french_unaccented", weight="A")
            + SearchVector(
                models.F("location_name"), config="french_unaccented", weight="B"
            )
            + SearchVector(
                models.F("location_city"), config="french_unaccented", weight="B"
            )
            + SearchVector(
                models.F("location_zip"), config="french_unaccented", weight="B"
            )
            + SearchVector(
                models.F("description"), config="french_unaccented", weight="C"
            )
            + SearchVector(
                models.F("report_content"), config="french_unaccented", weight="C"
            )
        )
        query = PrefixSearchQuery(query, config="french_unaccented")

        return (
            self.annotate(search=vector)
            .filter(search=query)
            .annotate(rank=SearchRank(vector, query))
            .order_by("-rank")
        )
예제 #4
0
    def get_search_results(self, request, queryset, search_term):
        if search_term:
            queryset = queryset.filter(recipient__search=PrefixSearchQuery(
                search_term, config="simple_unaccented"))

        use_distinct = False

        return queryset, use_distinct
예제 #5
0
 def full_text_search(self, query):
     q = Q(search=PrefixSearchQuery(query, config="simple_unaccented"))
     try:
         phonenumbers.parse(query, "FR")
     except phonenumbers.phonenumberutil.NumberParseException:
         return self.filter(q)
     else:
         return self.filter(q | Q(contact_phone__icontains=query[1:]))
예제 #6
0
 def get_search_results(self, request, queryset, search_term):
     use_distinct = False
     if search_term:
         return (
             queryset.filter(person__search=PrefixSearchQuery(
                 search_term, config="simple_unaccented")),
             use_distinct,
         )
     return queryset, use_distinct
예제 #7
0
    def search(self, search_terms):
        vector = SearchVector(
            models.F("name"), config="simple_unaccented",
            weight="A") + SearchVector(models.F("code_departement"),
                                       config="simple_unaccented",
                                       weight="B")
        query = PrefixSearchQuery(search_terms, config="simple_unaccented")

        return (self.annotate(search=vector).filter(search=query).annotate(
            rank=SearchRank(vector, query)).order_by("-rank"))
예제 #8
0
    def simple_search(self, query):
        """Cherche uniquement sur le nom de l'événement, le nom du lieu et le nom de la ville"""
        vector = (SearchVector(
            models.F("name"), config="french_unaccented", weight="A") +
                  SearchVector(models.F("location_name"),
                               config="french_unaccented",
                               weight="B") +
                  SearchVector(models.F("location_city"),
                               config="french_unaccented",
                               weight="C"))

        query = PrefixSearchQuery(query, config="french_unaccented")

        return (self.annotate(search=vector).filter(search=query).annotate(
            rank=SearchRank(vector, query)).order_by("-rank"))
예제 #9
0
 def get_events_full_text_search(self, text_query, min_date, max_date,
                                 location, distance_max):
     if not text_query:
         return []
     qs = self.get_queryset()
     q = PrefixSearchQuery(text_query, config="fr")
     qs = (qs.annotate(rank=SearchRank(F("search"), q)).filter(
         rank__gt=0).order_by("-rank").filter(
             visibility=Event.VISIBILITY_PUBLIC))
     if min_date:
         qs = qs.filter(start_time__gt=min_date)
     if max_date:
         qs = qs.filter(start_time__lt=(max_date + timedelta(days=1)))
     if location and distance_max:
         qs = qs.annotate(
             distance=Distance("coordinates", location)).filter(
                 distance__lte=DistanceMeasure(km=int(distance_max)))
     return qs
예제 #10
0
 def search(self, query):
     return self.filter(person__search=PrefixSearchQuery(
         query, config="simple_unaccented"))
예제 #11
0
 def rechercher(self, query):
     return self.filter(
         search=PrefixSearchQuery(query, config="data_france_search"))