use of org.apache.wiki.search.SearchMatcher in project jspwiki by apache.
the class AbstractFileProvider method findPages.
/**
* Iterates through all WikiPages, matches them against the given query,
* and returns a Collection of SearchResult objects.
*
* @param query {@inheritDoc}
* @return {@inheritDoc}
*/
public Collection findPages(QueryItem[] query) {
File wikipagedir = new File(m_pageDirectory);
TreeSet<SearchResult> res = new TreeSet<SearchResult>(new SearchResultComparator());
SearchMatcher matcher = new SearchMatcher(m_engine, query);
File[] wikipages = wikipagedir.listFiles(new WikiFileFilter());
for (int i = 0; i < wikipages.length; i++) {
FileInputStream input = null;
// log.debug("Searching page "+wikipages[i].getPath() );
String filename = wikipages[i].getName();
int cutpoint = filename.lastIndexOf(FILE_EXT);
String wikiname = filename.substring(0, cutpoint);
wikiname = unmangleName(wikiname);
try {
input = new FileInputStream(wikipages[i]);
String pagetext = FileUtil.readContents(input, m_encoding);
SearchResult comparison = matcher.matchPageContent(wikiname, pagetext);
if (comparison != null) {
res.add(comparison);
}
} catch (IOException e) {
log.error("Failed to read " + filename, e);
} finally {
IOUtils.closeQuietly(input);
}
}
return res;
}
Aggregations