예제 #1
0
def get_search_settings():
    global SEARCH_SETTINGS

    # Use cached search settings if available
    if SEARCH_SETTINGS is not None:
        return SEARCH_SETTINGS

    # Process search settings
    search_models = get_search_models()
    SEARCH_SETTINGS = VosaeSettingsBuilder(settings=settings.ES_SETTINGS)
    for name, obj in search_models:
        docmapping = DocumentObjectField(_all=settings.ES_ALL_CONFIG, name=obj.Meta.document_type)
        for field in obj.Meta.fields:
            docmapping.add_property(field)
        SEARCH_SETTINGS.add_mapping(docmapping, obj.Meta.document_type)
    return SEARCH_SETTINGS
예제 #2
0
파일: search.py 프로젝트: tcpr1/vosae-app
def get_search_settings():
    global SEARCH_SETTINGS

    # Use cached search settings if available
    if SEARCH_SETTINGS is not None:
        return SEARCH_SETTINGS

    # Process search settings
    search_models = get_search_models()
    SEARCH_SETTINGS = VosaeSettingsBuilder(settings=settings.ES_SETTINGS)
    for name, obj in search_models:
        docmapping = DocumentObjectField(_all=settings.ES_ALL_CONFIG,
                                         name=obj.Meta.document_type)
        for field in obj.Meta.fields:
            docmapping.add_property(field)
        SEARCH_SETTINGS.add_mapping(docmapping, obj.Meta.document_type)
    return SEARCH_SETTINGS
