Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lookups.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from django.db.models import Transform
  2. from django.db.models.lookups import PostgresOperatorLookup
  3. from .search import SearchVector, SearchVectorExact, SearchVectorField
  4. class DataContains(PostgresOperatorLookup):
  5. lookup_name = "contains"
  6. postgres_operator = "@>"
  7. class ContainedBy(PostgresOperatorLookup):
  8. lookup_name = "contained_by"
  9. postgres_operator = "<@"
  10. class Overlap(PostgresOperatorLookup):
  11. lookup_name = "overlap"
  12. postgres_operator = "&&"
  13. class HasKey(PostgresOperatorLookup):
  14. lookup_name = "has_key"
  15. postgres_operator = "?"
  16. prepare_rhs = False
  17. class HasKeys(PostgresOperatorLookup):
  18. lookup_name = "has_keys"
  19. postgres_operator = "?&"
  20. def get_prep_lookup(self):
  21. return [str(item) for item in self.rhs]
  22. class HasAnyKeys(HasKeys):
  23. lookup_name = "has_any_keys"
  24. postgres_operator = "?|"
  25. class Unaccent(Transform):
  26. bilateral = True
  27. lookup_name = "unaccent"
  28. function = "UNACCENT"
  29. class SearchLookup(SearchVectorExact):
  30. lookup_name = "search"
  31. def process_lhs(self, qn, connection):
  32. if not isinstance(self.lhs.output_field, SearchVectorField):
  33. config = getattr(self.rhs, "config", None)
  34. self.lhs = SearchVector(self.lhs, config=config)
  35. lhs, lhs_params = super().process_lhs(qn, connection)
  36. return lhs, lhs_params
  37. class TrigramSimilar(PostgresOperatorLookup):
  38. lookup_name = "trigram_similar"
  39. postgres_operator = "%%"
  40. class TrigramWordSimilar(PostgresOperatorLookup):
  41. lookup_name = "trigram_word_similar"
  42. postgres_operator = "%%>"