Search in sources :

Example 1 with SearchResultComparator

use of org.apache.wiki.search.SearchResultComparator 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;
}
Also used : TreeSet(java.util.TreeSet) SearchResultComparator(org.apache.wiki.search.SearchResultComparator) SearchResult(org.apache.wiki.search.SearchResult) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) SearchMatcher(org.apache.wiki.search.SearchMatcher)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 SearchMatcher (org.apache.wiki.search.SearchMatcher)1 SearchResult (org.apache.wiki.search.SearchResult)1 SearchResultComparator (org.apache.wiki.search.SearchResultComparator)1