安装SMG
SMongo logo 2.png
仓库地址 SMongo零件
lua源码 核心模块
为了避免覆盖可能存在的同名模板,零件中的主模板叫做SMongo/ask,您可以根据本站情况将其移动到template:Ask,以使用{{ask}}

SMongo,全称是“Semantic-Style Mongo Query”,又名“傻芒果”,顾名思义(用傻瓜式的SMW语句查询JSON格式的MongoDB数据),他可以让你像使用Semantic MediaWiki{{#ask:}}函数一样查询灰机的MongoDB数据


更新

  • 2023/01/24:v 0.1.13更新:追加一种新的运算符&用以表示查询一个数字范围内的值(详见文档)。
  • 2022/04/07:v 0.1.12更新:现在指定的|table=xxxx可以正常生效了。
    • 在过去的版本中,指定的|table=xxxx只是作为schema的来源,并没有在查询条件中限定数据表的来源("_id"),现在这个问题已经被修复(由Gerley提出)。
  • 2021/11/28:v 0.1.11更新:修复|format=table时,输出数组字段报错的问题。
  • 2020/06/04:v 0.1.10更新:修复了一个tab/tabx模式下,同一列数据类型不一致导致的查询问题。
    • 优化了debug模式,现在为所有的debug选项和返回内容添加了collapse状态,以节约版面。
  • 2020/05/20:v 0.1.9更新:
    • 修正了多个key参与排序并单独制定升降序规则时(|sort = key1,key2,key3...)无法正确排序的bug,现在Smongo会默认require一个叫做Module:OrderedTable的组件以使前述问题不再出现。
    • 修复了debug模式下无法正确显示options(查询选项)的问题。
    • 修正了|order = reverse 无效的bug。
  • 2020/04/09:v 0.1.8更新:修正了|format = template模式下,debug无法正确显示template_args(模板参数)的问题。现在named_argsnamed args可以一样被识别为命名参开关了。
  • 2020/02/08:v 0.1.7更新:增加了“跳过”,即SMW中的|offset参数(Mongo中是skip)。
  • 2020/02/08:v 0.1.6更新:修复了查询条件><时的bug,现在能够正确生效了。
  • 2020/02/05:v 0.1.5更新:
    • 在查询条件中增加了@“正则表达式”模式和~“查找不存在字段”的模式
    • 同时修复了关于|format = template的一个bug。
    • 并增加了“#指定schema”模式,该模式下不用指定数据表的位置也可以进行查询,对应的,现在的SMongo已经不再强制您指定|table参数了。
    • 使用|format=count时,|limit=参数将不再生效,内置的limit=200也会随之解除。
    • 增加了#debug模式,现在可以通过|debug=1参数来获取dump出来的各种数值
    • 精简了代码片段,留下了更多的注释!
  • 2020/01/31:v 0.1.4更新,增加了|query= key::value1,value2即查询条件的“or”模式,同时将条件的分隔符由,修改为;,修复了一些小bug。
  • 2020/01/23:v 0.1.3更新,增加了|format=count——#统计功能
  • 2020/01/23:v 0.1.2更新,修复一个位于#多关键词排序功能的bug
  • 2020/01/21:v 0.1.1更新,新增#多关键词排序功能
  • 2020/01/20:v 0.1.0发布

关于

  • SMongo并不是一个真正意义上的框架或者MW插件,而是一个完全通过Lua模块撰写“轮子”,设计的初衷是为了向已经习惯了SMW查询又一时间难以学会Lua的游戏wiki编辑者们。是一种过渡工具,简化书写Lua查询MongoDB的难度。
  • 如果您对自己的能力充满信心,还是建议您尽快掌握真正的Lua语法来查询灰机的MongoDB数据。
  • 如上所述,由于SMongo是由Lua构建,因此某些地方受到限制,无法100%的复原SMW的语法,但很多地方却比SMW更加出色。

优点

  • 灵活:只需要搬运一个模板和模块既可以使用,语法完全继承了SMW的ask函数,对于熟悉SMW的人来说,可以快速上手。
  • 性能:由于使用lua查询MongoDB,性能有着质的飞跃,查询大批量数据几乎没有压力。
  • 限制较少:以query条件为例,由于性能问题,SMW限制了同时并列条件的最大数量(4个),在SMongo里,可以一口气写上40个条件也没问题。由于使用tabx存储、更新数据,也省去了#set之苦。
  • 便于修改:核心是用Lua模块编写,第一版只用了约200行代码实现,有能力的开发者也可以自行修改和扩展,以带来更多的特性。

已知的缺陷

  • 结果排序:SMongo的操作基于MediaWiki模块机制下frame.object对于模板函数frame.args的调取,由于性能问题,MW限制了frame.args的类型是metatable而不是真正的table,因此我们无法对metatable进行排序操作(ipairs),因此使用SMongo返回的查询结果可能与输入参数的顺序不一致。(原文:However, due to how Lua implements table iterators, iterating over arguments will return them in an unspecified order, and there's no way to know the original order as they appear in wikitext.Note that values in this table are always strings
    • 由此带来的问题:在format=template时,如果没有开启named args选项,模板内的参数序号也与查询时输入参数的顺序不一致
    • 解决方法:尽量使用named args=yes,使用命名参即可绕过这个问题。
  • 兼容性:由于MediaWiki上述metatable的限制,metatable中的所有element都是string类型,而灰机目前支持的JSON、tab、tabx三种格式的MongoDB入库方法,都是基于JSON格式的数据标准,因此默认的查询无法保证能够100%匹配数据库中正确的数据类型(number、boolean等)。可以通过指定schema来绕过这一限制,详见下文


tab/tabx模式(推荐)

准备数据表

参见:h:帮助:MongoDB支持

您需要在data:xxxxx.tabdata:xxxxx.tabx的页面上传一个数据表,注意,您可以在excel中编辑数据,但是需要注意以下事项:

  • 表头(第一行)必须是英文,不能以空格或下划线开头;
  • 数据中不能出现制表符和换行符(excel单元格内的硬换行);
  • 单元格内的字符长度不能超过400;

否则页面parser在保存时会抛出异常,并注明数据地址,第一个数字表示行,第二个数字是列(序号从0开始索引)

本文档中使用的数据表为:Data:Testdata.tabx

指定数据表

tab/tabx格式的数据在使用Smongo时必须声明所查询的数据表,格式如下: |table = xxxxxxx.tabx

该功能用来读取此数据表的schema,以正确匹配查询数据的类型(否则默认查询都是string)。

例子

{{ask
|table = Testdata.tabx
...
}}

JSON模式(进阶)

通过为SMongo指定一个schema表,可以完全解锁全部限制,发挥100%的功能,在查询JSON模式的数据时,无需书写|table = xxxx.tab/tabx,否则无法开启JSON模式。但一样可以查询到.tab/.tabx里的数据,(如果有的话)

方法如下:

指定schema

通过在Module:Query/data页面指定一个schema,方法如下:

  • 在本站的Module:Query/data创建一个名为schema的table
  • 将你站所有待查字段的type进行声明,类似在SMW使用过程中,通过在property页面指定字段的has type属性。

下面是一个schema的例子:

实例:hearthstone:Module:Query/data
local p = {}

p.schema = {
	['artist'] ='string',
	['attack'] = 'number',
	['collectible'] ='boolean',
	['cost'] = 'number',
	['dbfId'] = 'number',
	['flavor_zhTW'] = 'string',
	['flavor_jaJP'] = 'string',
	['flavor_enUS'] = 'string',
	['health'] = 'number',
	['id'] = 'string',
}
return p

搬运模板

所有SMongo的模板集成在Template:AskModule:Query

重命名

为了避免覆盖可能存在的同名模板,零件中的主模板叫做SMongo/ask,您可以根据本站情况将其移动到template:Ask,以使用{{ask}}

调用

默认引用{{SMongo/Ask}}模板,您也可以自己重定向到{{ask}},然后就像使用普通的模板一样,为ask模板传参数即可,例如:

{{ask
  |table = Testdata.tabx
  |query = Toy Category::funko; Funko Series::1; Is Released::true; Year::2012
  |?Has Name = 名字
  |?Funko Franchise = 系列
}}

查询

与SMW的{{#ask:}}函数基本一致

参数 说明 备注
table 必须指定一个tabx的数据表,否则有可能无法获取正确的schema 默认模式下必须,开启schema模式后不写
query ask的查询条件,由于parser的限制,移除了方括号的写法
采用 key1::value1;key2::value2;..的形式
query = Toy Category::funko; Funko Seriers::1; Is Released::true; Year::2012
limit 返回的数据上限,注意,多余部分会隐去,不会像SMW那样出现“查看更多” 默认200
sort 排序的关键词,不用加“?”,但是注意大小写,详见#排序 默认是_id
order 排序方法,详见#排序 默认1
class 为默认返回表格结果添加的class,可以用空格隔开多个class,不用引号 class = table table-stripped
mainlabel 默认返回表格的 第一格中所显示的文字 默认为空
format 目前仅支持tabletemplatecount 默认是table
intro 默认表格前的内容
outro 默认表格后的内容
default 查询结果为空时返回的内容
headers headers = hide隐藏第一行
offset 跳过的结果,默认是0
  • linksearchlabel两个鸡肋的功能我删掉了,实际使用SMW的过程中,大家都在千方百计的隐藏掉他们

指定数据表

|table = xxxxxxx.tabx

用来读取表的schema,以正确匹配查询数据的类型,支持tabtabx,JSON可能会有问题(类型不匹配,默认查询都是string)。如果目标表格不存在会返回错误提示。

例子

{{ask
|table = Testdata.tabx
...
}}

书写条件

|query = key1::value1;key2::value2;...

为了避免被MediaWiki的parser解析为内链,这里没有使用SMW的条件书写方法,而是用字典的形式。

例子

{{ask
...
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
...
}}
  • 如果存储的value是一个序列(JSON中的list)譬如list = [ value1, value2, value3 ],那么key1::value1依然可以查询到结果(类似SMW查询被|sep的数据)
  • 单一查询条件支持多个value并列,用,进行分割,彼此之间是“or”的关系,例如|query = key1::value1,value2;,可以同时查找key1的值为(或包含)value1或value2的数据
  • SMongo支持在条件中使用!+<>,用法与SMW一致。

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Has Name::异鬼,魔山
|?Has Name = Has Name 
|?Funko Franchise = 系列
}}

结果

Has Name系列
Data:Testdata.tabx#10异鬼Game of Thrones
Data:Testdata.tabx#109魔山Game of Thrones
Data:Testdata.tabx#11异鬼Game of Thrones
Data:Testdata.tabx#110魔山Game of Thrones
Data:Testdata.tabx#42魔山Game of Thrones
Data:Testdata.tabx#70魔山Game of Thrones

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Year::2012,2016
|?Has Name = Has Name 
|?Year = 年份
}}

结果

Has Name年份
Data:Testdata.tabx#1提利昂·兰尼斯特2012
Data:Testdata.tabx#10异鬼2012
Data:Testdata.tabx#104丹妮莉丝·坦格利安和卓耿2016
Data:Testdata.tabx#2提利昂·兰尼斯特2012
Data:Testdata.tabx#3奈德·史塔克2012
Data:Testdata.tabx#4奈德·史塔克2012
Data:Testdata.tabx#49玛格丽·提利尔2016
Data:Testdata.tabx#5丹妮莉丝·坦格利安2012
Data:Testdata.tabx#50波隆2016
Data:Testdata.tabx#51乔拉·莫尔蒙2016
Data:Testdata.tabx#52史坦尼斯·拜拉席恩2016
Data:Testdata.tabx#53梅丽珊卓2016
Data:Testdata.tabx#54梅丽珊卓2016
Data:Testdata.tabx#55鹰身女妖之子2016
Data:Testdata.tabx#56夜王2016
Data:Testdata.tabx#57夜王2016
Data:Testdata.tabx#60无垢者2016
Data:Testdata.tabx#61卓耿2016
Data:Testdata.tabx#62雷哥2016
Data:Testdata.tabx#63强壮的玛格2016
Data:Testdata.tabx#7丹妮莉丝·坦格利安2012
Data:Testdata.tabx#8卓戈卡奥2012
Data:Testdata.tabx#9猎狗2012

查询字段

|?param = xxx

?param 作为查找的字段,xxx会成为表头显示的文字(不可省略)

  • 注意,查的key都得是指定的tabx里有的,没有的当然没法查了,注意这里查的不是真正的SMW数据,所以也就不存在什么[[category:]],[[concept:]]
  • 等号“=”不能省,值不能为空,否则mw.frame不会将其识别为参数

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
|?Has Name = Has Name 
|?Funko Franchise = 系列
}}

