CN106372238A - 一种基于数据库的非递归无限分类的实现方法 - Google Patents

一种基于数据库的非递归无限分类的实现方法 Download PDF

Info

Publication number
CN106372238A
CN106372238A CN201610820879.3A CN201610820879A CN106372238A CN 106372238 A CN106372238 A CN 106372238A CN 201610820879 A CN201610820879 A CN 201610820879A CN 106372238 A CN106372238 A CN 106372238A
Authority
CN
China
Prior art keywords
classification
level
cat
catid
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201610820879.3A
Other languages
English (en)
Inventor
周振
刘慧平
于藜铭
支芳龙
鲁文凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Electric Technology Co., Ltd.
Original Assignee
Guangzhou Shizhen Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Shizhen Information Technology Co Ltd filed Critical Guangzhou Shizhen Information Technology Co Ltd
Priority to CN201610820879.3A priority Critical patent/CN106372238A/zh
Publication of CN106372238A publication Critical patent/CN106372238A/zh
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2272Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2358Change logging, detection, and notification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • G06F16/2445Data retrieval commands; View definitions

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种基于数据库的非递归无限分类的实现方法,包括两大模块,分别为对子表分类进行维护,并维护主表分类层级的数据结构和对产品的分类进行查询;以及显示分类下相关的产品信息,对于以上两大模块,需要作出如下步骤:增加分类数据,并对数据进行维护;列出分类数据,并通过分类信息进行查询;搜索出相关的分类信息,并对关联的产品进行检索;最快最准确的定位产品的信息,并展示。本发明采用的非递归分类:主要解决的是查询效率,以及操作的灵活性,由于综合、动态地考虑了查询的效率,以及操作的易用性。符合数据库建模设计,维护处理新增加的节点级别,可以做到无限级别扩展。

Description

