I'm performing search operation using pattern matcher. It works very well on single word input like below:
if "I like to eat healthy diet." is my string and I want to search word "eat", it gives me output as "to eat healthy".
, but in case of space separated inputs
if "I like to eat healthy diet." is my string and I want to search "to eat", it doesn't gives me any output.
Below is the code for search
for (Link link : publication.links) {
String htmlText = fetch.getData(link.getHref());
Pattern pattern = Pattern.compile(searchQuery);
Matcher matcher = pattern.matcher(htmlText);
while (matcher.find()) {
int start = matcher.start();
String prev = getTextBefore(start, htmlText);
String next = getTextAfter(start, searchQueryPath, htmlText);
String match = prev.concat(searchQueryPath).concat(next);
Search searchResult = new Search();
searchResult.setSearchIndex(start);
searchResult.setResource(link.getHref());
searchResult.setMatchString(match);
searchResult.setTextBefore(prev);
searchResult.setTextAfter(next);
String title = parseChapterTitle(htmlText);
if (title != null) {
searchResult.setTitle(title);
} else {
searchResult.setTitle("Title not available");
}
searchQueryResults.searchResultList.add(searchResult);
}
}
In above code, htmltext is string to be searched for searchQuery. And searchQuery is getting for searchView.
Aucun commentaire:
Enregistrer un commentaire