예제 #3
0
파일: tests.py 프로젝트: CGenie/pyes
    def init_default_index(self):
        settings = SettingsBuilder({'index.number_of_replicas': 0,
                                     "index.number_of_shards": 1})
        from pyes.mappings import DocumentObjectField
        from pyes.mappings import IntegerField
        from pyes.mappings import NestedObject
        from pyes.mappings import StringField, DateField

        docmapping = DocumentObjectField(name=self.document_type)
        docmapping.add_property(
            StringField(name="parsedtext", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(
            StringField(name="name", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(
            StringField(name="title", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(IntegerField(name="position", store=True))
        docmapping.add_property(DateField(name="date", store=True))
        docmapping.add_property(StringField(name="uuid", store=True, index="not_analyzed"))
        nested_object = NestedObject(name="nested")
        nested_object.add_property(StringField(name="name", store=True))
        nested_object.add_property(StringField(name="value", store=True))
        nested_object.add_property(IntegerField(name="num", store=True))
        docmapping.add_property(nested_object)
        settings.add_mapping(docmapping)

        self.conn.ensure_index(self.index_name, settings)
예제 #4
0
    def init_default_index(self):
        settings = SettingsBuilder({
            'index.number_of_replicas': 0,
            "index.number_of_shards": 1
        })
        from pyes.mappings import DocumentObjectField
        from pyes.mappings import IntegerField
        from pyes.mappings import NestedObject
        from pyes.mappings import StringField, DateField

        docmapping = DocumentObjectField(name=self.document_type)
        docmapping.add_property(
            StringField(name="parsedtext",
                        store=True,
                        term_vector="with_positions_offsets",
                        index="analyzed"))
        docmapping.add_property(
            StringField(name="name",
                        store=True,
                        term_vector="with_positions_offsets",
                        index="analyzed"))
        docmapping.add_property(
            StringField(name="title",
                        store=True,
                        term_vector="with_positions_offsets",
                        index="analyzed"))
        docmapping.add_property(IntegerField(name="position", store=True))
        docmapping.add_property(DateField(name="date", store=True))
        docmapping.add_property(
            StringField(name="uuid", store=True, index="not_analyzed"))
        nested_object = NestedObject(name="nested")
        nested_object.add_property(StringField(name="name", store=True))
        nested_object.add_property(StringField(name="value", store=True))
        nested_object.add_property(IntegerField(name="num", store=True))
        docmapping.add_property(nested_object)
        settings.add_mapping(docmapping)

        self.conn.ensure_index(self.index_name, settings)
    def init_default_index(self):
        from pyes.helpers import SettingsBuilder
        settings = SettingsBuilder()
        from pyes.mappings import DocumentObjectField
        from pyes.mappings import IntegerField
        from pyes.mappings import NestedObject
        from pyes.mappings import StringField, DateField, BooleanField, GeoPointField, FloatField

        docmapping = DocumentObjectField(name=self.document_type)
        docmapping.add_property(
            StringField(name="description", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(
            StringField(name="name", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(StringField(name="tag", store=True, index="not_analyzed"))
        docmapping.add_property(IntegerField(name="age", store=True))
        docmapping.add_property(FloatField(name="price"))
        docmapping.add_property(DateField(name="date", store=True))
        docmapping.add_property(BooleanField(name="in_stock", store=True, index="not_analyzed"))
        docmapping.add_property(GeoPointField(name="position"))
        nested_object = NestedObject(name="metadata")
        nested_object.add_property(StringField(name="name", store=True))
        nested_object.add_property(StringField(name="value", store=True))
        nested_object.add_property(IntegerField(name="num", store=True))
        docmapping.add_property(nested_object)
        settings.add_mapping(docmapping)

        self.conn.ensure_index(self.index_name, settings)
def create_and_add_mapping(connection, index_name, type_name):
    from pyes.mappings import DocumentObjectField
    from pyes.mappings import IntegerField
    from pyes.mappings import NestedObject
    from pyes.mappings import StringField, DateField

    from pyes.helpers import SettingsBuilder

    settings = SettingsBuilder()
    docmapping = DocumentObjectField(name=type_name)
    docmapping.add_property(
        StringField(name="parsedtext", store=True, term_vector="with_positions_offsets", index="analyzed"))
    docmapping.add_property(
        StringField(name="name", store=True, term_vector="with_positions_offsets", index="analyzed"))
    docmapping.add_property(
        StringField(name="title", store=True, term_vector="with_positions_offsets", index="analyzed"))
    docmapping.add_property(IntegerField(name="position", store=True))
    docmapping.add_property(DateField(name="date", store=True))
    docmapping.add_property(StringField(name="uuid", store=True, index="not_analyzed"))
    nested_object = NestedObject(name="nested")
    nested_object.add_property(StringField(name="name", store=True))
    nested_object.add_property(StringField(name="value", store=True))
    nested_object.add_property(IntegerField(name="num", store=True))
    docmapping.add_property(nested_object)
    settings.add_mapping(docmapping)

    connection.ensure_index(index_name, settings)
예제 #7
0
    def init_default_index(self):
        from pyes.helpers import SettingsBuilder
        settings = SettingsBuilder()
        from pyes.mappings import DocumentObjectField
        from pyes.mappings import IntegerField
        from pyes.mappings import NestedObject
        from pyes.mappings import StringField, DateField, BooleanField, GeoPointField, FloatField

        docmapping = DocumentObjectField(name=self.document_type)
        docmapping.add_property(
            StringField(name="description",
                        store=True,
                        term_vector="with_positions_offsets",
                        index="analyzed"))
        docmapping.add_property(
            StringField(name="name",
                        store=True,
                        term_vector="with_positions_offsets",
                        index="analyzed"))
        docmapping.add_property(
            StringField(name="tag", store=True, index="not_analyzed"))
        docmapping.add_property(IntegerField(name="age", store=True))
        docmapping.add_property(FloatField(name="price"))
        docmapping.add_property(DateField(name="date", store=True))
        docmapping.add_property(
            BooleanField(name="in_stock", store=True, index="not_analyzed"))
        docmapping.add_property(GeoPointField(name="position"))
        nested_object = NestedObject(name="metadata")
        nested_object.add_property(StringField(name="name", store=True))
        nested_object.add_property(StringField(name="value", store=True))
        nested_object.add_property(IntegerField(name="num", store=True))
        docmapping.add_property(nested_object)
        settings.add_mapping(docmapping)

        self.conn.ensure_index(self.index_name, settings)
예제 #8
0
    def _get_mapping(self):
        """Build an ES optimized mapping for the given fields"""
        from pyes.mappings import DocumentObjectField, IntegerField, StringField, BooleanField, FloatField, DateField

        document = DocumentObjectField(name=self.document_type)
        for field in self.fields:
            st = field.storage_type
            if st == "unknown":
                #lets es detect the type
                continue
            elif st in ["string", "text"]:
                document.add_property(StringField(name=field.name))
            elif st == "integer":
                document.add_property(IntegerField(name=field.name))
            elif st == "boolean":
                document.add_property(BooleanField(name=field.name))
            elif st == "date":
                document.add_property(DateField(name=field.name))
            elif st == "float":
                document.add_property(FloatField(name=field.name))

        return document
예제 #9
0
    def _get_mapping(self):
        """Build an ES optimized mapping for the given fields"""
        from pyes.mappings import DocumentObjectField, IntegerField, StringField, BooleanField, FloatField, DateField

        document = DocumentObjectField(name=self.document_type)
        for field in self.fields:
            st = field.storage_type
            if st == "unknown":
                #lets es detect the type
                continue
            elif st in ["string", "text"]:
                document.add_property(StringField(name=field.name))
            elif st == "integer":
                document.add_property(IntegerField(name=field.name))
            elif st == "boolean":
                document.add_property(BooleanField(name=field.name))
            elif st == "date":
                document.add_property(DateField(name=field.name))
            elif st == "float":
                document.add_property(FloatField(name=field.name))

        return document