结果

Has Name系列
Data:Testdata.tabx#1提利昂·兰尼斯特Game of Thrones
Data:Testdata.tabx#10异鬼Game of Thrones
Data:Testdata.tabx#2提利昂·兰尼斯特Game of Thrones
Data:Testdata.tabx#3奈德·史塔克Game of Thrones
Data:Testdata.tabx#4奈德·史塔克Game of Thrones
Data:Testdata.tabx#5丹妮莉丝·坦格利安Game of Thrones
Data:Testdata.tabx#7丹妮莉丝·坦格利安Game of Thrones
Data:Testdata.tabx#8卓戈卡奥Game of Thrones
Data:Testdata.tabx#9猎狗Game of Thrones
  • 通过?param =xxx的形式可以指定返回表格中对应的文字

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
|?Has Name = 名字
|?Funko Franchise = 系列
|limit =5
|class= sortable
|mainlabel = funko!
}}

结果

funko!系列名字
Data:Testdata.tabx#1Game of Thrones提利昂·兰尼斯特
Data:Testdata.tabx#10Game of Thrones异鬼
Data:Testdata.tabx#2Game of Thrones提利昂·兰尼斯特
Data:Testdata.tabx#3Game of Thrones奈德·史塔克
Data:Testdata.tabx#4Game of Thrones奈德·史塔克

