class ArticleDocument(Document):
    category = fields.ObjectField(
        properties={
            'id': fields.TextField(),
            'name': fields.TextField(),
            'image': fields.FileField(),
        })
    cover = fields.FileField()
    tags = fields.ListField(fields.TextField())

    class Index:
        name = 'articles'
        settings = {'number_of_shards': 1, 'number_of_replicas': 1}

    class Django:
        model = Articles
        fields = [
            'id', 'updated_at', 'title', 'subtitle', 'author_name', 'user',
            'realease', 'is_active', 'slug'
        ]
        # related_models = [Category]

    def get_queryset(self):
        """Not mandatory but to improve performance we can select related in one sql request"""
        return super(ArticleDocument,
                     self).get_queryset().select_related('category')
Example #2
0
class TagDocument(Document):
	post = fields.ObjectField(properties = {
		'id' : fields.IntegerField(),
		'statement' : fields.TextField(),
		'file' : fields.ObjectField(properties={
			'file' : fields.FileField()
		}),
		'created_date' : fields.DateField(),
		'user' : fields.ObjectField(properties={
			'username' : fields.TextField(),
			'avatar' : fields.FileField(),
		})
	})

	tag = fields.ObjectField(properties = {
		'title' : fields.TextField()
	})

	class Django:
		model = TagPost

		fields = [
			'title',
		]
	#burada hata var. çözemezsem nedtedfield ile sanırım oluyordu o şekilde Tag'dan gelip tagpost'u ve onun postunu almaya çalış.
	related_models = [Post, Tag]
class CarDocument(DocType):
    # test can override __init__
    def __init__(self, *args, **kwargs):
        super(CarDocument, self).__init__(*args, **kwargs)

    manufacturer = fields.ObjectField(properties={
        'name': fields.StringField(),
        'country': fields.StringField(),
    })

    ads = fields.NestedField(
        properties={
            'description': fields.StringField(analyzer=html_strip),
            'title': fields.StringField(),
            'pk': fields.IntegerField(),
        })

    categories = fields.NestedField(
        properties={
            'title': fields.StringField(),
            'slug': fields.StringField(),
            'icon': fields.FileField(),
        })

    class Meta:
        model = Car
        fields = [
            'name',
            'launched',
            'type',
        ]

    def get_queryset(self):
        return super(CarDocument,
                     self).get_queryset().select_related('manufacturer')
Example #4
0
class CarDocument(DocType):
    manufacturer = fields.ObjectField(
        properties={
            'name': fields.StringField(),
            'country': fields.StringField(),
            'logo': fields.FileField(),
        })

    ads = fields.NestedField(
        properties={
            'description': fields.StringField(analyzer=html_strip),
            'title': fields.StringField(),
            'pk': fields.IntegerField(),
        })

    categories = fields.NestedField(properties={
        'title': fields.StringField(),
    })

    class Meta:
        model = Car
        related_models = [Manufacturer, Category]
        fields = [
            'name',
            'launched',
            'type',
        ]

    def get_queryset(self):
        return super(CarDocument,
                     self).get_queryset().select_related('manufacturer')

    def get_instances_from_related(self, related_instance):
        return related_instance.car_set.all()
Example #5
0
class LogDetailDocument(Document):

    id = fields.IntegerField(attr="id")
    logfile = fields.ObjectField(properties={
        "name": fields.TextField(),
        "log_file": fields.FileField(),
    })

    class Index:
        name = "log_detail"
        settings = {"number_of_shards": 1, "number_of_replicas": 0}

    class Django:

        model = LogDetail
        fields = [
            "line",
            "count",
        ]
        related_models = [DocumentModel]

    def get_instances_from_related(self, related_instance):
        """If related_models is set, define how to retrieve the Car instance(s) from the related model.
        The related_models option should be used with caution because it can lead in the index
        to the updating of a lot of items.
        """
        if isinstance(related_instance, Document):
            return related_instance.logdetail_set.all()
Example #6
0
class ReferenceDocument(DocType):
    pk = fields.IntegerField(attr='pk')
    sid = fields.IntegerField(attr='sid')
    pmid = string_field(attr='pmid')
    study = ObjectField(properties={
        "pk": fields.IntegerField(),
        "name": string_field('name'),
    })
    name = string_field("name")
    doi = string_field("doi")
    title = string_field("title")
    abstract = text_field("abstract")
    journal = text_field("journal")
    date = fields.DateField()
    pdf = fields.FileField(fielddata=True)

    authors = ObjectField(properties={
        'first_name': string_field("first_name"),
        'last_name': string_field("last_name"),
        'pk': fields.IntegerField(),
    })

    class Meta(object):
        model = Reference
        # Ignore auto updating of Elasticsearch when a model is saved
        # or deleted:
        ignore_signals = True
        # Don't perform an index refresh after every update (overrides global setting):
        auto_refresh = False
