Skip to content

Commit

Permalink
wrap up
Browse files Browse the repository at this point in the history
  • Loading branch information
MykolaGolubyev committed Sep 18, 2024
1 parent 0814548 commit 12004f0
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
public class GlobalSearchEntry {
private String url;
private String fullTitle;
private String text;
private SearchText text;

public GlobalSearchEntry() {
}

public GlobalSearchEntry(String url, String fullTitle, String text) {
this.url = url;
this.fullTitle = fullTitle;
this.text = text;
this.text = SearchScore.STANDARD.text(text);
}

public String getUrl() {
Expand All @@ -51,11 +51,11 @@ public void setFullTitle(String fullTitle) {
this.fullTitle = fullTitle;
}

public String getText() {
public SearchText getText() {
return text;
}

public void setText(String text) {
public void setText(SearchText text) {
this.text = text;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public List<SearchText> getSearchTextList() {
}

public String extractText() {
return searchTextList.stream().map(SearchText::getText).collect(Collectors.joining(" "));
return searchTextList.stream()
.map(SearchText::getText)
.filter(text -> !text.isEmpty())
.collect(Collectors.joining(" "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private SearchText createSearchText(SearchScore score, List<String> parts) {
.replaceAll("\\s+", " ")
.trim());
}

private void flushTextParts() {
if (standardScoreParts.isEmpty() && highScoreParts.isEmpty()) {
return;
Expand All @@ -175,5 +176,8 @@ private void flushTextParts() {
searchEntries.add(new PageSearchEntry(pageSectionTitle, List.of(
createSearchText(SearchScore.STANDARD, standardScoreParts),
createSearchText(SearchScore.HIGH, highScoreParts))));

standardScoreParts.clear();
highScoreParts.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SearchText {
public SearchText() {
}

public SearchText(SearchScore score, String text ) {
public SearchText(SearchScore score, String text) {
this.score = score;
this.text = removeNonReadableSymbols(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ world""")
"\n" +
"To create an `external` link use:\n")

parseResult.searchEntries().collect { it -> it.extractText() }.join(" ").should == "external Best To create an link use"
parseResult.searchEntries().collect { it -> it.extractText() }.join(" ").should == "Best To create an link use external"
}

private void parse(String markdown, Path path = Paths.get("test.md")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestMarkdownParser extends MarkdownParser {
def element = new DocElement('TestMarkdown', 'markdown', markdown)
page.addChild(element)

def searchEntry = new PageSearchEntry('dummy page section title', SearchScore.STANDARD.text(markdown))
def searchEntry = new PageSearchEntry('dummy page section title', [SearchScore.STANDARD.text(markdown)])

return new MarkupParserResult(page, [], [searchEntry], [], new PageMeta())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestMarkupParser implements MarkupParser {
def element = new DocElement("TestMarkup", "markup", markup)
page.addChild(element)

def searchEntry = new PageSearchEntry('dummy page section title', SearchScore.STANDARD.text(markup))
def searchEntry = new PageSearchEntry('dummy page section title', [SearchScore.STANDARD.text(markup)])

return new MarkupParserResult(page, [], [searchEntry], [], new PageMeta())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ class GlobalSearchEntriesTest {
void "should generate XML document"() {
def entries = new GlobalSearchEntries()
entries.addAll([
new GlobalSearchEntry('/doc-id/title1', 'full title 1', new SearchText('text 1', SearchScore.HIGH)),
new GlobalSearchEntry('/doc-id/title2', 'full title 2', new SearchText('text 2', SearchScore.STANDARD))])
new GlobalSearchEntry('/doc-id/title1', 'full title 1', 'text 1'),
new GlobalSearchEntry('/doc-id/title2', 'full title 2', 'text 2')])

println entries.toXml()
entries.toXml().should == '<znai>\n' +
' <entry>\n' +
' <url>/doc-id/title1</url>\n' +
' <fullTitle>full title 1</fullTitle>\n' +
' <text>\n' +
' <score>STANDARD</score>\n' +
' <text>text 1</text>\n' +
' <score>HIGH</score>\n' +
' </text>\n' +
' </entry>\n' +
' <entry>\n' +
' <url>/doc-id/title2</url>\n' +
' <fullTitle>full title 2</fullTitle>\n' +
' <text>\n' +
' <text>text 2</text>\n' +
' <score>STANDARD</score>\n' +
' <text>text 2</text>\n' +
' </text>\n' +
' </entry>\n' +
'</znai>\n'
Expand All @@ -52,18 +52,18 @@ class GlobalSearchEntriesTest {
void "should handle ansi sequences"() {
def entries = new GlobalSearchEntries()
entries.addAll([
new GlobalSearchEntry('/doc-id/title', 'title', new SearchText(
new GlobalSearchEntry('/doc-id/title', 'title',
"\u001B[1mwebtau:\u001B[m000\u001B" +
"[1m>\u001B[m http.get(\"https://jsonplaceholder.typicode.com/todos/1\")" +
" \u001B[33m> (\u001B[32m342ms\u001B[33m)\u001B[0m", SearchScore.STANDARD))])
" \u001B[33m> (\u001B[32m342ms\u001B[33m)\u001B[0m")])

entries.toXml().should == '<znai>\n' +
' <entry>\n' +
' <url>/doc-id/title</url>\n' +
' <fullTitle>title</fullTitle>\n' +
' <text>\n' +
' <text>webtau:000> http.get("https://jsonplaceholder.typicode.com/todos/1") > (342ms)</text>\n' +
' <score>STANDARD</score>\n' +
' <text>webtau:000> http.get("https://jsonplaceholder.typicode.com/todos/1") > (342ms)</text>\n' +
' </text>\n' +
' </entry>\n' +
'</znai>\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ class SearchCrawlerParserHandlerTest {
parserHandler.onInlinedCode("broker", DocReferences.EMPTY)
parserHandler.onSectionEnd()

parserHandler.getSearchEntries().should == [ "pageSectionTitle" | "searchText"] {
parserHandler.getSearchEntries().should == [ "pageSectionTitle" | "searchTextList"] {
______________________________________________________________________________
"section one" | [text: "hello", score: SearchScore.STANDARD]
"section one" | [text: "source code inlined term", score: SearchScore.HIGH]
"section two" | [text: "world", score: SearchScore.STANDARD]
"section two" | [text: "code broker", score: SearchScore.HIGH] }
"section one" | [[text: "hello", score: SearchScore.STANDARD], [text: "source code inlined term", score: SearchScore.HIGH]]
"section two" | [[text: "world", score: SearchScore.STANDARD], [text: "code broker", score: SearchScore.HIGH]] }
}

@Test
Expand All @@ -68,7 +66,7 @@ class SearchCrawlerParserHandlerTest {
parserHandler.onStrongEmphasisEnd()
}

searchEntries.searchTextList.text.should == ["Hello"]
searchEntries.collect { it.extractText() }.should == ["Hello"]
}

@Test
Expand All @@ -79,7 +77,7 @@ class SearchCrawlerParserHandlerTest {
parserHandler.onSimpleText("entry two.")
}

searchEntries.searchTextList.text.should == ["entry one entry two"]
searchEntries.collect { it.extractText() }.should == ["entry one entry two"]
}

@Test
Expand All @@ -90,7 +88,7 @@ class SearchCrawlerParserHandlerTest {
parserHandler.onSimpleText("entry two.")
}

searchEntries.searchTextList.text.should == ["entry one entry two"]
searchEntries.collect { it.extractText() }.should == ["entry one entry two"]
}

@Test
Expand All @@ -99,7 +97,7 @@ class SearchCrawlerParserHandlerTest {
parserHandler.onInlinedCode("record.access", DocReferences.EMPTY)
}

searchEntries.searchTextList.text.should == ["record access"]
searchEntries.collect { it.extractText() }.should == ["record access"]
}

@Test
Expand All @@ -109,7 +107,7 @@ class SearchCrawlerParserHandlerTest {
" --key=value")
}

searchEntries.searchTextList.text.should == ["hello world of quotes and separators like and maybe backward and " +
searchEntries.collect { it.extractText() }.should == ["hello world of quotes and separators like and maybe backward and " +
"inside different brackets and other key value"]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.junit.Test
class SearchTextTest {
@Test
void "should remove non readable symbols"() {
def searchText = new SearchText(
def searchText = new SearchText(SearchScore.STANDARD,
"CLI renders ANSI colors automatically. \u001B[1mwebtau:\u001B[m000\u001B" +
"[1m>\u001B[m http.get(\"https://jsonplaceholder.typicode.com/todos/1\") \u001B[33m>" +
" \u001B[34mexecuting HTTP GET" +
Expand All @@ -44,7 +44,7 @@ class SearchTextTest {
"\u001B[32m\"delectus aut autem\"\u001B[36m,\u001B[0m \u001B[35m\"completed\": " +
"false\u001B[0m \u001B[36m}\u001B[0m \u001B[32m. \u001B[34mexecuted HTTP GET " +
"\u001B[35mhttps://jsonplaceholder.typicode.com/todos/1\u001B[33m" +
" (\u001B[32m342ms\u001B[33m)\u001B[0m", SearchScore.STANDARD)
" (\u001B[32m342ms\u001B[33m)\u001B[0m")

searchText.text.should == "CLI renders ANSI colors automatically. webtau:000> " +
"http.get(\"https://jsonplaceholder.typicode.com/todos/1\") " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ second paragraph
[type: 'Emphasis', content: [[text: 'italic', type: 'SimpleText']]]]],
[type: 'Paragraph', content: [[text: ' second paragraph ', type: 'SimpleText']]]]

searchText.should == 'hello world another paragraph with bolditalic second paragraph'
searchText.should == 'hello another paragraph with bolditalic second paragraph world'
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class ServerSideSimplifiedRendererTest {
void "should render simple page for crawl indexing"() {
def searchEntries = new PageLocalSearchEntries(
toc.tocItems[0], [
new PageSearchEntry('PS0', SearchScore.STANDARD.text('hello \' " <> [] & world')),
new PageSearchEntry('PS1', SearchScore.STANDARD.text('of search'))])
new PageSearchEntry('PS0', [SearchScore.STANDARD.text('hello \' " <> [] & world')]),
new PageSearchEntry('PS1', [SearchScore.STANDARD.text('of search')])])

ServerSideSimplifiedRenderer.renderPageTextContent(searchEntries).should ==
ServerSideSimplifiedRenderer.LOADING_INDICATOR +
Expand Down

0 comments on commit 12004f0

Please sign in to comment.