一种基于数据库的非递归无限分类的实现方法
技术领域
本发明涉及一种数据分类领域,具体涉及一种基于数据库的非递归无限分类的实现方法。
背景技术
目前通用的分类方案,以上基本可以满足项目需求。但是相对于商品的分类而言,需要有以下需求,查找一级分类下的所有分类,查找某分类的所有子分类,以及快速的增删改。这对于现在的信息检索可以节约查询时间,为准确搜索某类商品的信息,快速浏览,把握信息的准确度有着很强的意义;
无限分类的实现方法:就像windows下新建一个文件夹,在新建的文件夹下又可以新建一个文件夹,这样无限循环下去,无限分类也是这样,父类可以分出它子类,子类又可以分出它的子类,这样一直无限循环下去。
关于该问题,找到几种解决方案,各有优缺点。
第一种方案:
使用递归算法,也是使用频率最多的,大部分开源程序也是这么处理,不过一般都只用到四级分类。这种算法的数据库结构设计最为简单。category表中一个字段id,一个字段fid(父id)。这样可以根据WHERE id=fid来判断上一级内容,运用递归至最顶层。
分析:通过这种数据库设计出的无限级,可以说读取的时候相当费劲,所以大部分的程序最多3-4级分类,这就足以满足需求,从而一次性读出所有的数据,再对得到数组或者对象进行递归。本身负荷还是没太大问题。但是如果分类到更多级,那是不可取的办法。这样看来这种分类有个好处,就是增删改的时候轻松了。然而就二级分类而言,采用这种算法就应该算最优先了。
第二种方案:
设置fid字段类型为varchar,将父类id都集中在这个字段里,用符号隔开,比如:1,3,6这样可以比较容易得到各上级分类的ID,而且在查询分类下的信息的时候,可以使用:SELECT*FROM category WHERE pid LIKE“1,3%”。分析:相比于递归算法,在读取数据方面优势非常大,但是若查找该分类的所有父分类或者子分类查询的效率也不是很高,至少也要二次query,从某种意义看上,个人觉得不太符合数据库范式的设计。倘若递增到无限级,还需考虑字段是否达到要求,而且在修改分类和转移分类的时候操作将非常麻烦。暂时,在自己项目中用的就是类似第二种方案的解决办法。就该方案在我的项目中存在这样的问题,如果当所有数据记录达到上万甚至10W以上后,一次性将所有分类,有序分级的现实出来,效率很低。极有可能是项目处理数据代码效率低带来的。
第三种方案:改进前序遍历树
树型结构应具备特点:数据存储冗余小、直观性强;方便返回整个树型结构数据;可以很轻松的返回某一子树(方便分层加载),以及很快的获取某节点的祖谱路径;***、删除、移动节点效率高等等。
分析:我们先把树按照水平方式摆开。从根节点开始(“Food”),然后他的左边写上1。然后按照树的顺序(从上到下)给“Fruit”的左边写上2。这样,你沿着树的边界遍历,然后同时在每个节点的左边和右边写上数字。最后,我们回到了根节点“Food”在右边写上18。下面是标上了数字的树,同时把遍历的顺序。该方案存在的缺点是查询方便,但是增删改操作有点繁琐。
发明内容
本发明针对现有技术中其各自的不足,提供一种采用非递归调用方式实现,新增层级关系表,表示其逻辑关系,采用非递归实现,提高查询效率,简化增删改的操作的基于数据库的非递归无限分类的实现方法。
本发明是通过以下技术方案来实现的:一种基于数据库的非递归无限分类的实现方法,包括两大模块,分别为对子表分类进行维护,并维护主表分类层级的数据结构和对产品的分类进行查询;
以及显示分类下相关的产品信息,对于以上两大模块,需要作出如下步骤:
步骤1、增加分类数据,并对数据进行维护;
步骤2、列出分类数据,并通过分类信息进行查询;
步骤3、搜索出相关的分类信息,并对关联的产品进行检索;
步骤4、最快最准确的定位产品的信息,并展示。
无限级分类,主要是通过储存上级分类的parentid以及分类路径来实现。一般使用connect by查询语句来进行递归查询。但在查询中会带来各种不便,以及影响查询效率。由于分类数据可以模拟数据结构,模拟分类的数据由树状显示,通过建立数据模型,用非递归方式实现。
(一)创建数据库表、分类表,以及分类层级表;
(二)增加表b2b_cat_level,保存所有的两两之间有关联的分类id的关系,不仅保存某catid对应的上级id,也保存catid的上上一级的id;
(三)新增分类:当我们新增分类是,同时维护两张表的数据,***的语句如下Insert into b2b_cat(catid,cat_name,cat_code)values(‘10001002’,’空调’,’10001002’);
Insert into b2b_cat_level(Catid,Superiorid,superiorlevel)values(‘10001002’,’10001000’,2);
Insert into b2b_cat_level(Catid,Superiorid,superiorlevel)values(‘10001002’,’10000000,1);
(四)向上查询:如果需要向上查找某个分类的一级类目,可以通过数据库语句select Superiorid from b2b_cat_level where catid=?And parentcatlevel=1,返回的是这个第一分类的所有子分类列表;
(五)向下查询:如果需要向下找某个分类的所有子分类,可以通过数据库查询语句select catid from b2b_cat_level where Superiorid=?,返回这个分类的下一级子分类列表;
(六)修改分类:可以通过指定修改层级level例如:
Update b2b_cat_level set superiorlevel=?Where Catid=?;
(七)删除分类:通过分类表的catid删除分类表对应的分类,同时删除关联的分类层级。
本发明的有益效果是:本发明采用非递归调用方式实现,新增层级关系表,表示其逻辑关系,采用非递归实现,提高查询效率,简化增删改的操作。本发明选用一种折中的方案,既在不太影响效率的情况下,操作也不会太复杂。
具体实施方式
本说明书中公开的所有特征,或公开的所有方法或过程中的步骤,除了互相排斥的特征和/或步骤以外,均可以以任何方式组合。
本说明书中公开的任一特征,除非特别叙述,均可被其他等效或具有类似目的的替代特征加以替换。即,除非特别叙述,每个特征只是一系列等效或类似特征中的一个例子而已。
一种基于数据库的非递归无限分类的实现方法,包括了两大模块,分别为对子表分类进行维护,并维护主表分类层级的数据结构和对产品的分类进行查询;
以及显示分类下相关的产品信息,对于以上两大模块,需要作出如下步骤:
1、增加分类数据,并对数据进行维护;2、列出分类数据,并通过分类信息进行查询;3、搜索出相关的分类信息,并对关联的产品进行检索;4、最快最准确的定位产品的信息,并展示。
具体操作如下:
(一)创建数据库表、分类表,以及分类层级表;
分类表:
分类层级表:
(二)增加表b2b_cat_level,保存所有的两两之间有关联的分类id的关系,不仅保存某catid对应的上级id,也保存catid的上上一级的id;
分类表b2b_cat表构建如下
Catid 分类ID
Cat_name 分类名字
Cat_code 分类编码
数据示例如下
Catid Cat_name Cat_code
10000000 家用电器 10000000
10001000 大家电 10001000
10001001 平板电视 10001001
b2b_cat_level表构建如下
Catid 分类ID
Superiorid 上级分类ID
superiorlevel 上级分类的级别
数据示例如下:
Catid Superiorid superiorlevel 说明
10001001 10001000 2 三级->二级
10001001 10000000 1 三级->一级
10001000 10000000 1 二级->一级
(三)新增分类:当我们新增分类是,同时维护两张表的数据,***的语句如下Insert into b2b_cat(catid,cat_name,cat_code)values(‘10001002’,’空调’,’10001002’);
Insert into b2b_cat_level(Catid,Superiorid,superiorlevel)values(‘10001002’,’10001000’,2);
Insert into b2b_cat_level(Catid,Superiorid,superiorlevel)values(‘10001002’,’10000000,1);
数据事例如下:
Catid Superiorid superiorlevel 说明
10001002 10001000 2 三级->二级
10001002 10000000 1 三级->一级
10001000 10000000 1 二级->一级
(四)向上查询:如果需要向上查找某个分类的一级类目,可以通过数据库语句select Superiorid from b2b_cat_level where catid=?And parentcatlevel=1,返回的是这个第一分类的所有子分类列表;
(五)向下查询:如果需要向下找某个分类的所有子分类,可以通过数据库查询语句select catid from b2b_cat_level where Superiorid=?,返回这个分类的下一级子分类列表;
(六)修改分类:可以通过指定修改层级level例如:
Update b2b_cat_level set superiorlevel=?Where Catid=?;
(七)删除分类:通过分类表的catid删除分类表对应的分类,同时删除关联的分类层级;
例如:
Delete b2b_cat where catid=?
Delete b2b_cat_level where catid=?。
本发明的有益效果是:由于综合、动态地考虑了查询的效率,以及操作的易用性。符合数据库建模设计,维护处理新增加的节点级别,可以做到无限级别扩展。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何不经过创造性劳动想到的变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应该以权利要求书所限定的保护范围为准。