class MemberDocument(Document):
    """Member Elasticsearch document."""
    id = fields.IntegerField(attr='id')
    full_name = StringField(analyzer=html_strip,
                            fields={
                                'raw': KeywordField(),
                                'suggest': fields.CompletionField(),
                            })
    birthday = fields.DateField()
    roles = fields.NestedField(
        properties={
            'title':
            fields.TextField(analyzer=html_strip,
                             attr='role',
                             fields={
                                 'raw': KeywordField(),
                             }),
        })
    member_url = fields.TextField(attr='get_absolute_url')
    image = fields.FileField(attr="image")

    class Django(object):
        """Inner nested class Django."""

        model = Members  # The model associate with this Document
Example #8
0
class UserDocument(Document):

	post = fields.ObjectField(properties = {
		'id' : fields.IntegerField(),
		'statement' : fields.TextField(),
		'location' : fields.ObjectField(properties = {
			'city' : fields.TextField(),
			'country' : fields.TextField(),
		}),
		
		'file' : fields.ObjectField(properties={
			'file' : fields.FileField()
		}),
		'created_date' : fields.DateField(),
	})
	class Django:
		model = User

		fields = [
			'id',
			'username',
			'birthday',
			'avatar',
			'info',
			'web_page',
			'active',
			'timestamp',
		]

	related_models = [Post]
Example #9
0
class MessageDocument(Document):
    chat = fields.ObjectField(
        properties={
            'id':
            fields.IntegerField(),
            'title':
            fields.TextField(),
            'owner':
            fields.ObjectField(
                properties={
                    'id':
                    fields.IntegerField(),
                    'name':
                    fields.TextField(),
                    'image':
                    fields.ObjectField(properties={
                        'id': fields.IntegerField(),
                        'image': fields.FileField()
                    })
                })
        })

    from_user = fields.ObjectField(
        properties={
            'id':
            fields.IntegerField(),
            'name':
            fields.TextField(),
            'image':
            fields.ObjectField(properties={
                'id': fields.IntegerField(),
                'image': fields.FileField()
            })
        })

    class Index:
        name = 'messages'

    class Django:
        model = Message
        fields = [
            'id',
            'image',
            'body',
            'created_at',
            'is_read',
        ]
Example #10
0
class PropertyImageDocument(Document):
    """PropertyImage Elasticsearch document."""

    id = fields.IntegerField(attr="id")
    property = fields.TextField(attr="property_indexing")
    image = fields.FileField()

    class Django(object):
        """The model associate with this Document"""

        model = PropertyImage
Example #11
0
class CompanyDocument(DocType):
    id = fields.IntegerField(attr='id')

    name = fields.TextField(
        analyzer=edgengram_analyzer,
        fields={
            'raw': fields.KeywordField(),
        }
    )
    geo = fields.GeoPointField(attr='geo_es_format')
    description = fields.TextField()
    avatar = fields.FileField()
    city = fields.ObjectField(
        properties={
            'id': fields.IntegerField(),
            'name': fields.TextField(
                fields={
                    'raw': fields.KeywordField(),
                }
            ),
            'name_fa': fields.TextField(
                fields={
                    'raw': fields.KeywordField(),
                }
            ),
            'geo': fields.GeoPointField(
                attr='geo_es_format'
            ),
            'region': fields.TextField(
                attr='region.name',
                fields={
                    'raw': fields.KeywordField(),
                }
            )

        }
    )

    related_models = [City, ]

    class Meta:
        model = Company
        fields = [
            'slug',
            'description_extra',
            'size',
            'website',
            'founded',
            'facebook',
            'twitter',
            'linkedin',
            'verified',
        ]
Example #12
0
class CollectionDocument(Document):
    """Collection Elasticsearch document."""
    id = fields.IntegerField(attr='id')
    title = StringField(analyzer=html_strip,
                        fields={
                            'raw': KeywordField(),
                            'suggest': fields.CompletionField(),
                        })
    collection_url = fields.TextField(attr='get_absolute_url')
    image = fields.FileField(attr="image")

    class Django(object):
        """Inner nested class Django."""
        model = Collection  # The model associate with this Document
