Search in sources :

Example 1 with QueryItem

use of org.apache.wiki.search.QueryItem in project jspwiki by apache.

the class TwoXWikiPageProvider method findPages.

/**
 * {@inheritDoc}
 */
@Override
public Collection<SearchResult> findPages(final QueryItem[] query) {
    final TreeSet<SearchResult> res = new TreeSet<>(new SearchResultComparator());
    final SearchMatcher matcher = new SearchMatcher(engine, query);
    final Map<String, WikiPage> wikipages = pages.entrySet().stream().map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), e.getValue().get(e.getValue().size() - 1))).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
    for (final String wikipage : wikipages.keySet()) {
        final String pagetext = contents.get(wikipage).get(contents.get(wikipage).size() - 1);
        try {
            final SearchResult comparison = matcher.matchPageContent(wikipage, pagetext);
            if (comparison != null) {
                res.add(comparison);
            }
        } catch (final IOException e) {
        // ok to ignore, shouldn't happen
        }
    }
    return res;
}
Also used : Arrays(java.util.Arrays) Properties(java.util.Properties) Date(java.util.Date) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WikiPage(org.apache.wiki.WikiPage) IOException(java.io.IOException) WikiEngine(org.apache.wiki.WikiEngine) SearchResultComparator(org.apache.wiki.search.SearchResultComparator) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SearchResult(org.apache.wiki.search.SearchResult) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AbstractMap(java.util.AbstractMap) List(java.util.List) WikiPageProvider(org.apache.wiki.providers.WikiPageProvider) SearchMatcher(org.apache.wiki.search.SearchMatcher) Map(java.util.Map) QueryItem(org.apache.wiki.search.QueryItem) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) Collections(java.util.Collections) WikiProvider(org.apache.wiki.WikiProvider) AbstractMap(java.util.AbstractMap) TreeSet(java.util.TreeSet) SearchResultComparator(org.apache.wiki.search.SearchResultComparator) WikiPage(org.apache.wiki.WikiPage) SearchResult(org.apache.wiki.search.SearchResult) IOException(java.io.IOException) SearchMatcher(org.apache.wiki.search.SearchMatcher)

Aggregations

IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 WikiEngine (org.apache.wiki.WikiEngine)1 WikiPage (org.apache.wiki.WikiPage)1 WikiProvider (org.apache.wiki.WikiProvider)1 NoRequiredPropertyException (org.apache.wiki.api.exceptions.NoRequiredPropertyException)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 WikiPageProvider (org.apache.wiki.providers.WikiPageProvider)1