I am trying to compare 2 indexes of a string. Basically if the first index of a string is not equal to the second index, create new searchIndex() method in void main.
This represents if the user is entering a query in the search engine of 2 words, the results should show the matching text files for the first word and the matching text files for the second word rather than showing the total number of matches and mixing the text files with each other without knowing which word is related to which text file.
If I entered Japan in the textbox
Output:
Searching for 'Japan '
3
Files\whalehunt.txt
Files\japan.txt
Files\innovation.txt
But if I entered 2 words:
Output:
Searching for 'Japan amazon '
5
Files\whalehunt.txt
Files\japan.txt
Files\peru.txt
Files\correspondent.txt
Files\innovation.txt
In case of 2 words, the user is not knowing which word is for which file. It is all mixed up. What I am trying to do is to compare the indexes of the query string to match if the two words are same or not. If not it should add a new searchIndex() method in void main and assign the second word to it.
So rather than this:
public static void main(String[] args) throws Exception {
createIndex();
searchIndex("Japan amazon ");
}
Do this:
public static void main(String[] args) throws Exception {
createIndex();
searchIndex("Japan ");
searchIndex("amazon");
}
What I have tried is:
public static void searchIndex(String searchString) throws IOException, ParseException {
for(int n=0;n<=1000;n++)
{
if (searchString.substring(0) != searchString.substring(1))
{
void main.searchIndex(searchString.); //**Error**
}
}
Any help would be grateful !!
Regards.
Your serachIndex() method is totally wrong, IMHO. You are comparing indexes 0 and 1 of the string for 1000 times. Why aren’t you using a tokenizer or String.split() to make separate words out of your string? Something like this:
BTW, I assume you are aware of tools like Apache Lucene and algorithms like MapReduce.