Claims (2)

1.一种基于数据库的非递归无限分类的实现方法,其特征在于,包括两大模块,分别为对子表分类进行维护,并维护主表分类层级的数据结构和对产品的分类进行查询;
以及显示分类下相关的产品信息,对于以上两大模块,需要作出如下步骤:
步骤1、增加分类数据,并对数据进行维护;
步骤2、列出分类数据,并通过分类信息进行查询;
步骤3、搜索出相关的分类信息,并对关联的产品进行检索;
步骤4、最快最准确的定位产品的信息,并展示。
2.如权利要求1所述的基于数据库的非递归无限分类的实现方法,其特征在于,以上所述的步骤1至步骤4具体操作如下:
(一)创建数据库表、分类表,以及分类层级表;
(二)增加表b2b_cat_level,保存所有的两两之间有关联的分类id的关系,不仅保存某catid对应的上级id,也保存catid的上上一级的id;
(三)新增分类:当我们新增分类是,同时维护两张表的数据,***的语句如下Insertinto b2b_cat(catid,cat_name,cat_code)values(‘10001002’,’空调’,’10001002’);Insert into b2b_cat_level(Catid,Superiorid,superiorlevel)values(‘10001002’,’10001000’,2);
Insert into b2b_cat_level(Catid,Superiorid,superiorlevel)values(‘10001002’,’10000000,1);
(四)向上查询:如果需要向上查找某个分类的一级类目,可以通过数据库语句selectSuperiorid from b2b_cat_level where catid=?And parentcatlevel=1,返回的是这个第一分类的所有子分类列表;
(五)向下查询:如果需要向下找某个分类的所有子分类,可以通过数据库查询语句select catid from b2b_cat_level where Superiorid=?,返回这个分类的下一级子分类列表;
(六)修改分类:可以通过指定修改层级level例如:
Update b2b_cat_level set superiorlevel=?Where Catid=?;
(七)删除分类:通过分类表的catid删除分类表对应的分类,同时删除关联的分类层级。
CN201610820879.3A 2016-09-13 2016-09-13 一种基于数据库的非递归无限分类的实现方法 Pending CN106372238A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610820879.3A CN106372238A (zh) 2016-09-13 2016-09-13 一种基于数据库的非递归无限分类的实现方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610820879.3A CN106372238A (zh) 2016-09-13 2016-09-13 一种基于数据库的非递归无限分类的实现方法

Publications (1)

Publication Number Publication Date
CN106372238A true CN106372238A (zh) 2017-02-01

Family

ID=57897293

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610820879.3A Pending CN106372238A (zh) 2016-09-13 2016-09-13 一种基于数据库的非递归无限分类的实现方法

Country Status (1)