排除条件(!)

key::!value

例子

{{ask
|table = Testdata.tabx
|query = Year::!2011
|?Has Name = Has Name 
|?Funko Franchise = Franchise
|?Year = Year
|limit =20
|mainlabel = -
}}

结果

FranchiseHas NameYear
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones异鬼2012
Game of Thrones卡奥卡丽熙和雷哥2015
Game of Thrones琼恩和布兰2017
Game of Thrones琼恩和拉姆斯2017
Game of Thrones乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯2018
Game of Thrones丹妮莉丝·坦格利安和卓耿2016
Game of Thrones夜王和冰龙版韦赛利昂2018
Game of Thrones异鬼和尸鬼马2019
Game of Thrones琼恩·雪诺和雷哥2019
Game of Thrones丹妮莉丝·坦格利安和卓耿2019
Game of Thrones魔山2019
Game of Thrones异鬼2013
Game of Thrones魔山2019
Game of Thrones席恩·葛雷乔伊2019
Game of Thrones艾莉亚·史塔克0
Game of Thrones夜王2019
Game of Thrones夜王2019
Game of Thrones布兰·史塔克2019
Game of Thrones琼恩·雪诺2019

任意条件(+)

key::+

例子

{{ask
|table = Testdata.tabx
|query = Year::+
|?Has Name = Has Name 
|?Funko Franchise = Franchise
|?Year = Year
|limit =20
|mainlabel = -
}}

结果

