SemanticMediaWiki / SemanticScribunto

Provides service functions to support the Scribunto extension
Other
23 stars 14 forks source link

Add sep example to mw.smw.set.md #79

Closed OyvindLGjesdal closed 4 years ago

OyvindLGjesdal commented 4 years ago

This PR addresses or contains: documentation

It was not obvious to me that the sep=, and template should be added as the next sibling(s) in the table. When reading the documentation, I tried the following:

my property2=value2.1,value2.2|+sep=,

until looking at https://github.com/SemanticMediaWiki/SemanticScribunto/blob/b81e565b6991b64ff2a1ca5f5f6c004fd1de3fad/tests/phpunit/Integration/JSONScript/Fixtures/module.smw.lua#L71 which has an example using +sep.

kghbln commented 4 years ago

@OyvindLGjesdal Thanks a lot.

@oetterer You may do the honours. :)

OyvindLGjesdal commented 4 years ago

I think my first assumption about LUA tables was correct, that the order cannot be guaranteed. That implies that the sep can be inserted anywhere, and will be applied for all items in the dataStoreType2. Is this how it works?

oetterer commented 4 years ago

@OyvindLGjesdal Unfortunately, the relavant bit of information can be found at the very end of the set documentation:

Note however: lua does not maintain the order in an associative array. Using parameters for set like the separator or the template parameter requires a strict parameter order in which case you must use the table format as shown with dataStoreType2 in the example above.

meaning, when you define your query like

query = {
    'property1_name=' .. value1,
    'property2_name=' .. value2 .. ',' .. value3,
    '+sep=,',
}

the order is maintained. When you use

query = {
    property1_name = 'value',
    property2_name = 'value',
    +sep = ',',
}

lua might (and probably will) scramble the order.