473,796 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Algorithm on search

Search engine have to record all of the query string. Now i have a
search engine log which contains 10 milllion query strings, but almost
of them are repeated, not more than 3 million of them are non-
repeated.
My task is to pick the top 10 most popular query string, memory < 1G,
the length of the query string is no more than 255.

The faster, the better.
the principal solutions, algorithm and data structure.

Thank you.:-)
Jun 27 '08 #1
3 1584
Vincent SHAO <vi************ ***@gmail.comwr ites:
Search engine have to record all of the query string. Now i have a
search engine log which contains 10 milllion query strings, but almost
of them are repeated, not more than 3 million of them are non-
repeated.
My task is to pick the top 10 most popular query string, memory < 1G,
the length of the query string is no more than 255.

The faster, the better.
the principal solutions, algorithm and data structure.
Sounds like homework... Is it homework?
In real "search engine" queries, it's not strings, but _sets_ of
keywords that are searched, so already your data structures will be
suboptimal... That is, unless it's homework.

In anycase, have a look at http://en.wikipedia.org/wiki/Bloom_filter

--
__Pascal Bourguignon__
Jun 27 '08 #2
Vincent SHAO wrote:
Search engine have to record all of the query string. Now i have a
search engine log which contains 10 milllion query strings, but almost
of them are repeated, not more than 3 million of them are non-
repeated.
My task is to pick the top 10 most popular query string, memory < 1G,
the length of the query string is no more than 255.

The faster, the better.
the principal solutions, algorithm and data structure.

Thank you.:-)
My first attempt would be to stuff the query strings into a map with the
query string (or a hash of it) as the key, the number of times it occurs as
the data.

Then a loop to read the data and sort, or simply compare counts and store
the keys for the top 10.
--
Jim Langston
ta*******@rocke tmail.com
Jun 27 '08 #3
On May 6, 2:15 pm, p...@informatim ago.com (Pascal J. Bourguignon)
wrote:
Vincent SHAO <vincent.shao.b ...@gmail.comwr ites:
Search engine have to record all of the query string. Now i
have a search engine log which contains 10 milllion query
strings, but almost of them are repeated, not more than 3
million of them are non-repeated. My task is to pick the
top 10 most popular query string, memory < 1G, the length of
the query string is no more than 255.
The faster, the better. the principal solutions, algorithm
and data structure.
Sounds like homework... Is it homework?
It sounds like a problem that really could come up
professionally (which doesn't mean it isn't homework---a well
conceived course will use realistic examples).
In real "search engine" queries, it's not strings, but _sets_ of
keywords that are searched, so already your data structures will be
suboptimal... That is, unless it's homework.
What about SQL or LDAP? The problem is that he probably should
consider requests that different only in white space to be the
same; for that matter (considering SQL), something like "SELECT
* FROM table1 WHERE a 5 AND b < 10" is the same as "select *
from table1 where b < 10 and a 5". He probably needs to
normalize the input somewhat, but how far depends on the project
requirements.

Anyway, the obvious solution is to use an std::map< Query, long >
for starters, then copy the tabluation into a vector (of
Map::value_type ) and sort that on the criteria he's interested
in. If that's not fast enough, replace std::map with a not
yet standard hash_map, and only if that's not fast enough, to
start worrying about other solutions.
In anycase, have a look athttp://en.wikipedia.or g/wiki/Bloom_filter
That saves space, not time, and probably isn't appropriate for
such a small table. (Space savings become time savings when the
result in less disk accesses. In his case, however, the
complete table will almost certainly fit into real memory.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
4637
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like eBay, Yahoo and others. This is what she wants my program to be able to do: (try this test at different websites just for fun). At eBay: - enter the word 'television' in a search field à you will get 2155 items.
28
3182
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple linear search the best here(for loop from beginning to end of array)? It seems like some other search algorithm like binary or whatever would be of no benefit on this data set.
3
3360
by: Johann Blake | last post by:
This aticle presents factual evidence that Google's PageRank, inbound links and keywords are irrelevent to your placement in the search results. It presents several case studies that show conclusively that the algorithm used by Google's search engine is flawed with serious "bugs" that deny many websites the high ranking that they should otherwise be granted while granting it to those who shouldn't have it. The article is entitled...
8
1773
by: Ben Fidge | last post by:
Hi I'm working on a site which requires the users to specify a hotel at which they're staying in London. The complete list of hotels comes to something like 1600 records. Each record consists of Hotel Name, Street Address and Postcode. We need to make it as simple as possible for users to pick their hotel, but I don't want to put 1600 hotel names in a drop-down list, and we have to consider the fact that not every user is going to...
6
2277
by: Bernie Yaeger | last post by:
I need a little help with an algorithm. Let's say I have an array with 15 items. I want to find "Fern" where there are "Able", "Me Also", "Zimmerman", etc in no particular order. Forget about the fact that it's an array - I know how to search an array. I just want an algorithm that will do the following: 1. search the first 1/2 - say 8 items. If the value is less than what I'm seeking, the algorithm needs to return 'search 1 - 8...
4
5350
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given the Identifier. The logical way would be to read the record once and put it in an STL container such as vector and then use lower_bound to search for a given identifier. But for some strange reason i'm asked to not use a container but instead...
4
32085
prometheuzz
by: prometheuzz | last post by:
Hello (Java) enthusiasts, In this article I’d like to tell you a little bit about graphs and how you can search a graph using the BFS (breadth first search) algorithm. I’ll address, and hopefully answer, the following questions: • what is a graph? • how can a graph be represented as an ADT? • how can we search/walk through a graph using the BFS algorithm?
6
4092
by: pj | last post by:
Hi, I 'm currently writing a program that performs transliteration (i.e., converts greek text written using the english alphabet to "pure" greek text using the greek alphabet) as part of my thesis. I have decided to add the capability to convert words using some sort of lookup algorithm as a sidekick to the "normal" conversion algorithm, and here it starts getting interesting. I want to find an algorithm that satisfies these...
6
17864
by: kamsmartx | last post by:
I'm new to programming and need some help figuring out an algorithm. I need to design some kind of algorithm which will help us define capacity for one of our portfolios....here's the problem explained (also see attached example): 1. The graph defines total capacity, y-axis being $, x-axis being date/time. the bars on the graph represent individual items. 2. What I need to do is place the items on the graph in an optimized manner,...
6
12184
Kelicula
by: Kelicula | last post by:
Why?: One commonly used algorithm is the binary search. If you don't already know it, you should read on. Very helpful. Saves much CPU. Reduces computations exponentially. When searching though a lot of information to find a match, the first idea that comes to mind is the linear search. Loop through all the values looking for a match. If you find it, return the location, or value and end the search. However this becomes highly...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.