forked from jaeksoft/opensearchserver
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b0cae1
commit d1fe4ab
Showing
7 changed files
with
889 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
release date=12:00 14.09.2017,version=1.6.0,urgency=low,by=Emmanuel Keller <[email protected]>,distribution=unknown | ||
* GH-1900: Allow leading wildcard in Pattern query | ||
* GH-1881: Support of array in database crawler | ||
* GH-1879: Parsing of BLOB in the Database crawler | ||
* GH-1877: ClosedChannelException on Terms extraction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/com/jaeksoft/searchlib/test/HtmlParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* License Agreement for OpenSearchServer | ||
* <p> | ||
* Copyright (C) 2016-2017 Emmanuel Keller / Jaeksoft | ||
* <p> | ||
* http://www.open-search-server.com | ||
* <p> | ||
* This file is part of OpenSearchServer. | ||
* <p> | ||
* OpenSearchServer is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* <p> | ||
* OpenSearchServer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* <p> | ||
* You should have received a copy of the GNU General Public License | ||
* along with OpenSearchServer. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
**/ | ||
package com.jaeksoft.searchlib.test; | ||
|
||
import com.jaeksoft.searchlib.SearchLibException; | ||
import com.jaeksoft.searchlib.analysis.ClassPropertyEnum; | ||
import com.jaeksoft.searchlib.analysis.LanguageEnum; | ||
import com.jaeksoft.searchlib.parser.HtmlParser; | ||
import com.jaeksoft.searchlib.parser.ParserFieldEnum; | ||
import com.jaeksoft.searchlib.parser.ParserFieldTarget; | ||
import com.jaeksoft.searchlib.parser.ParserResultItem; | ||
import com.jaeksoft.searchlib.parser.htmlParser.HtmlParserEnum; | ||
import com.jaeksoft.searchlib.streamlimiter.StreamLimiter; | ||
import com.jaeksoft.searchlib.streamlimiter.StreamLimiterFile; | ||
import com.jaeksoft.searchlib.util.map.SourceField; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
public class HtmlParserTest { | ||
|
||
private void testGeneratedSourceWithExclusion(final HtmlParserEnum htmlParserEnum) { | ||
try { | ||
final Path htmlFile = | ||
Paths.get("src", "test", "resources", "com", "jaeksoft", "searchlib", "test", "oss.html"); | ||
final StreamLimiter streamLimiter = | ||
new StreamLimiterFile(0, htmlFile.toFile(), htmlFile.toUri().toString()); | ||
final HtmlParser parser = new HtmlParser(); | ||
parser.initProperties(); | ||
parser.getFieldMap() | ||
.add(new SourceField("generatedSource"), | ||
new ParserFieldTarget("generatedSource", null, null, false)); | ||
parser.setUserProperty(ClassPropertyEnum.XPATH_EXCLUSION.getName(), "//h3"); | ||
parser.setUserProperty(ClassPropertyEnum.HTML_PARSER.getName(), htmlParserEnum.getLabel()); | ||
parser.doParserContent(null, null, streamLimiter, LanguageEnum.ENGLISH); | ||
final List<ParserResultItem> results = parser.getParserResults(); | ||
final String htmlProvider = results.get(0).getFieldValue(ParserFieldEnum.htmlProvider, 0); | ||
Assert.assertEquals(htmlParserEnum.getLabel(), htmlProvider); | ||
final String generatedSource = results.get(0).getFieldValue(ParserFieldEnum.generatedSource, 0); | ||
Assert.assertTrue(generatedSource.contains("<h4>")); | ||
Assert.assertFalse(generatedSource.contains("<h3>")); | ||
} catch (IOException | SearchLibException e) { | ||
Assert.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGeneratedSourceWithExclusionHtmlCleaner() { | ||
testGeneratedSourceWithExclusion(HtmlParserEnum.HtmlCleanerParser); | ||
} | ||
|
||
@Test | ||
public void testGeneratedSourceWithExclusionTagSoup() { | ||
testGeneratedSourceWithExclusion(HtmlParserEnum.TagSoupParser); | ||
} | ||
|
||
@Test | ||
public void testGeneratedSourceWithExclusionNekoHtml() { | ||
testGeneratedSourceWithExclusion(HtmlParserEnum.NekoHtmlParser); | ||
} | ||
} |
Oops, something went wrong.