48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from zoo.models import EntitySchema, Entity
|
|
from zoo.zoo_data.search import JSONTextRef
|
|
|
|
from django.contrib.postgres.search import TrigramDistance
|
|
from django.db.models import F
|
|
|
|
|
|
def test_new_schema(db):
|
|
|
|
schema = EntitySchema.objects.create(
|
|
name='person',
|
|
schema={
|
|
'type': 'object',
|
|
'properties': {
|
|
'first_name': {
|
|
'type': 'string',
|
|
},
|
|
'last_name': {
|
|
'type': 'string',
|
|
},
|
|
'address': {
|
|
'type': 'object',
|
|
'properties': {
|
|
'street': {
|
|
'type': 'string',
|
|
},
|
|
}
|
|
}
|
|
}
|
|
})
|
|
Entity.objects.create(
|
|
schema=schema,
|
|
meta={},
|
|
content={
|
|
'first_name': 'Leon',
|
|
'last_name': 'Blum',
|
|
'address': {
|
|
'street': 'Rue du Château',
|
|
}
|
|
})
|
|
qs = Entity.objects.content_search(schema, address__street='chateau')
|
|
print qs.query
|
|
assert qs.count() == 1
|
|
for e in qs:
|
|
print e.similarity
|