From e357ade47d116c9b65b413666e467f9826dbeb9b Mon Sep 17 00:00:00 2001 From: luccioman Date: Sun, 13 May 2018 10:29:52 +0200 Subject: Reduced memory footprint of text snippet extraction By not parsing and storing at first all sentences of a document, but only on the fly the ones necessary to compute the snippet. --- .../net/yacy/search/snippet/TextSnippetTest.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'test/java') diff --git a/test/java/net/yacy/search/snippet/TextSnippetTest.java b/test/java/net/yacy/search/snippet/TextSnippetTest.java index f572ee0e2..2d12c5d24 100644 --- a/test/java/net/yacy/search/snippet/TextSnippetTest.java +++ b/test/java/net/yacy/search/snippet/TextSnippetTest.java @@ -88,8 +88,30 @@ public class TextSnippetTest { for (String word : wordlist) { assertTrue("testTextSnippet word included " + word, rstr.contains(word)); } - } + + /** + * Test snippet extraction when only document title matches searched terms. + * @throws MalformedURLException when the test document URL is malformed. Should not happen. + */ + @Test + public void testTextSnippetMatchTitle() throws MalformedURLException { + final URIMetadataNode testDoc = new URIMetadataNode(doc); + testDoc.addField(CollectionSchema.title.name(), "New test case title"); + testDoc.addField(CollectionSchema.keywords.name(), "junit"); + testDoc.addField(CollectionSchema.author.name(), "test author"); + testDoc.addField(CollectionSchema.text_t.name(), + "A new testcase has been introduced. " + "It includes a few test lines but only title should match."); + + final String querywords = "title"; + final QueryGoal qg = new QueryGoal(querywords); + + final TextSnippet ts = new TextSnippet(null, testDoc, qg.getIncludeWordsSet(), qg.getIncludeHashes(), + cacheStrategy, pre, snippetMaxLength, reindexing); + assertEquals("testTextSnippet Error Code: ", "", ts.getError()); + assertTrue("Snippet line should be extracted from first text lines.", + ts.getLineRaw().startsWith("A new testcase has been introduced.")); + } /** * Test of getLineMarked method, of class TextSnippet. -- cgit v1.2.3