FranchiseHas NameYear
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones异鬼2012
Game of Thrones卡奥卡丽熙和雷哥2015
Game of Thrones琼恩和布兰2017
Game of Thrones琼恩和拉姆斯2017
Game of Thrones乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯2018
Game of Thrones丹妮莉丝·坦格利安和卓耿2016
Game of Thrones夜王和冰龙版韦赛利昂2018
Game of Thrones异鬼和尸鬼马2019
Game of Thrones琼恩·雪诺和雷哥2019
Game of Thrones丹妮莉丝·坦格利安和卓耿2019
Game of Thrones魔山2019
Game of Thrones异鬼2013
Game of Thrones魔山2019
Game of Thrones席恩·葛雷乔伊2019
Game of Thrones艾莉亚·史塔克0
Game of Thrones夜王2019
Game of Thrones夜王2019
Game of Thrones布兰·史塔克2019
Game of Thrones琼恩·雪诺2019

不存在的条件(~)

当有一些数据根本没有某个字段时,我们要如何查找他们(查询空气!这是SMW做不到的): key::~

例子

{{ask
|table = Testdata.tabx
|query = Has Link::~;Has Name::+
|?Has Name = 名字
|limit =20
}}

结果

名字
Data:Testdata.tabx#1提利昂·兰尼斯特
Data:Testdata.tabx#10异鬼
Data:Testdata.tabx#100卡奥卡丽熙和雷哥
Data:Testdata.tabx#101琼恩和布兰
Data:Testdata.tabx#102琼恩和拉姆斯
Data:Testdata.tabx#103乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯
Data:Testdata.tabx#104丹妮莉丝·坦格利安和卓耿
Data:Testdata.tabx#105夜王和冰龙版韦赛利昂
Data:Testdata.tabx#106异鬼和尸鬼马
Data:Testdata.tabx#107琼恩·雪诺和雷哥
Data:Testdata.tabx#108丹妮莉丝·坦格利安和卓耿
Data:Testdata.tabx#109魔山
Data:Testdata.tabx#11异鬼
Data:Testdata.tabx#110魔山
Data:Testdata.tabx#111席恩·葛雷乔伊
Data:Testdata.tabx#112艾莉亚·史塔克
Data:Testdata.tabx#113夜王
Data:Testdata.tabx#114夜王
Data:Testdata.tabx#115布兰·史塔克
Data:Testdata.tabx#116琼恩·雪诺

大于 or 小于(</>)

key::>value

key::<value

例子

{{ask
|table = Testdata.tabx
|query = Year::>2010
|?Has Name = Has Name 
|?Funko Franchise = Franchise
|?Year = Year
|sort = Year
|order = 1
|limit =20
|mainlabel = -
}}

结果

FranchiseHas NameYear
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones丹妮莉丝·坦格利安2012
Game of Thrones奈德·史塔克2012
Game of Thrones卓戈卡奥2012
Game of Thrones奈德·史塔克2012
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones丹妮莉丝·坦格利安2012
Game of Thrones猎狗2012
Game of Thrones异鬼2012
Game of Thrones罗柏·史塔克2013
Game of Thrones詹姆·兰尼斯特2013
Game of Thrones琼恩·雪诺2013
Game of Thrones琼恩·雪诺2013
Game of Thrones丹妮莉丝·坦格利安2013
Game of Thrones艾莉亚·史塔克2013
Game of Thrones异鬼2013
Game of Thrones琼恩·雪诺2013
Game of Thrones琼恩·雪诺2014
Game of Thrones提利昂·兰尼斯特2014
Game of Thrones山姆威尔·塔利2014

在一个数字范围内(&)

key::&value1~value2 等价于

[key] = {
    ['&gte'] = value1,
    ['&lte'] = value2
}

例子

{{ask
|table = Testdata.tabx
|query = Year::&2010~2016
|?Has Name = Has Name 
|?Funko Franchise = Franchise
|?Year = Year
|sort = Year
|order = 1
|limit =20
|mainlabel = -
}}

结果

FranchiseHas NameYear
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones丹妮莉丝·坦格利安2012
Game of Thrones奈德·史塔克2012
Game of Thrones卓戈卡奥2012
Game of Thrones奈德·史塔克2012
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones丹妮莉丝·坦格利安2012
Game of Thrones猎狗2012
Game of Thrones异鬼2012
Game of Thrones罗柏·史塔克2013
Game of Thrones詹姆·兰尼斯特2013
Game of Thrones琼恩·雪诺2013
Game of Thrones琼恩·雪诺2013
Game of Thrones丹妮莉丝·坦格利安2013
Game of Thrones艾莉亚·史塔克2013
Game of Thrones异鬼2013
Game of Thrones琼恩·雪诺2013
Game of Thrones琼恩·雪诺2014
Game of Thrones提利昂·兰尼斯特2014
Game of Thrones山姆威尔·塔利2014

使用正则表达式(@)

key::@re

下面这个例子是在查找所有叫 xxxx·兰尼斯特的Funko玩偶

{{ask
|table = Testdata.tabx
|query = Has Name::@.*兰尼斯特
|?Has Name = Has Name 
|?Funko Franchise = Franchise
|?Year = Year
|sort = Year
|order = 1
|limit =20
|mainlabel = -
}}

结果

