Search in sources :

Example 16 with ResponseData

use of org.codelibs.fess.crawler.entity.ResponseData in project fess by codelibs.

the class DocumentHelperTest method test_getDigest.

public void test_getDigest() {
    DocumentHelper documentHelper = new DocumentHelper();
    ResponseData responseData = new ResponseData();
    Map<String, Object> dataMap = new HashMap<>();
    assertEquals("1234567...", documentHelper.getDigest(responseData, " 1234567890  1234567890  1234567890 ", dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, "123456789012345678901234567890", dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, "123456789012345678901", dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, "12345678901234567890", dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, "1234567890123456789", dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, "12345678901", dataMap, 10));
    assertEquals("1234567890", documentHelper.getDigest(responseData, "1234567890", dataMap, 10));
    assertEquals("123456789", documentHelper.getDigest(responseData, "123456789", dataMap, 10));
    assertEquals("1234567", documentHelper.getDigest(responseData, "1234567", dataMap, 10));
    assertEquals("1", documentHelper.getDigest(responseData, "1", dataMap, 10));
    assertEquals("", documentHelper.getDigest(responseData, "", dataMap, 10));
    assertEquals("", documentHelper.getDigest(responseData, " ", dataMap, 10));
    assertEquals("", documentHelper.getDigest(responseData, null, dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, " 1234567890  1234567890  1234567890 ", dataMap, 10));
    assertEquals("1234567...", documentHelper.getDigest(responseData, "12345678901234567890", dataMap, 10));
}
Also used : HashMap(java.util.HashMap) ResponseData(org.codelibs.fess.crawler.entity.ResponseData)

Example 17 with ResponseData

use of org.codelibs.fess.crawler.entity.ResponseData in project fess by codelibs.

the class DocumentHelperTest method test_getContent_maxAlphanum.

public void test_getContent_maxAlphanum() {
    DocumentHelper documentHelper = new DocumentHelper() {

        protected int getMaxAlphanumTermSize() {
            return 2;
        }
    };
    ResponseData responseData = new ResponseData();
    Map<String, Object> dataMap = new HashMap<>();
    assertEquals("", documentHelper.getContent(responseData, null, dataMap));
    assertEquals("", documentHelper.getContent(responseData, "", dataMap));
    assertEquals("", documentHelper.getContent(responseData, " ", dataMap));
    assertEquals("", documentHelper.getContent(responseData, "  ", dataMap));
    assertEquals("", documentHelper.getContent(responseData, "\t", dataMap));
    assertEquals("", documentHelper.getContent(responseData, "\t\t", dataMap));
    assertEquals("", documentHelper.getContent(responseData, "\t \t", dataMap));
    assertEquals("12 ab", documentHelper.getContent(responseData, " 123 abc ", dataMap));
    assertEquals("123 あいう", documentHelper.getContent(responseData, " 123 あいう ", dataMap));
    assertEquals("12 ab", documentHelper.getContent(responseData, " 123\nabc ", dataMap));
    assertEquals("12", documentHelper.getContent(responseData, " 123abc ", dataMap));
}
Also used : HashMap(java.util.HashMap) ResponseData(org.codelibs.fess.crawler.entity.ResponseData)

Example 18 with ResponseData

use of org.codelibs.fess.crawler.entity.ResponseData in project fess by codelibs.

the class FessXpathTransformerTest method test_processMetaRobots_none.

public void test_processMetaRobots_none() throws Exception {
    final String data = "<meta name=\"robots\" content=\"none\" />";
    final Document document = getDocument(data);
    final FessXpathTransformer transformer = new FessXpathTransformer();
    final ResponseData responseData = new ResponseData();
    responseData.setUrl("http://example.com/");
    try {
        transformer.processMetaRobots(responseData, new ResultData(), document);
        fail();
    } catch (ChildUrlsException e) {
        assertTrue(e.getChildUrlList().isEmpty());
    } catch (Exception e) {
        fail();
    }
}
Also used : ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException) ResultData(org.codelibs.fess.crawler.entity.ResultData) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) Document(org.w3c.dom.Document) ComponentNotFoundException(org.lastaflute.di.core.exception.ComponentNotFoundException) ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException)

Example 19 with ResponseData

use of org.codelibs.fess.crawler.entity.ResponseData in project fess by codelibs.

the class FessXpathTransformerTest method test_getThumbnailUrl_no.

public void test_getThumbnailUrl_no() throws Exception {
    final FessXpathTransformer transformer = new FessXpathTransformer();
    final ResponseData responseData = new ResponseData();
    responseData.setUrl("http://example.com/");
    String data = "<html><body>foo</body></html>";
    assertNull(transformer.getThumbnailUrl(responseData, getDocument(data)));
    data = "<img src=\"http://example/foo.jpg\" width=\"x\" height=\"x\">";
    assertNull(transformer.getThumbnailUrl(responseData, getDocument(data)));
    data = "<img src=\"http://example/foo.jpg\" width=\"10\" height=\"100\">";
    assertNull(transformer.getThumbnailUrl(responseData, getDocument(data)));
    data = "<img src=\"http://example/foo.jpg\" width=\"100\" height=\"10\">";
    assertNull(transformer.getThumbnailUrl(responseData, getDocument(data)));
    data = "<img src=\"http://example/foo.jpg\" width=\"400\" height=\"100\">";
    assertNull(transformer.getThumbnailUrl(responseData, getDocument(data)));
    data = "<img src=\"http://example/foo.jpg\" width=\"100\" height=\"400\">";
    assertNull(transformer.getThumbnailUrl(responseData, getDocument(data)));
}
Also used : ResponseData(org.codelibs.fess.crawler.entity.ResponseData)

Aggregations

ResponseData (org.codelibs.fess.crawler.entity.ResponseData)19 ResultData (org.codelibs.fess.crawler.entity.ResultData)10 HashMap (java.util.HashMap)8 Document (org.w3c.dom.Document)8 ChildUrlsException (org.codelibs.fess.crawler.exception.ChildUrlsException)7 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)4 CrawlerSystemException (org.codelibs.fess.crawler.exception.CrawlerSystemException)4 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)4 ComponentUtil (org.codelibs.fess.util.ComponentUtil)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 SerializeUtil (org.codelibs.core.io.SerializeUtil)3 StringUtil (org.codelibs.core.lang.StringUtil)3 ComponentNotFoundException (org.lastaflute.di.core.exception.ComponentNotFoundException)3