Reputation: 15630
I need to implement similar kind of search functionality which Linked in or facebook offers. If you use the new Graph search in fb, when you type L on the search text, it will suggest some users having L in their names, Places having L, pages having L and so on. So how this kind of searching is implemented.
I believe there might be a table which stores copy of entire data divided.
Something like
TypeID - Text - ID for the corresponding table
User - Laurence - 1
User - Elis Lowman - 2
Pages - Lexus - 4
Pages - Lux - 1
Place - Las Vegas - 6
Place - Lebonan - 8
Am I correct ? or any other way we can able to achieve this ?\
EDIT
I checked the same in linked In. There are also having the similar kind of search. Please check the attached image.
Thanks in advance for any help.
Upvotes: 0
Views: 96
Reputation: 86
Databases and open-source packages such as Lucene and Sphinx Search allow queries with wildcard keywords to do prefix search. Their speed and result quality vary. There are also commercial packages specifically designed for this type of search queries.
Upvotes: 0
Reputation: 178471
I have no idea how it is implemented on FaceBook, but I will give a general answer.
First note that you are looking for something that is refered in the Information Retrieval field as Query Auto Completion.
Here are some basic guide lines how it can be done:
Trie data structure is pretty efficient in searching for prefixes. Going over the route of the prefix and then doing DFS from there can give you all words in the dictionary with the same prefix.
However, it will give you a huge - mostly irrelevant list of terms, and the server wants to give the user the best suggestions, and not all suggestions. The common way to do it is using the query log. More frequent queries are more likely to be what the user is looking for. So, the search engine holds a cache of queries and prefixes and use it to provide the client the pages he most likely wants.
The search for optimal auto completion is far from over, and during the few last years many works have been made regarding it. For example, I find Naama Kraus and Ziv Bar Yosef's work: Context Sensitive Query Auto Completion as a very interesting one. The idea is not to use only a general knowledge of query log - also use the data on the user, in this case - you are using his last queries - because most likely the new query is somehow related to his last one.
Upvotes: 1