FranchiseHas NameYear
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones提利昂·兰尼斯特2012
Game of Thrones詹姆·兰尼斯特2013
Game of Thrones提利昂·兰尼斯特2014
Game of Thrones泰温·兰尼斯特2014
Game of Thrones瑟曦·兰尼斯特2014
Game of Thrones泰温·兰尼斯特2014
Game of Thrones詹姆·兰尼斯特2015
Game of Thrones瑟曦·兰尼斯特2017
Game of Thrones提利昂·兰尼斯特2017
Game of Thrones提利昂·兰尼斯特2019
Game of Thrones瑟曦·兰尼斯特2019

结果

统计

|format = count 例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Is Released::true;Limit::!通版
|?Has Name = 名字
|?Funko Franchise = 系列
|?Year = 年份
|format =count
|mainlabel = funko!
}}

结果: 37


排序

|sort = <sort-key>

|order = <order>

order = 1 |asc | ascending | -1 | desc | descending | reverse
  • 升序:1,asc,ascending
  • 反序:-1,desc,descending,reverse

不支持乱序(随机),因为Mongo没有……

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Is Released::true;Limit::!通版
|?Has Name = 名字
|?Funko Franchise = 系列
|?Year = 年份
|sort =Year
|order = reverse
|limit = 20
|class= sortable
|mainlabel = funko!
}}

结果

funko!系列名字年份
Data:Testdata.tabx#94Game of Thrones娜梅莉亚2019
Data:Testdata.tabx#59Game of Thrones夜王2019
Data:Testdata.tabx#91Game of Thrones夜王2019
Data:Testdata.tabx#93Game of Thrones艾莉亚·史塔克2019
Data:Testdata.tabx#79Game of Thrones奥莲娜·雷德温2018
Data:Testdata.tabx#95Game of Thrones乔治·马丁2018
Data:Testdata.tabx#80Game of Thrones贝里·唐德利恩2018
Data:Testdata.tabx#69Game of Thrones巨人克星托蒙德2018
Data:Testdata.tabx#85Game of Thrones森林之子2018
Data:Testdata.tabx#75Game of Thrones尸鬼巨人2018
Data:Testdata.tabx#103Game of Thrones乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯2018
Data:Testdata.tabx#72Game of Thrones莱安娜·莫尔蒙2017
Data:Testdata.tabx#58Game of Thrones夜王2017
Data:Testdata.tabx#70Game of Thrones魔山2017
Data:Testdata.tabx#101Game of Thrones琼恩和布兰2017
Data:Testdata.tabx#73Game of Thrones贾坤2017
Data:Testdata.tabx#63Game of Thrones强壮的玛格2016
Data:Testdata.tabx#61Game of Thrones卓耿2016
Data:Testdata.tabx#54Game of Thrones梅丽珊卓2016
Data:Testdata.tabx#57Game of Thrones夜王2016

多关键词排序

|sort = key1, key2

|order = order1,order2

支持多个参数排序,关键词用,隔开(依然与SMW一致)

  • order的数量少于sort的时候,会自动用“1”(升序)补齐
  • order的数量多于sort的时候,多余的部分无效

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Is Released::true;Limit::!通版
|?Has Name = 名字
|?Year = 年份
|?Funko Series = 系列
|?Funko Index = index
|sort =  Year,Funko Index,Funko Series
|order = reverse,asc,reverse
|limit = 20
}}

结果

系列index名字年份
Data:Testdata.tabx#59644夜王2019
Data:Testdata.tabx#911074夜王2019
Data:Testdata.tabx#949976娜梅莉亚2019
Data:Testdata.tabx#931076艾莉亚·史塔克2019
Data:Testdata.tabx#103980乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯2018
Data:Testdata.tabx#95991乔治·马丁2018
Data:Testdata.tabx#69753巨人克星托蒙德2018
Data:Testdata.tabx#75860尸鬼巨人2018
Data:Testdata.tabx#79864奥莲娜·雷德温2018
Data:Testdata.tabx#80865贝里·唐德利恩2018
Data:Testdata.tabx#85969森林之子2018
Data:Testdata.tabx#101980琼恩和布兰2017
Data:Testdata.tabx#58644夜王2017
Data:Testdata.tabx#70754魔山2017
Data:Testdata.tabx#72756莱安娜·莫尔蒙2017
Data:Testdata.tabx#73757贾坤2017
Data:Testdata.tabx#54642梅丽珊卓2016
Data:Testdata.tabx#57644夜王2016
Data:Testdata.tabx#61646卓耿2016
Data:Testdata.tabx#63648强壮的玛格2016

用隐藏关键词排序

甚至可以把没有查询的字段拿来排序(前提是存在),这一点SMW是做不到的,下面的例子里使用了没有请求的字段Funko Index作为排序关键词

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Is Released::true;Limit::!通版
|?Has Name = 名字
|?Funko Franchise = 主题
|?Year = 年份
|?Funko Series = 系列
|sort =Year,Funko Index
|order = reverse,asc
|limit = 20
}}

结果

