在不使用模型的情况下在bulbflow中进行选择性索引 [英] Selective indexing in bulbflow without using Models

查看:59
本文介绍了在不使用模型的情况下在bulbflow中进行选择性索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Neo4j上使用了bulbflow(python),并且试图在我的一部分键上添加 only 索引(目前,仅将名为'name'的键用于可选索引-基于查询).

I'm using bulbflow (python) with Neo4j and I'm trying to add an index only on a subset of my keys (for now, simply keys named 'name' for optional index-based lookup).

我不喜欢bulbflow模型(过于严格),并且我不知道如何在不更改代码的情况下进行选择性索引,因为自动索引"是全局设置-我看不到如何配置它根据密钥.

I don't love the bulbflow Models (too restrictive) and I couldn't figure out how to do selective indexing without changing code since the 'autoindex' is a global setting -- I don't see how to configure it based on the key.

有人做过这样的事情吗?

Has anyone done something like this?

-安德鲁

推荐答案

您可以通过将g.config.autoindex设置为False来禁用灯泡自动索引.

You can disable Bulbs auto-indexing by setting g.config.autoindex to False.

请参见 https://github.com/espeed/bulbs/blob/master/bulbs/config.py#L62

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.config.autoindex = False
>>> g.vertices.create(name="James")

在上面的示例中,这将导致name属性不会被自动索引.

In the example above, this will cause the name property not to be indexed automatically.

autoindex设置为False将切换为使用低级客户端的create_vertex()方法而不是create_indexed_vertex()方法:

Setting autoindex to False will switch to using the low-level client's create_vertex() method instead of the create_indexed_vertex() method:

请参见 https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L422

create_indexed_vertex()方法具有一个keys arg,可用于选择性索引:

The create_indexed_vertex() method has a keys arg, which you can use for selective indexing:

请参见 https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L424

这是Bulbs模型使用的低级client方法.通常,您不需要显式调用低级客户端方法,但是如果这样做,则可以通过在键arg中包含属性名称来选择性地索引属性.

This is the low-level client method used by Bulbs models. You generally don't need to explicitly call the low-level client methods, but if you do, you can selectively index properties by including the property name in the keys arg.

要在模型中选择索引属性,只需在模型定义中覆盖get_index_keys():

To selectively index properties in a Model, simply override get_index_keys() in your Model definition:

请参见 https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L383

默认情况下,灯泡模型会为所有属性编制索引.如果没有提供键,则所有属性都将被索引(例如TinkerPop/Blueprints中的索引).

By default, Bulbs models index all properties. If no keys are provided, then all properties are indexed (like in TinkerPop/Blueprints).

请参见Model _create()和get_bundle()方法:

See the Model _create() and get_bundle() methods:

  • _create() https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L583
  • get_bundle() https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L363
  • get_index_keys() https://github.com/espeed/bulbs/blob/master/bulbs/model.py#L383

要为通用顶点和边启用选择性索引,我更新了Bulbs通用顶点/边方法,以包含_keys arg,您可以在其中提供要索引的属性名称(键)列表.

To enable selective indexing for generic vertices and edges, I updated the Bulbs generic vertex/edge methods to include a _keys arg where you can supply a list of property names (keys) to index.

请参见 https://github.com/espeed/bulbs/commit/4fe39d5a76675020286ec9aeaa8e71d58a >

See https://github.com/espeed/bulbs/commit/4fe39d5a76675020286ec9aeaa8e71d58e3a432a

现在,要选择性地索引通用顶点/边上的属性,您可以提供要索引的属性名称列表:

Now, to selectively index properties on generic vertices/edges, you can supply a list of property names to index:

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.config.autoindex = False
>>> james = g.vertices.create(name="James", city="Dallas", _keys=["name"])
>>> julie = g.vertices.create(name="Julie", city="Dallas", _keys=["name"])
>>> g.edges.create(james, "knows", julie, timestamp=12345, someprop="somevalue", _keys=["someprop"])

在上面的示例中,将为每个顶点建立name属性的索引,并为边缘建立someprop的索引.请注意,citytimestamp不会被索引,因为这些属性名称未明确包含在索引键列表中.

In the example above, the name property will be indexed for each vertex, and someprop will be indexed for the edge. Note that city and timestamp will not be indexed because those property names were not explicitly included in the list of index keys.

如果g.config.autoindexTrue并且_keysNone(默认值),则将对所有属性进行索引(就像之前一样).

If g.config.autoindex is True and _keys is None (the default), all properties will be indexed (just like before).

如果g.config.autoindexFalse并且_keysNone,则不会索引任何属性.

If g.config.autoindex is False and _keys is None, no properties will be indexed.

如果将_keys显式设置为属性名称列表,则无论g.config.autoindexTrue还是False,都将仅对那些属性建立索引.

If _keys is explicitly set to a list of property names, only those properties will be indexed, regardless if g.config.autoindex is True or False.

请参见 https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L422

注意:如果您使用Neo4j Server,Rexster或Titan Server,并且所有图形数据库服务器的索引体系结构都处于自动状态,则自动索引的工作方式会有所不同.过去几个月的流量.似乎所有人都从手动索引系统转向自动索引.

NOTE: How auto-indexing works differs somewhat if you're using Neo4j Server, Rexster, or Titan Server, and the indexing architecture for all the graph-database servers has been in a state of flux for the past few months. It appears that all are moving from a manual-indexing system to auto-indexing.

对于直到最近才具有自动索引功能的图形数据库服务器(例如Neo4j Server),Bulbs通过使用数据库的低级手动索引方法的自定义Gremlin脚本启用了自动索引:

For graph-database servers that did not have auto-indexing capability until recently (e.g. Neo4j Server), Bulbs enabled auto-indexing via custom Gremlin scripts that used the database's low-level manual indexing methods:

  • https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L1008
  • https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/gremlin.groovy#L11

但是,Neo4j Server,TinkerPop/Rexster和Titan Server之间不推荐使用手动索引编制,因此Bulbs 0.4索引编制架构将相应地发生变化.通过像在SQL create table语句中一样预先声明索引键,仍然可以进行选择性索引.

However, manual indexing has been deprecated among Neo4j Server, TinkerPop/Rexster, and Titan Server so Bulbs 0.4 indexing architecture will change accordingly. Selective indexing will still be possible by declaring your index keys upfront, like you would in an SQL create table statement.

顺便说一句:您对模型有何限制? Bulbs Models(实际上是整个库)被设计为灵活的,因此您可以根据需要进行修改.

BTW: What about did you find restrictive about Models? Bulbs Models (actually the entire library) is designed to be flexible so you can modify it to whatever you need.

有关如何自定义灯泡模型的信息,请参见灯泡示例:

See the Lightbulb example for how to customize Bulbs Models: Is there a equivalent to commit in bulbs framework for neo4j

如果您有任何疑问,请告诉我.

Let me know if you have any questions.

这篇关于在不使用模型的情况下在bulbflow中进行选择性索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