Example #13
0
class PostDocument(Document):
	user = fields.ObjectField(properties = {
		'username' : fields.TextField(),
		'avatar' : fields.FileField(),
		})

	file = fields.ObjectField(properties = {
		'file' : fields.FileField()
	})

	location = fields.ObjectField(properties = {
		'city' : fields.TextField(),
		'country' : fields.TextField()
	})
	
	"""def prepare_location(self, instance):
		results = instance.location
		try:
			return {
				"longtitude" : results["longtitude"],
				"latitude" : results["latitude"],
			}
		except TypeError:
			return {"longtitude":None,"latitude":None}"""
		

	class Django:
		model = Post

		fields = [
			'id',
			'statement',
			'created_date',
		]

	related_models = [User, File, Location]
class CarDocument(Document):
    # test can override __init__
    def __init__(self, *args, **kwargs):
        super(CarDocument, self).__init__(*args, **kwargs)

    manufacturer = fields.ObjectField(properties={
        'name': fields.StringField(),
        'country': fields.StringField(),
    })

    ads = fields.NestedField(
        properties={
            'description': fields.StringField(analyzer=html_strip),
            'title': fields.StringField(),
            'pk': fields.IntegerField(),
        })

    categories = fields.NestedField(
        properties={
            'title': fields.StringField(),
            'slug': fields.StringField(),
            'icon': fields.FileField(),
        })

    class Django:
        model = Car
        related_models = [Ad, Manufacturer, Category]
        fields = [
            'name',
            'launched',
            'type',
        ]

    class Index:
        name = 'test_cars'
        settings = index_settings

    def get_queryset(self):
        return super(CarDocument,
                     self).get_queryset().select_related('manufacturer')

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Ad):
            return related_instance.car

        # otherwise it's a Manufacturer or a Category
        return related_instance.car_set.all()
Example #15
0
class UserDocument(Document):
    image = fields.ObjectField(properties={
        'id': fields.IntegerField(),
        'image': fields.FileField()
    })

    class Index:
        name = 'users'

    class Django:
        model = User
        fields = [
            'id',
            'name',
            'following',
            'is_staff',
            'gender',
        ]
Example #16
0
class PostDocument(Document):
    user = fields.ObjectField(
        properties={
            'id':
            fields.IntegerField(),
            'name':
            fields.TextField(),
            'gender':
            fields.BooleanField(),
            'is_staff':
            fields.BooleanField(),
            'image':
            fields.ObjectField(properties={
                'id': fields.IntegerField(),
                'image': fields.FileField(),
            })
        })

    group = fields.ObjectField(properties={
        'id': fields.IntegerField(),
        'title': fields.TextField(),
    })

    likers = fields.NestedField(properties={
        'id': fields.IntegerField(),
    })

    dislikers = fields.NestedField(properties={
        'id': fields.IntegerField(),
    })

    class Index:
        name = 'posts'

    class Django:
        model = Post
        fields = ['id', 'body', 'image', 'date_posted']
class CarDocument(Document):
    manufacturer = fields.ObjectField(
        properties={
            'name': fields.TextField(),
            'country': fields.TextField(),
            'logo': fields.FileField(),
        })

    ads = fields.NestedField(
        properties={
            'description': fields.TextField(analyzer=html_strip),
            'title': fields.TextField(),
            'pk': fields.IntegerField(),
        })

    categories = fields.NestedField(properties={
        'title': fields.TextField(),
    })

    class Django:
        model = Car
        fields = [
            'name',
            'launched',
            'type',
        ]

    class Index:
        name = "car"

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Ad):
            return related_instance.car

        # otherwise it's a Manufacturer or a Category
        return related_instance.car_set.all()
Example #18
0
class MovieDocument(Document):
    """Movie Elasticsearch document."""

    id = fields.IntegerField(attr='id')
    title = StringField(analyzer=html_strip,
                        fields={
                            'raw': KeywordField(),
                            'suggest': fields.CompletionField(),
                        })
    world_premiere = fields.DateField()
    country = StringField(analyzer=html_strip,
                          fields={
                              'raw': KeywordField(),
                          })
    rf_premiere = fields.DateField()
    categories = fields.NestedField(
        properties={
            'title':
            fields.TextField(analyzer=html_strip,
                             fields={
                                 'raw': KeywordField(),
                             }),
        })
    rating_kp = fields.FloatField()
    rating_imdb = fields.FloatField()
    directors = fields.NestedField(
        properties={
            'full_name': fields.TextField(analyzer=html_strip),
            'id': fields.IntegerField(),
        })
    image = fields.FileField(attr="poster")
    movie_url = fields.TextField(attr='get_absolute_url')

    class Django(object):
        """Inner nested class Django."""
        model = Movies  # The model associate with this Document