主题系列年份名字
Data:Testdata.tabx#59Game of Thrones62019夜王
Data:Testdata.tabx#91Game of Thrones102019夜王
Data:Testdata.tabx#94Game of Thrones992019娜梅莉亚
Data:Testdata.tabx#93Game of Thrones102019艾莉亚·史塔克
Data:Testdata.tabx#103Game of Thrones982018乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯
Data:Testdata.tabx#95Game of Thrones992018乔治·马丁
Data:Testdata.tabx#69Game of Thrones72018巨人克星托蒙德
Data:Testdata.tabx#75Game of Thrones82018尸鬼巨人
Data:Testdata.tabx#79Game of Thrones82018奥莲娜·雷德温
Data:Testdata.tabx#80Game of Thrones82018贝里·唐德利恩
Data:Testdata.tabx#85Game of Thrones92018森林之子
Data:Testdata.tabx#101Game of Thrones982017琼恩和布兰
Data:Testdata.tabx#58Game of Thrones62017夜王
Data:Testdata.tabx#70Game of Thrones72017魔山
Data:Testdata.tabx#72Game of Thrones72017莱安娜·莫尔蒙
Data:Testdata.tabx#73Game of Thrones72017贾坤
Data:Testdata.tabx#54Game of Thrones62016梅丽珊卓
Data:Testdata.tabx#57Game of Thrones62016夜王
Data:Testdata.tabx#61Game of Thrones62016卓耿
Data:Testdata.tabx#63Game of Thrones62016强壮的玛格

隐藏第一列

|mainlabel =-

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
|?Has Name = 名字
|?Funko Franchise = 系列
|limit =5
|mainlabel = -
}}

结果

系列名字
Game of Thrones提利昂·兰尼斯特
Game of Thrones异鬼
Game of Thrones提利昂·兰尼斯特
Game of Thrones奈德·史塔克
Game of Thrones奈德·史塔克

隐藏第一行

|headers=hide

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
|?Has Name = 名字
|?Funko Franchise = 系列
|limit =5
|mainlabel = -
|headers =hide
}}

结果

Game of Thrones提利昂·兰尼斯特
Game of Thrones异鬼
Game of Thrones提利昂·兰尼斯特
Game of Thrones奈德·史塔克
Game of Thrones奈德·史塔克

用模板封装

SMongo支持使用template作为format,|format=template 与SMW的ask函数基本一致

  • 注意,默认为序号参,{{{1}}}是数据列的id,查询返回的结果是从{{{2}}}开始(与SMW一致)
参数 说明 备注
template 主模板,返回的每个结果都会被扔进这个模板处理 必须
introtemplate 前置模板
outrotemplate 后置模板
userparam 添加用户自定义的参数,模板内引用方法为{{{userparam}}}
named args 只要等号后值不为空,即可开启命名参数模式,模板内的参数形如{{{?Has Name}}}与SMW完全一致

例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
|?Has Name = y
|?Funko Franchise = y
|limit =20
|format =template
|named args = yes
|template = ask/1
|introtemplate =ask/0
|outrotemplate =ask/2
}}

结果

模板:Ask/0 - intro 模板
姓名:提利昂·兰尼斯特
Game of Thrones
姓名:异鬼
Game of Thrones
姓名:提利昂·兰尼斯特
Game of Thrones
姓名:奈德·史塔克
Game of Thrones
姓名:奈德·史塔克
Game of Thrones
姓名:丹妮莉丝·坦格利安
Game of Thrones
姓名:丹妮莉丝·坦格利安
Game of Thrones
姓名:卓戈卡奥
Game of Thrones
姓名:猎狗
Game of Thrones
模板:Ask/2 - outro 模板

debug模式

在参数中加如|debug=1 (其实等于几都行)来开启debug模式,获得各种参数,


例子

{{ask
|table = Testdata.tabx
|query = Toy Category::funko;Funko Series::1;Is Released::true;Year::2012
|?Has Name = y
|?Funko Franchise = y
|limit =5
|debug=1
}}

结果