Country Link
CN (1) CN106372238A (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109766439A (zh) * 2018-12-15 2019-05-17 内蒙航天动力机械测试所 统计查询软件的无限树状分类定义与指派方法
CN110019006A (zh) * 2017-10-16 2019-07-16 航天信息股份有限公司 一种用于无限级分类及排序的方法及***

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001014948A2 (en) * 1999-08-19 2001-03-01 Matrix Device Limited Recursive dynamic access to a data model having a hierarchical tree structure
CN101840400A (zh) * 2009-03-19 2010-09-22 北大方正集团有限公司 一种多级分类检索方法及***
CN103942267A (zh) * 2014-03-26 2014-07-23 上海德上网络科技有限公司 应用于在线教育***中的树形数据结构的建立方法

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001014948A2 (en) * 1999-08-19 2001-03-01 Matrix Device Limited Recursive dynamic access to a data model having a hierarchical tree structure
CN101840400A (zh) * 2009-03-19 2010-09-22 北大方正集团有限公司 一种多级分类检索方法及***
CN103942267A (zh) * 2014-03-26 2014-07-23 上海德上网络科技有限公司 应用于在线教育***中的树形数据结构的建立方法

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
CAIGAN: "《"http://www.cnblogs.com/caicaizi/p/5238471.html"》", 3 March 2016 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110019006A (zh) * 2017-10-16 2019-07-16 航天信息股份有限公司 一种用于无限级分类及排序的方法及***
CN110019006B (zh) * 2017-10-16 2022-03-04 航天信息股份有限公司 一种用于无限级分类及排序的方法及***
CN109766439A (zh) * 2018-12-15 2019-05-17 内蒙航天动力机械测试所 统计查询软件的无限树状分类定义与指派方法

Similar Documents

Publication Publication Date Title
US5257365A (en) Database system with multi-dimensional summary search tree nodes for reducing the necessity to access records
US6199059B1 (en) System and method for classifying and retrieving information with virtual object hierarchy
US7124148B2 (en) User-friendly search results display system, method, and computer program product
CN104063523B (zh) 一种电子商务搜索评分与排名的方法及***
CN103218719B (zh) 一种电子商务网站导航方法及***
Kotidis et al. An alternative storage organization for ROLAP aggregate views based on cubetrees
CN103678620B (zh) 一种基于用户历史行为特征的知识文档推荐方法
CN103314371B (zh) 一种检索的方法和***
US20040158567A1 (en) Constraint driven schema association
CN104794242B (zh) 一种搜索方法
Yiu et al. Ranking spatial data by quality preferences
CN103186550A (zh) 一种视频的相关视频列表的生成方法及***
AU2004292680A1 (en) Method of constructing preferred views of hierarchical data
CN104008171A (zh) 一种法律数据库构建方法及法律检索服务方法
US20080162446A1 (en) Linked logical fields
US8065343B2 (en) Data storage and retrieval system with optimized categorization of information items based on category selection
CN106997390A (zh) 一种设备配件或零部件商品交易信息搜索方法
CN102306176A (zh) 一种基于数据仓库内在特征的olap关键词查询方法
US20010042060A1 (en) Attribute tagging and matching system and method for database management
CN106372238A (zh) 一种基于数据库的非递归无限分类的实现方法
CN106127863B (zh) 一种冰箱发泡模具系列化设计***及其方法
CN109062921B (zh) 一种提取船舶托盘管理信息的方法及***
CN105159898A (zh) 一种搜索的方法和装置
CN102033886A (zh) 一种织物检索方法及***
Sapir et al. A methodology for the design of a fuzzy data warehouse

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB03 Change of inventor or designer information
CB03 Change of inventor or designer information

Inventor after: Zhou Zhen

Inventor after: Liu Huiping

Inventor after: Yu Liming

Inventor before: Zhou Zhen

Inventor before: Liu Huiping

Inventor before: Yu Liming

Inventor before: Zhi Fanglong

Inventor before: Lu Wenkai

TA01 Transfer of patent application right

Effective date of registration: 20170313

Address after: 510000 Guangzhou science and Technology Industrial Development Zone, Guangdong Province, science Avenue, room 101, No. 808

Applicant after: Guangzhou Electric Technology Co., Ltd.

Address before: 510000 Guangzhou science and Technology Industrial Development Zone, Guangdong Province, science Avenue, room 101, No. 808

Applicant before: Guangzhou Mdt InfoTech Ltd

TA01 Transfer of patent application right
CB03 Change of inventor or designer information
CB03 Change of inventor or designer information

Inventor after: Zhou Zhen

Inventor after: Liu Huiping

Inventor after: Yu Liming

Inventor before: Zhou Zhen

Inventor before: Liu Huiping

Inventor before: Yu Liming

Inventor before: Zhi Fanglong

Inventor before: Lu Wenkai

TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20170324

Address after: 510000 Guangzhou science and Technology Industrial Development Zone, Guangdong Province, science Avenue, room 101, No. 808

Applicant after: Guangzhou Electric Technology Co., Ltd.

Address before: 510000 Guangzhou science and Technology Industrial Development Zone, Guangdong Province, science Avenue, room 101, No. 808

Applicant before: Guangzhou Mdt InfoTech Ltd

RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20170201