Welcome in his lecture, I'm going to show you how to make a very, very simple search engine for now,
it will search the words inside the gibbons' think and let people curate.
Now, let me show you how it's going to work.
They say that you have a series of words or in other words, a slice of words like these, once, as
you know, each element here is a street value, right.
OK, let's also say that the user want to search inside these words by using a query like this.
This query is also a slice of sorts so the user can create the system for multiple words.
For example, here, the imaginary user searches for again and words.
So the user searches for these highlighted words inside the words right, as you can see, there are
multiple matches, for example.
Again, word appears three times, the antwoord appears twice.
Let me show you how to build this system.
The.
First, I'm going to put the words inside a constant named corpus here, lazy cat jumps again and again
and again.
By the way, what's inside the corpus is an important the important thing is the algorithm that I'm
going to program in a minute.
I put into a constant fear because I don't want this to sink obscurity called.
All right.
Saddam, previously, I'm going to split the corpus into its words, using the strings that fields function.
Now, the words variable contains the verse is a slice of strings, right?
As you can see here, think of the worst variable as a database where people can curate its contents,
might have came from a file or from VEP or from network and so on.
So it doesn't matter where its content comes from, as long as you have that corpus.
All right, now I'm going to get the queries from the come line using the Oyster ARC's, as usual.
Here I used the expression that I showed you before.
Remember, this returns a new slice without its first item.
OK.
OK, now I'm going to type two nested loops using for the first one, we loop over the correct words
so each query will be searched against the words the corpus.
Our database, by the way, of course, this is not a perfect search algorithm, but it will help me
to show you how a simple search algorithm works.
Anyway, first, let me type the first loop that ranges or the slice like this.
Well, to start here, I didn't use the index variable and I skipped it by using a blank identifier
because I don't need it right in this loop, I'm only going to check or each credit card.
All right, now let me show you how it works.
Let me first come on top these words.
We're both here to prevent unused verbal warning labels at a princella, here to print the correct words.
Go around, mean that, go again and.
Let's try again and this try weed out the words.
OK, it pertains to words.
Let's get back.
Let me remove this printer line here and on comment, the words variable here.
OK.
Now, I'm going to at the next loop inside here.
This will loop over the words variable, so inside these nested loop, I'm going to search for the each
square it word in the word slice.
OK.
So how can I check whether security measures to avert inside the word less, I can use a simple if statement,
right, let's do that.
So when aquarium matches to avert, Dango will simply execute this if statement.
Now I'm going to print a message which prints the position of the birds inside the corpus and the word
itself.
Now I'm going to type the position of the bird inside the words with the verb.
Then I'm going to actually print the word using this cue, up next, I'm going to pass the position
like this.
Then I'm going to pass the word like this.
I plus mom here, do you know why?
I did so because I want to print the position of the word, not its index inside the slice, it is like
one, two, three, not like zero one to.
All right, let's run this now and see it in action.
Let's try it again and again only and and without any arguments.
OK, it works, right?
Cool, however, as you can see, it brings back duplicate results.
For example, when I search for the again, word brings multiple results, right?
OK, let's talk about this a little bit.
They say that the system should only return unique words, so it should keep searching for more words
after it finds the words, for example, isn't here.
The user searches for multiple words, right?
So the system will only print the first matched words once, even though there are multiple matches.
So it'll keep the duplicates.
Who can do that?
Well, in the search logic, you can use a brake statement and quit from the Knesset look when it finds
the word.
Let me show you.
As I said, I need to break from the nested loop and find some of the corporate words, so to do that,
I just need to add a brake statement here.
OK, Illustrated's.
As you can see, as soon as it finds the corporate world, it stops searching for the rest of the birds
inside the corpus.
The big statement terminates the nested loop after it finds the search words.
Now it only prints the unique words cool.
Now is the time I prepared a little exercise for you, you can find them all in the course of history,
of course, here.
I'm only going to show you one of them.
Let's check it out.
First exercise, his name is Case Insensitive Search, currently the word finder program doesn't return
results for the words with different types, right?
For example, he doesn't find the word when the user queries the word with uppercase letters, they
say that the user runs the program like this.
All like this.
Ah, this.
OK, here is your exercise for all the cases here, the word finder program should find the lazy keyword
inside the corpus.
Of course, this lazy keyword can change.
This is just an example.
OK, for more details about this exercise and for all the other exercises, please check out the car.
Story has always.
All right, there is only one step left labeled statements are important.
OK, I hope to see you there.
Bye for now.