use of org.apache.wiki.api.search.QueryItem in project jspwiki by apache.
the class WikiProviderAdaptersTest method testAttachmentProvider.
@Test
public void testAttachmentProvider() throws Exception {
final AttachmentProvider attachmentProvider = engine.getManager(AttachmentManager.class).getCurrentProvider();
final Attachment att11 = new Attachment(engine, "page1", "att11.txt");
final Attachment att13 = new Attachment(engine, "page1", "att13.txt");
final QueryItem qi = new QueryItem();
qi.word = "doesn't matter will be ignored";
qi.type = QueryItem.REQUESTED;
Assertions.assertEquals("com.example.providers.TwoXWikiAttachmentProvider", attachmentProvider.getProviderInfo());
Assertions.assertEquals(2, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
final byte[] attDataArray = new byte[attachmentProvider.getAttachmentData(att11).available()];
attachmentProvider.getAttachmentData(att11).read(attDataArray);
Assertions.assertArrayEquals("blurb".getBytes(StandardCharsets.UTF_8), attDataArray);
Assertions.assertEquals(0, attachmentProvider.findAttachments(new QueryItem[] { qi }).size());
Assertions.assertEquals(3, attachmentProvider.listAllChanged(new Date(0L)).size());
Assertions.assertEquals(att11.getName(), attachmentProvider.getAttachmentInfo(new WikiPage(engine, "page1"), "att11.txt", 0).getName());
Assertions.assertEquals(1, attachmentProvider.getVersionHistory(att11).size());
attachmentProvider.putAttachmentData(att13, new ByteArrayInputStream("blorb".getBytes(StandardCharsets.UTF_8)));
Assertions.assertEquals(3, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
attachmentProvider.putAttachmentData(att13, new ByteArrayInputStream("blorb".getBytes(StandardCharsets.UTF_8)));
Assertions.assertEquals(2, attachmentProvider.getVersionHistory(att13).size());
attachmentProvider.deleteVersion(attachmentProvider.getVersionHistory(att13).get(1));
Assertions.assertEquals(1, attachmentProvider.getVersionHistory(att13).size());
attachmentProvider.deleteAttachment(att13);
Assertions.assertEquals(0, attachmentProvider.getVersionHistory(att13).size());
Assertions.assertEquals(2, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
attachmentProvider.moveAttachmentsForPage("page1", "page0");
Assertions.assertEquals(2, attachmentProvider.listAttachments(new WikiPage(engine, "page0")).size());
Assertions.assertEquals(0, attachmentProvider.listAttachments(new WikiPage(engine, "page1")).size());
}
use of org.apache.wiki.api.search.QueryItem in project jspwiki by apache.
the class WikiProviderAdaptersTest method testPageProvider.
@Test
public void testPageProvider() throws Exception {
final PageProvider pageProvider = engine.getManager(PageManager.class).getProvider();
final QueryItem qi = new QueryItem();
qi.word = "blablablabla";
qi.type = QueryItem.REQUESTED;
Assertions.assertEquals("com.example.providers.TwoXWikiPageProvider", pageProvider.getProviderInfo());
Assertions.assertEquals(3, pageProvider.getAllChangedSince(new Date(0L)).size());
Assertions.assertEquals(3, pageProvider.getAllPages().size());
Assertions.assertEquals(3, pageProvider.getPageCount());
Assertions.assertTrue(pageProvider.pageExists("page1"));
Assertions.assertTrue(pageProvider.pageExists("page1", 0));
pageProvider.movePage("page1", "page0");
Assertions.assertTrue(pageProvider.pageExists("page0"));
Assertions.assertFalse(pageProvider.pageExists("page1"));
pageProvider.putPageText(new WikiPage(engine, "page4"), "bloblobloblo");
Assertions.assertTrue(pageProvider.pageExists("page4"));
Assertions.assertEquals(1, pageProvider.findPages(new QueryItem[] { qi }).size());
pageProvider.putPageText(new WikiPage(engine, "page4"), "blublublublu");
Assertions.assertEquals(2, pageProvider.getVersionHistory("page4").size());
Assertions.assertEquals("bloblobloblo", pageProvider.getPageText("page4", 0));
Assertions.assertEquals("blublublublu", pageProvider.getPageText("page4", 1));
pageProvider.deleteVersion("page4", 1);
Assertions.assertEquals(1, pageProvider.getVersionHistory("page4").size());
pageProvider.deletePage("page4");
Assertions.assertFalse(pageProvider.pageExists("page4"));
}
use of org.apache.wiki.api.search.QueryItem in project jspwiki by apache.
the class SearchAdapterTest method testOldQueryItemfrom.
@Test
public void testOldQueryItemfrom() {
final QueryItem qi = new QueryItem();
qi.type = 1;
qi.word = "word";
final org.apache.wiki.search.QueryItem old = SearchAdapter.oldQueryItemfrom(qi);
Assertions.assertEquals(qi.type, old.type);
Assertions.assertEquals(qi.word, old.word);
}
use of org.apache.wiki.api.search.QueryItem in project jspwiki by apache.
the class BasicSearchProvider method parseQuery.
/**
* Parses a query into something that we can use.
*
* @param query A query string.
* @return A parsed array.
*/
public QueryItem[] parseQuery(final String query) {
final StringTokenizer st = new StringTokenizer(query, " \t,");
final QueryItem[] items = new QueryItem[st.countTokens()];
int word = 0;
log.debug("Expecting " + items.length + " items");
// Parse incoming search string
while (st.hasMoreTokens()) {
log.debug("Item " + word);
String token = st.nextToken().toLowerCase();
items[word] = new QueryItem();
switch(token.charAt(0)) {
case '+':
items[word].type = QueryItem.REQUIRED;
token = token.substring(1);
log.debug("Required word: " + token);
break;
case '-':
items[word].type = QueryItem.FORBIDDEN;
token = token.substring(1);
log.debug("Forbidden word: " + token);
break;
default:
items[word].type = QueryItem.REQUESTED;
log.debug("Requested word: " + token);
break;
}
items[word++].word = token;
}
return items;
}
use of org.apache.wiki.api.search.QueryItem in project jspwiki by apache.
the class WikiPageAdapterProvider method findPages.
/**
* {@inheritDoc}
*/
@Override
public Collection<SearchResult> findPages(final QueryItem[] query) {
final org.apache.wiki.search.QueryItem[] queryItems = Arrays.stream(query).map(SearchAdapter::oldQueryItemfrom).toArray(org.apache.wiki.search.QueryItem[]::new);
final Collection<org.apache.wiki.search.SearchResult> results = provider.findPages(queryItems);
return results.stream().map(SearchAdapter::newSearchResultFrom).collect(Collectors.toCollection(() -> new TreeSet<>(new SearchResultComparator())));
}
Aggregations