use of org.apache.wiki.api.search.SearchResult in project jspwiki by apache.
the class SearchAdapterTest method testNewSearchResultFrom.
@Test
public void testNewSearchResultFrom() {
final org.apache.wiki.search.SearchResult old = new org.apache.wiki.search.SearchResult() {
@Override
public WikiPage getPage() {
return null;
}
@Override
public int getScore() {
return 0;
}
@Override
public String[] getContexts() {
return new String[0];
}
};
final SearchResult sr = SearchAdapter.newSearchResultFrom(old);
Assertions.assertEquals(old.getPage(), sr.getPage());
Assertions.assertEquals(old.getScore(), sr.getScore());
Assertions.assertArrayEquals(old.getContexts(), sr.getContexts());
}
use of org.apache.wiki.api.search.SearchResult in project jspwiki by apache.
the class BasicSearchProvider method findPages.
private Collection<SearchResult> findPages(final QueryItem[] query, final Context wikiContext) {
final TreeSet<SearchResult> res = new TreeSet<>(new SearchResultComparator());
final SearchMatcher matcher = new SearchMatcher(m_engine, query);
final Collection<Page> allPages;
try {
allPages = m_engine.getManager(PageManager.class).getAllPages();
} catch (final ProviderException pe) {
log.error("Unable to retrieve page list", pe);
return null;
}
final AuthorizationManager mgr = m_engine.getManager(AuthorizationManager.class);
for (final Page page : allPages) {
try {
if (page != null) {
final PagePermission pp = new PagePermission(page, PagePermission.VIEW_ACTION);
if (wikiContext == null || mgr.checkPermission(wikiContext.getWikiSession(), pp)) {
final String pageName = page.getName();
final String pageContent = m_engine.getManager(PageManager.class).getPageText(pageName, PageProvider.LATEST_VERSION) + attachmentNames(page);
final SearchResult comparison = matcher.matchPageContent(pageName, pageContent);
if (comparison != null) {
res.add(comparison);
}
}
}
} catch (final ProviderException pe) {
log.error("Unable to retrieve page from cache", pe);
} catch (final IOException ioe) {
log.error("Failed to search page", ioe);
}
}
return res;
}
use of org.apache.wiki.api.search.SearchResult in project jspwiki by apache.
the class SearchResultIteratorTag method nextResult.
private int nextResult() {
if (m_iterator != null && m_iterator.hasNext() && m_count++ < m_maxItems) {
final SearchResult r = (SearchResult) m_iterator.next();
// Create a wiki context for the result
final Engine engine = m_wikiContext.getEngine();
final HttpServletRequest request = m_wikiContext.getHttpRequest();
final Command command = PageCommand.VIEW.targetedCommand(r.getPage());
final Context context = Wiki.context().create(engine, request, command);
// Stash it in the page context
pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), r);
return EVAL_BODY_BUFFERED;
}
return SKIP_BODY;
}
use of org.apache.wiki.api.search.SearchResult in project jspwiki by apache.
the class SearchManagerTest method testSimpleSearch4.
@Test
public void testSimpleSearch4() throws Exception {
final String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
final MockHttpServletRequest request = m_engine.newHttpRequest();
request.getParameterMap().put("page", new String[] { "TestPage" });
final Context ctx = Wiki.context().create(m_engine, request, ContextEnum.PAGE_EDIT.getRequestContext());
m_engine.getManager(PageManager.class).saveText(ctx, txt);
Collection<SearchResult> res = new ArrayList<>();
Awaitility.await("testSimpleSearch4").until(findsResultsFor(res, "mankind"));
Assertions.assertEquals(1, res.size(), "result not found");
m_engine.getManager(PageManager.class).saveText(ctx, "[{ALLOW view Authenticated}] It was the dawn of the third age of mankind... page is blocked");
res = m_mgr.findPages("mankind", ctx);
Assertions.assertNotNull(res, "null result");
Assertions.assertEquals(0, res.size(), "result found, should be blocked");
m_engine.deleteTestPage("TestPage");
}
use of org.apache.wiki.api.search.SearchResult in project jspwiki by apache.
the class SaveWikiPageTaskTest method testSaveWikiPageTask.
@Test
public void testSaveWikiPageTask() throws Exception {
final TestEngine engine = TestEngine.build(with("jspwiki.lucene.initialdelay", "0"), with("jspwiki.lucene.indexdelay", "1"));
final String pageName = "TestSaveWikiPageTestPage";
final Page page = Wiki.contents().page(engine, pageName);
engine.saveText(pageName, "initial text on first revision");
final Context context = Wiki.context().create(engine, engine.newHttpRequest(), page);
final SaveWikiPageTask task = new SaveWikiPageTask();
task.setWorkflow(1, new HashMap<>());
task.getWorkflowContext().put(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, "correct horse battery staple");
final Collection<SearchResult> res = new ArrayList<>();
Assertions.assertEquals(Outcome.STEP_COMPLETE, task.execute(context));
Awaitility.await("ensure page gets indexed").until(findsResultsFor(context, res, "horse"));
Assertions.assertEquals(1, res.size(), "no pages found");
Assertions.assertEquals(pageName, res.iterator().next().getPage().getName(), "page");
}
Aggregations