yy
Data:Testdata.tabx#1Game of Thrones提利昂·兰尼斯特
Data:Testdata.tabx#10Game of Thrones异鬼
Data:Testdata.tabx#2Game of Thrones提利昂·兰尼斯特
Data:Testdata.tabx#3Game of Thrones奈德·史塔克
Data:Testdata.tabx#4Game of Thrones奈德·史塔克
DEBUG信息
查询条件(query)
table#1 {
 ["Funko Series"] = table#2 {
   ["$in"] = table#3 {
     1,
   },
 },
 ["Is Released"] = table#4 {
   ["$in"] = table#5 {
     true,
     1,
   },
 },
 ["Toy Category"] = table#6 {
   ["$in"] = table#7 {
     "funko",
   },
 },
 ["Year"] = table#8 {
   ["$in"] = table#9 {
     2012,
   },
 },
 ["_id"] = table#10 {
   ["$regex"] = "Data:Testdata.tabx#.*",
 },
}
查询选项(options)
table#1 {
 ["limit"] = 5,
 ["sort"] = table#2 {
   ["_id"] = 1,
 },
}
查询返回数据(nil为空)
table#1 {
 table#2 {
   ["Data Toys"] = "Data:Funko1",
   ["Funko Category"] = "Funko Pop!",
   ["Funko Franchise"] = "Game of Thrones",
   ["Funko Index"] = 1,
   ["Funko Series"] = 1,
   ["Has Image"] = "01权力的游戏funkopop系列1提利昂.jpg",
   ["Has Link"] = "提利昂·兰尼斯特",
   ["Has Name"] = "提利昂·兰尼斯特",
   ["In Bundle"] = false,
   ["Is Released"] = 1,
   ["Limit"] = "通版",
   ["Toy Category"] = "funko",
   ["Year"] = 2012,
   ["_id"] = "Data:Testdata.tabx#1",
   ["wiki_index"] = 1,
 },
 table#3 {
   ["Data Toys"] = "Data:Funko10",
   ["Funko Category"] = "Funko Pop!",
   ["Funko Franchise"] = "Game of Thrones",
   ["Funko Index"] = 6,
   ["Funko Series"] = 1,
   ["Has Image"] = "06权力的游戏funkopop系列1异鬼.jpg",
   ["Has Link"] = "异鬼",
   ["Has Name"] = "异鬼",
   ["In Bundle"] = false,
   ["Is Released"] = 1,
   ["Limit"] = "通版",
   ["Toy Category"] = "funko",
   ["Year"] = 2012,
   ["_id"] = "Data:Testdata.tabx#10",
   ["wiki_index"] = 10,
 },
 table#4 {
   ["Data Toys"] = "Data:Funko2",
   ["Funko Category"] = "Funko Pop!",
   ["Funko Franchise"] = "Game of Thrones",
   ["Funko Index"] = 1,
   ["Funko Series"] = 1,
   ["Has Features"] = "脸上有疤",
   ["Has Image"] = "01权力的游戏funkopop系列1提利昂刀疤.png",
   ["Has Link"] = "提利昂·兰尼斯特",
   ["Has Name"] = "提利昂·兰尼斯特",
   ["In Bundle"] = false,
   ["Is Released"] = 1,
   ["Limit"] = "PopCultcha",
   ["Toy Category"] = "funko",
   ["Year"] = 2012,
   ["_id"] = "Data:Testdata.tabx#2",
   ["wiki_index"] = 2,
 },
 table#5 {
   ["Data Toys"] = "Data:Funko3",
   ["Funko Category"] = "Funko Pop!",
   ["Funko Franchise"] = "Game of Thrones",
   ["Funko Index"] = 2,
   ["Funko Series"] = 1,
   ["Has Image"] = "02权力的游戏funkopop系列1奈德.jpg",
   ["Has Link"] = "奈德·史塔克",
   ["Has Name"] = "奈德·史塔克",
   ["In Bundle"] = false,
   ["Is Released"] = 1,
   ["Limit"] = "通版",
   ["Toy Category"] = "funko",
   ["Year"] = 2012,
   ["_id"] = "Data:Testdata.tabx#3",
   ["wiki_index"] = 3,
 },
 table#6 {
   ["Data Toys"] = "Data:Funko4",
   ["Funko Category"] = "Funko Pop!",
   ["Funko Franchise"] = "Game of Thrones",
   ["Funko Index"] = 2,
   ["Funko Series"] = 1,
   ["Has Features"] = "断头",
   ["Has Image"] = "02权力的游戏funkopop系列1断头奈德SDCC2013.jpg",
   ["Has Link"] = "奈德·史塔克",
   ["Has Name"] = "奈德·史塔克",
   ["In Bundle"] = false,
   ["Is Released"] = 1,
   ["Limit"] = "SDCC",
   ["Toy Category"] = "funko",
   ["Year"] = 2012,
   ["_id"] = "Data:Testdata.tabx#4",
   ["wiki_index"] = 4,
 },
}
传入的参数(args)
table#1 {
 metatable = table#2
 ["?Funko Franchise"] = "y",
 ["?Has Name"] = "y",
 ["debug"] = "1",
 ["limit"] = "5",
 ["query"] = "Toy Category::funko;Funko Series::1;Is Released::true;Year::2012",
 ["table"] = "Testdata.tabx",
}
传入的模板参数(format=template)
table#1 { }
模板参数是否为命名参(namedArgs)
"unkown"
Schema Table
table#1 {
 table#2 {
   ["name"] = "datatoys",
   ["title"] = table#3 {
     ["en"] = "Data Toys",
   },
   ["type"] = "string",
 },
 table#4 {
   ["name"] = "wiki_index",
   ["title"] = table#5 {
     ["en"] = "wiki_index",
   },
   ["type"] = "number",
 },
 table#6 {
   ["name"] = "toycategory",
   ["title"] = table#7 {
     ["en"] = "Toy Category",
   },
   ["type"] = "string",
 },
 table#8 {
   ["name"] = "funkoindex",
   ["title"] = table#9 {
     ["en"] = "Funko Index",
   },
   ["type"] = "number",
 },
 table#10 {
   ["name"] = "funkofranchise",
   ["title"] = table#11 {
     ["en"] = "Funko Franchise",
   },
   ["type"] = "string",
 },
 table#12 {
   ["name"] = "funkoseries",
   ["title"] = table#13 {
     ["en"] = "Funko Series",
   },
   ["type"] = "number",
 },
 table#14 {
   ["name"] = "isreleased",
   ["title"] = table#15 {
     ["en"] = "Is Released",
   },
   ["type"] = "boolean",
 },
 table#16 {
   ["name"] = "hasname",
   ["title"] = table#17 {
     ["en"] = "Has Name",
   },
   ["type"] = "string",
 },
 table#18 {
   ["name"] = "haslink",
   ["title"] = table#19 {
     ["en"] = "Has Link",
   },
   ["type"] = "string",
 },
 table#20 {
   ["name"] = "limit",
   ["title"] = table#21 {
     ["en"] = "Limit",
   },
   ["type"] = "string",
 },
 table#22 {
   ["name"] = "year",
   ["title"] = table#23 {
     ["en"] = "Year",
   },
   ["type"] = "number",
 },
 table#24 {
   ["name"] = "funkocategory",
   ["title"] = table#25 {
     ["en"] = "Funko Category",
   },
   ["type"] = "string",
 },
 table#26 {
   ["name"] = "inbundle",
   ["title"] = table#27 {
     ["en"] = "In Bundle",
   },
   ["type"] = "boolean",
 },
 table#28 {
   ["name"] = "hasimage",
   ["title"] = table#29 {
     ["en"] = "Has Image",
   },
   ["type"] = "string",
 },
 table#30 {
   ["name"] = "hasfeatures",
   ["title"] = table#31 {
     ["en"] = "Has Features",
   },
   ["type"] = "string",
 },
 table#32 {
   ["name"] = "special",
   ["title"] = table#33 {
     ["en"] = "Special",
   },
   ["type"] = "string",
 },
 table#34 {
   ["name"] = "specialsize",
   ["title"] = table#35 {
     ["en"] = "Special Size",
   },
   ["type"] = "string",
 },
}
检查代码1
"101"
检查代码2
"101"


