What is best way of searching some keywrods in web page. In Database, i have list of webpages. In each webpage, i want to check if some keyword are present. I m storing webpage data as String.Is String.indexOf() methods good one ? Size of page may differ.
Maintain a collection of words you want to search . When a collection is implemented we can verify if a particular word is present or not buy using contains method. which would return tree if the word exists in a collection or false which states the world does not exist.
Sizeof would return the size of the string which does not serve your purpose of searching.
I am not convinced Sizeof exists in Java; it looks like a C keyword. Do you mean indexOf? You should use the String#contains method rather than indexOf if you only want to check for existence of a substring.
For a linear search, you would have to iterate the text of the webpage once for every keyword. Also what will happen for the keyword short if the text includes shorten? I think I shall work from Balaji Vankadaru's suggestion.
Put your keywords into a set. Split the text into a String, maybe splitting on whitespace. Iterate the split array and see whether the set contains each word.
posted 7 years ago
For my next trick, I'll need the help of a tiny ad ...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop