帮助:SMongo
安装SMG | |
---|---|
仓库地址 | 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。
- 修正了多个key参与排序并单独制定升降序规则时(
- 2020/04/09:v 0.1.8更新:修正了
|format = template
模式下,debug无法正确显示template_args
(模板参数)的问题。现在named_args
和named 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更新:
- 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模式(推荐)
准备数据表
您需要在data:xxxxx.tab
或data: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的例子:
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:Ask
和Module:Query
里
- 模板仓库链接:SMongo零件
- 源代码:templatemanager:module: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 |
目前仅支持table 、template 和count |
默认是table |
intro |
默认表格前的内容 | |
outro |
默认表格后的内容 | |
default |
查询结果为空时返回的内容 | |
headers |
headers = hide隐藏第一行 | |
offset |
跳过的结果,默认是0 |
link
和searchlabel
两个鸡肋的功能我删掉了,实际使用SMW的过程中,大家都在千方百计的隐藏掉他们
指定数据表
|table = xxxxxxx.tabx
用来读取表的schema,以正确匹配查询数据的类型,支持tab
、tabx
,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#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 | 奈德·史塔克 |
排除条件(!)
key::!value
例子:
{{ask |table = Testdata.tabx |query = Year::!2011 |?Has Name = Has Name |?Funko Franchise = Franchise |?Year = Year |limit =20 |mainlabel = - }}
结果:
Franchise | Has Name | Year |
---|---|---|
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 = - }}
结果:
Franchise | Has Name | Year |
---|---|---|
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 = - }}
结果:
Franchise | Has Name | Year |
---|---|---|
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] = { ['>e'] = value1, ['<e'] = 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 = - }}
结果:
Franchise | Has Name | Year |
---|---|---|
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 = - }}
结果:
Franchise | Has Name | Year |
---|---|---|
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#94 | Game of Thrones | 娜梅莉亚 | 2019 |
Data:Testdata.tabx#59 | Game of Thrones | 夜王 | 2019 |
Data:Testdata.tabx#91 | Game of Thrones | 夜王 | 2019 |
Data:Testdata.tabx#93 | Game of Thrones | 艾莉亚·史塔克 | 2019 |
Data:Testdata.tabx#79 | Game of Thrones | 奥莲娜·雷德温 | 2018 |
Data:Testdata.tabx#95 | Game of Thrones | 乔治·马丁 | 2018 |
Data:Testdata.tabx#80 | Game of Thrones | 贝里·唐德利恩 | 2018 |
Data:Testdata.tabx#69 | Game of Thrones | 巨人克星托蒙德 | 2018 |
Data:Testdata.tabx#85 | Game of Thrones | 森林之子 | 2018 |
Data:Testdata.tabx#75 | Game of Thrones | 尸鬼巨人 | 2018 |
Data:Testdata.tabx#103 | Game of Thrones | 乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯 | 2018 |
Data:Testdata.tabx#72 | Game of Thrones | 莱安娜·莫尔蒙 | 2017 |
Data:Testdata.tabx#58 | Game of Thrones | 夜王 | 2017 |
Data:Testdata.tabx#70 | Game of Thrones | 魔山 | 2017 |
Data:Testdata.tabx#101 | Game of Thrones | 琼恩和布兰 | 2017 |
Data:Testdata.tabx#73 | Game of Thrones | 贾坤 | 2017 |
Data:Testdata.tabx#63 | Game of Thrones | 强壮的玛格 | 2016 |
Data:Testdata.tabx#61 | Game of Thrones | 卓耿 | 2016 |
Data:Testdata.tabx#54 | Game of Thrones | 梅丽珊卓 | 2016 |
Data:Testdata.tabx#57 | Game 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#59 | 6 | 44 | 夜王 | 2019 |
Data:Testdata.tabx#91 | 10 | 74 | 夜王 | 2019 |
Data:Testdata.tabx#94 | 99 | 76 | 娜梅莉亚 | 2019 |
Data:Testdata.tabx#93 | 10 | 76 | 艾莉亚·史塔克 | 2019 |
Data:Testdata.tabx#103 | 98 | 0 | 乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯 | 2018 |
Data:Testdata.tabx#95 | 99 | 1 | 乔治·马丁 | 2018 |
Data:Testdata.tabx#69 | 7 | 53 | 巨人克星托蒙德 | 2018 |
Data:Testdata.tabx#75 | 8 | 60 | 尸鬼巨人 | 2018 |
Data:Testdata.tabx#79 | 8 | 64 | 奥莲娜·雷德温 | 2018 |
Data:Testdata.tabx#80 | 8 | 65 | 贝里·唐德利恩 | 2018 |
Data:Testdata.tabx#85 | 9 | 69 | 森林之子 | 2018 |
Data:Testdata.tabx#101 | 98 | 0 | 琼恩和布兰 | 2017 |
Data:Testdata.tabx#58 | 6 | 44 | 夜王 | 2017 |
Data:Testdata.tabx#70 | 7 | 54 | 魔山 | 2017 |
Data:Testdata.tabx#72 | 7 | 56 | 莱安娜·莫尔蒙 | 2017 |
Data:Testdata.tabx#73 | 7 | 57 | 贾坤 | 2017 |
Data:Testdata.tabx#54 | 6 | 42 | 梅丽珊卓 | 2016 |
Data:Testdata.tabx#57 | 6 | 44 | 夜王 | 2016 |
Data:Testdata.tabx#61 | 6 | 46 | 卓耿 | 2016 |
Data:Testdata.tabx#63 | 6 | 48 | 强壮的玛格 | 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#59 | Game of Thrones | 6 | 2019 | 夜王 |
Data:Testdata.tabx#91 | Game of Thrones | 10 | 2019 | 夜王 |
Data:Testdata.tabx#94 | Game of Thrones | 99 | 2019 | 娜梅莉亚 |
Data:Testdata.tabx#93 | Game of Thrones | 10 | 2019 | 艾莉亚·史塔克 |
Data:Testdata.tabx#103 | Game of Thrones | 98 | 2018 | 乔治·马丁、大卫·贝尼奥夫和丹尼尔·魏斯 |
Data:Testdata.tabx#95 | Game of Thrones | 99 | 2018 | 乔治·马丁 |
Data:Testdata.tabx#69 | Game of Thrones | 7 | 2018 | 巨人克星托蒙德 |
Data:Testdata.tabx#75 | Game of Thrones | 8 | 2018 | 尸鬼巨人 |
Data:Testdata.tabx#79 | Game of Thrones | 8 | 2018 | 奥莲娜·雷德温 |
Data:Testdata.tabx#80 | Game of Thrones | 8 | 2018 | 贝里·唐德利恩 |
Data:Testdata.tabx#85 | Game of Thrones | 9 | 2018 | 森林之子 |
Data:Testdata.tabx#101 | Game of Thrones | 98 | 2017 | 琼恩和布兰 |
Data:Testdata.tabx#58 | Game of Thrones | 6 | 2017 | 夜王 |
Data:Testdata.tabx#70 | Game of Thrones | 7 | 2017 | 魔山 |
Data:Testdata.tabx#72 | Game of Thrones | 7 | 2017 | 莱安娜·莫尔蒙 |
Data:Testdata.tabx#73 | Game of Thrones | 7 | 2017 | 贾坤 |
Data:Testdata.tabx#54 | Game of Thrones | 6 | 2016 | 梅丽珊卓 |
Data:Testdata.tabx#57 | Game of Thrones | 6 | 2016 | 夜王 |
Data:Testdata.tabx#61 | Game of Thrones | 6 | 2016 | 卓耿 |
Data:Testdata.tabx#63 | Game of Thrones | 6 | 2016 | 强壮的玛格 |
隐藏第一列
|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 }}
结果:
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 }}
结果:
y | y | |
---|---|---|
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 | 奈德·史塔克 |