Example #19
0
class ReferenceDocument(Document):
    pk = fields.IntegerField(attr='pk')
    sid = string_field(attr='sid')
    pmid = string_field(attr='pmid')
    study = ObjectField(
        properties={
            "pk":
            fields.IntegerField(),
            "sid":
            string_field('sid'),
            "name":
            string_field('name'),
            "licence":
            string_field("licence"),
            "creator":
            fields.ObjectField(
                properties={
                    'first_name': string_field("first_name"),
                    'last_name': string_field("last_name"),
                    'pk': string_field("pk"),
                    'username': string_field("username"),
                }),
            "curators":
            fields.ObjectField(attr="ratings",
                               properties={
                                   'first_name': string_field(
                                       "user.first_name"),
                                   'last_name': string_field("user.last_name"),
                                   'pk': string_field("user.pk"),
                                   'username': string_field("user.username"),
                                   'rating': fields.FloatField(attr='rating')
                               },
                               multi=True),
            "collaborators":
            fields.ObjectField(attr="collaborators",
                               properties={
                                   'first_name': string_field("first_name"),
                                   'last_name': string_field("last_name"),
                                   'pk': string_field("pk"),
                                   'username': string_field("username")
                               },
                               multi=True)
        })
    name = string_field("name")
    doi = string_field("doi")
    title = string_field("title")
    abstract = text_field("abstract")
    journal = text_field("journal")
    date = fields.DateField()
    pdf = fields.FileField(fielddata=True)

    authors = ObjectField(
        properties={
            'first_name': string_field("first_name"),
            'last_name': string_field("last_name"),
            'pk': fields.IntegerField(),
        })

    class Django:
        model = Reference
        # Ignore auto updating of Elasticsearch when a model is saved/deleted
        ignore_signals = True
        # Don't perform an index refresh after every update (overrides global setting):
        auto_refresh = False

    class Index:
        name = 'references'
        settings = elastic_settings
Example #20
0
class BlogPostIndex(Document):
    manufacturer = fields.ObjectField(
        properties={
            'name': fields.TextField(),
            'date': fields.DateField(),
            'country': fields.TextField(),
            'logo': fields.FileField(),
        })

    class Django:
        model = blog
        # index = 'test_ads'
        fields = [
            'author',
            'posted_date',
            'text',
            'title',
        ]

    class Index:
        name = 'blog'


# @registry.register_document
# class ArticleDocument(Document):
#     """Article elasticsearch document"""

#     id = fields.IntegerField(attr='id')
#     title = fields.TextField(
#         analyzer=html_strip,
#         fields={
#             'raw': fields.TextField(analyzer='keyword'),
#         }
#     )
#     body = fields.TextField(
#         analyzer=html_strip,
#         fields={
#             'raw': fields.TextField(analyzer='keyword'),
#         }
#     )
#     author = fields.IntegerField(attr='author_id')
#     created = fields.DateField()
#     modified = fields.DateField()
#     pub_date = fields.DateField()
#     class Django:
#         model = Car
#         fields = [
#             'name',
#             'color',
#         ]
#     class Meta:
#         model = articles_models.Article

# class CarDocument(Document):
#     # add a string field to the Elasticsearch mapping called type, the
#     # value of which is derived from the model's type_to_string attribute
#     type = fields.TextField(attr="type_to_string")

#     class Django:
#         model = Car
#         # we removed the type field from here
#         fields = [
#             'name',
#             'color',
#             'description',
#         ]
class TwitDocument(Document):
    """Twit ElasticSearch Document"""

    # id = fields.IntegerField(attr='id')
    
    # title = fields.TextField(
    #     attr='title',
    #     fields={
    #         'suggest': fields.Completion(),
    #     }
    # )
    # description = fields.TextField(
    #     attr='description',
    #     fields={
    #         'suggest': fields.Completion(),
    #     }
    # )
    # category = fields.ObjectField(
    #     properties={
    #         'name': fields.TextField(),
    #         'description': fields.TextField(),
    #     }
    # )

    company = fields.ObjectField(
        # attr='company_indexing',
        properties={
            'id' : fields.IntegerField(),
            'name': fields.TextField(
                analyzer=html_strip,
                fields={
                    'raw': fields.KeywordField(),
                    'suggest': fields.CompletionField(),
                }),
            # 'description': fields.TextField(),
        }
    )

    image = fields.FileField(attr='image')


    status = fields.IntegerField(attr='status')
    id = fields.IntegerField(attr='id')

    title = fields.TextField(
        analyzer=html_strip,
        fields={
            'raw': fields.TextField(analyzer='keyword'),
            'suggest': fields.CompletionField(),
            
        }
    )

    description = fields.TextField(
        analyzer=html_strip,
        fields={
            'raw': fields.TextField(analyzer='keyword'),
            'suggest': fields.CompletionField(),
        }
    )
    created_on = fields.DateField(attr='created_on')
    

    class Django(object):
        """Inner nested class Django."""

        model = Twit  # The model associate with this Document