acpanda
V2EX  ›  PHP

关于通过类别检索的问题

  •  
  •   acpanda · Aug 9, 2017 · 2574 views
    This topic created in 3210 days ago, the information mentioned may be changed or developed.
    请教一下各位 V 友。现有两张数据表,分别存储物品信息和类别层级信息。每项物品属于后者中一种类别,类别存在多级及继承,通过(id, name, parent_id)方式存储。那么,给出类别 A 时,如何把属于类别 A 及类别 A 下所有子类别的物品检索出来了?有什么比较好的方法吗?
    3 replies    2017-08-11 18:31:10 +08:00
    U7Q5tLAex2FI0o0g
        1
    U7Q5tLAex2FI0o0g  
       Aug 10, 2017
    上 solr ?

    或者物品表里多存一个字段:
    category_id, category_path
    5,',1,3,5,'
    6,',1,3,6,'
    再用 path 字段来查。不过这种效率不高
    FYK
        2
    FYK  
       Aug 11, 2017
    搜索 无限极分类 试试
    elevioux
        3
    elevioux  
       Aug 11, 2017
    先把 A 及其子分类先查出来,再找物品?

    之前做的是先把分类表整个读出来再 php 递归找子分类的。如果分类表很大就可能不适用了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1145 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 23:34 · PVG 07:34 · LAX 16:34 · JFK 19:34
    ♥ Do have faith in what you're doing.