taurenshaman
V2EX  ›  算法

求教有关“模式匹配”的算法/数据库设计: func(x,y,z,...)

  •  
  •   taurenshaman · Oct 14, 2018 · 3206 views
    This topic created in 2770 days ago, the information mentioned may be changed or developed.
    [场景]
    数据库中的条目 Item 包括不定数量的参数 Param,
    Param 有这些属性:
    Key:参数名
    DataType:限定的参数值类型
    Optional:该参数不是必须的
    Regex:用于更严格限定的正则表达式
    (其它还有些限定条件,比如最小值,最大值,枚举等等,暂时不考虑)

    问题:
    给定若干 [参数值] ,比如( 1,2,abc )或者( abc,123 ),怎样找出符合参数规则的条目。
    e.g. 2 个参数( abc,123 ),假设有条目 Item999 包含 4 个参数( x, y, z, m ),其中 x 是必须的,其它 3 个是可选的,这里假设 y 和 z 都是整数类型且都适用 123 这个值,m 是其它类型,则需要返回 2 个结果:
    Item999(x=abc, y=123),
    Item999(x=abc, z=123)


    不知道有谁接触过这方面的数据库设计或算法吗?
    谢谢!
    1 replies    2018-10-15 14:43:21 +08:00
    taurenshaman
        1
    taurenshaman  
    OP
       Oct 15, 2018
    自问自答:
    把每个 item 的所有可能性都列出来,类似索引数据,最后只是遍历即可:
    Item999, key1, key3
    Item999, key2, key3
    ...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1022 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:34 · PVG 02:34 · LAX 11:34 · JFK 14:34
    ♥ Do have faith in what you're doing.