BlessingCR’s Blog
BlessingCR’s Blog

目录树搜索文章反向构建目录

目录树搜索文章反向构建目录

需求背景: A平台带了某类文章管理功能,目录下带各类文章。要求搜索文章时前端显示具体目录树中每个节点中符合搜索要求的的节点,并显示该节点下有多少符合要求的文章(若A节点下A1节点有3篇,A2节点有5篇,则呈现目录树应该为A(8, A1(3), A2(5)))。

注意,若节点中只有某叶子节点带了信息,应该同时把从根节点到叶子节点的所有信息全量显示。如:

A(1)-B(1)-C(1)-D(1)-E(1)-F(1)

由于前期目录设计仅带id,pid, 没有维护路径信息,层级等内容,且不便于更改(目录要求可拖拽,所以不便限制层级,且目录可修改,可改变父节点,故不便维护路径)

实现思路如下:

1. redis维护全量目录树,方便后续步骤(可优化为redis维护版本,目录树维护在内存中,如果版本不对则更新内存中目录树)
2. redis维护每个节点的关键路径信息,如A-A1-A2的树,则维护map("A":[A,A1,A2], "A1":[A,A1], "A2":[A,A1,A2])
3. 数据库搜索到关键节点(从文章,文章目录表中,联查,得到所需节点,此时还不知关键路径)
4. 通过步骤2中关键信息,存储所有关键路径(set存,顺便去重,得到所有关键路径节点)
5. 通过步骤1中全量目录树,递归删除所有非关键路径节点数据,得到所需关键路径树
6. 通过步骤5中关键路径树,以及步骤3中所需节点中搜索出的每个节点中文章数目,递归构建关键树中每个节点带有文章数量信息

实践中,若所有步骤目录树均为同一种目录树,则步骤5,6可合为一步

没有标签
首页      Java基础      数据结构           目录树搜索文章反向构建目录

发表回复

textsms
account_circle
email

  • Good website! I really love how it is easy on my eyes and the data are well written. I’m wondering how I might be notified when a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a great day!

    9 月前 回复
  • Very good visual appeal on this internet site, I’d value it 10 10.

    9 月前 回复
  • I simply wanted to compose a brief remark to say thanks to you for all of the fantastic guides you are writing at this website. My considerable internet look up has at the end been rewarded with professional know-how to write about with my colleagues. I ‘d believe that we site visitors are unequivocally lucky to live in a fabulous community with so many outstanding professionals with very beneficial concepts. I feel truly fortunate to have seen your entire web pages and look forward to really more entertaining times reading here. Thank you once again for a lot of things.

    8 月前 回复
  • Simply want to say your article is as astonishing.
    The clearness in your post is simply spectacular and i
    could assume you are an expert on this subject.

    Fine with your permission allow me to grab your feed to keep updated
    with forthcoming post. Thanks a million and please continue the gratifying work.

    My page; nordvpn coupons inspiresensation (t.co)

    6 月前 回复
  • Your means of telling everything in this post is in fact fastidious, all be
    able to effortlessly be aware of it, Thanks a lot.

    My blog; nordvpn coupons inspiresensation

    6 月前 回复
  • 350fairfax nordvpn special coupon code 2025
    Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is fundamental and all. But imagine if you added some
    great visuals or video clips to give your posts more,
    “pop”! Your content is excellent but with pics and video clips, this
    blog could undeniably be one of the greatest in its niche.
    Very good blog!

    6 月前 回复
  • Hi! Someone in my Myspace group shared this site with us so I came to check
    it out. I’m definitely enjoying the information. I’m bookmarking and will
    be tweeting this to my followers! Wonderful blog
    and fantastic style and design.

    Also visit my web blog; eharmony special coupon code 2025

    4 月前 回复
  • Thank you for the auspicious writeup. It in fact was a
    amusement account it. Look advanced to more added agreeable from you!
    However, how could we communicate?

    Here is my site vpn

    4 月前 回复
  • Have you ever considered about including a little bit more than just
    your articles? I mean, what you say is important and everything.
    But think about if you added some great photos or video clips to give your posts more, “pop”!
    Your content is excellent but with images and videos, this site could certainly be one
    of the greatest in its niche. Great blog!

    https://tinyurl.com/2cab6g88 gamefly

    3 月前 回复
  • Hello, just wanted to tell you, I enjoyed this post. It was helpful.
    Keep on posting! https://tinyurl.com/2ax86k6l what is a vpn

    3 月前 回复
  • Thank you for the auspicious writeup. It in reality was once
    a entertainment account it. Look advanced to far delivered agreeable from you!
    However, how could we keep up a correspondence?

    3 月前 回复
  • If some one wants to be updated with latest technologies then he must be
    pay a visit this web site and be up to date all the
    time.

    3 月前 回复
  • Link exchange is nothing else however it is simply placing the other person’s website link on your page at
    appropriate place and other person will also do same for
    you. Eharmony special coupon code 2025 https://tinyurl.com/ywzs4a4o

    1 月前 回复
  • Excellent goods from you, man. I have understand your stuff previous to and you’re just too excellent.
    I really like what you’ve acquired here, really like what you
    are stating and the way in which you say it. You make it enjoyable
    and you still take care of to keep it wise. I cant wait to read much more from you.
    This is really a great website.

    Here is my site … http://winkler-martin.de/messages/61849.html

    3 周前 回复

BlessingCR’s Blog

目录树搜索文章反向构建目录
目录树搜索文章反向构建目录 需求背景: A平台带了某类文章管理功能,目录下带各类文章。要求搜索文章时前端显示具体目录树中每个节点中符合搜索要求的的节点,并显示该节点下有多少符合…
扫描二维码继续阅读
2024-01-23