Implementing trie for efficient search of products on my website

南楼画角 提交于 2019-12-10 12:09:28

问题


I have got a list of say million of products. Now when the user at my website types something, I need to show him some relevant products for help. The search should be fast. I think trie implementation will be fine for me.

But i am confused with the very idea of implementation. I need to have the tree ready always , so that i can search n show the result instantaneously. If i start inserting the elements while calling the javascript function , it will take too long.

Can anyone suggest me, what am i missing ? My aim is to show fast out of a list of MILLIONS

Thanks :)


回答1:


Let's say that you have a sidebar on the right where the relevant products need to be shown.

The user types in the search and only the first X products are displayed in the right (let's say first 50 products). Also there will be a "Display more products" link at the bottom of that list. Twitter for example uses this approach.

Even if there are 1 milions products available, the user doesn't need to see them all in the same time, so making an Ajax request for a) the first X products and b) the number of total products (so you know if a 'Display more' link is required) is perfect.

When the user clicks on 'Display more' you'll display another X products and so on.



来源:https://stackoverflow.com/questions/8464444/implementing-trie-for-efficient-search-of-products-on-my-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!