DEBUG信息
查询条件(query)
table#1 {
 [" Funko Series"] = table#2 {
   ["$in"] = table#3 {
     1,
   },
 },
 [" Is Released"] = table#4 {
   ["$in"] = table#5 {
     true,
     1,
   },
 },
 ["Toy Category"] = table#6 {
   ["$in"] = table#7 {
     "funko",
   },
 },
 ["_id"] = table#8 {
   ["$regex"] = "Data:Testdata.tabx#.*",
 },
}
查询选项(options)
table#1 {
 ["limit"] = 200,
 ["sort"] = table#2 {
   ["_id"] = 1,
 },
}
查询返回数据(nil为空)
table#1 { }
传入的参数(args)
table#1 {
 metatable = table#2
 ["?Funko Franchise"] = "系列",
 ["?Has Name"] = "名字",
 ["debug"] = "1",
 ["query"] = "Toy Category::funko; Funko Series::1; Is Released::true;",
 ["table"] = "Testdata.tabx",
}
传入的模板参数(format=template)
table#1 { }
模板参数是否为命名参(namedArgs)
"unkown"
Schema Table
table#1 {
 table#2 {
   ["name"] = "datatoys",
   ["title"] = table#3 {
     ["en"] = "Data Toys",
   },
   ["type"] = "string",
 },
 table#4 {
   ["name"] = "wiki_index",
   ["title"] = table#5 {
     ["en"] = "wiki_index",
   },
   ["type"] = "number",
 },
 table#6 {
   ["name"] = "toycategory",
   ["title"] = table#7 {
     ["en"] = "Toy Category",
   },
   ["type"] = "string",
 },
 table#8 {
   ["name"] = "funkoindex",
   ["title"] = table#9 {
     ["en"] = "Funko Index",
   },
   ["type"] = "number",
 },
 table#10 {
   ["name"] = "funkofranchise",
   ["title"] = table#11 {
     ["en"] = "Funko Franchise",
   },
   ["type"] = "string",
 },
 table#12 {
   ["name"] = "funkoseries",
   ["title"] = table#13 {
     ["en"] = "Funko Series",
   },
   ["type"] = "number",
 },
 table#14 {
   ["name"] = "isreleased",
   ["title"] = table#15 {
     ["en"] = "Is Released",
   },
   ["type"] = "boolean",
 },
 table#16 {
   ["name"] = "hasname",
   ["title"] = table#17 {
     ["en"] = "Has Name",
   },
   ["type"] = "string",
 },
 table#18 {
   ["name"] = "haslink",
   ["title"] = table#19 {
     ["en"] = "Has Link",
   },
   ["type"] = "string",
 },
 table#20 {
   ["name"] = "limit",
   ["title"] = table#21 {
     ["en"] = "Limit",
   },
   ["type"] = "string",
 },
 table#22 {
   ["name"] = "year",
   ["title"] = table#23 {
     ["en"] = "Year",
   },
   ["type"] = "number",
 },
 table#24 {
   ["name"] = "funkocategory",
   ["title"] = table#25 {
     ["en"] = "Funko Category",
   },
   ["type"] = "string",
 },
 table#26 {
   ["name"] = "inbundle",
   ["title"] = table#27 {
     ["en"] = "In Bundle",
   },
   ["type"] = "boolean",
 },
 table#28 {
   ["name"] = "hasimage",
   ["title"] = table#29 {
     ["en"] = "Has Image",
   },
   ["type"] = "string",
 },
 table#30 {
   ["name"] = "hasfeatures",
   ["title"] = table#31 {
     ["en"] = "Has Features",
   },
   ["type"] = "string",
 },
 table#32 {
   ["name"] = "special",
   ["title"] = table#33 {
     ["en"] = "Special",
   },
   ["type"] = "string",
 },
 table#34 {
   ["name"] = "specialsize",
   ["title"] = table#35 {
     ["en"] = "Special Size",
   },
   ["type"] = "string",
 },
}
检查代码1
"101"
检查代码2
"201"