-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use WhitespaceTokenizer instead of StandardTokenizer https://stackoverflow.com/a/6119584/21694752
- Loading branch information
1 parent
909afe4
commit bfa1356
Showing
9 changed files
with
33 additions
and
35 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
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
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
33 changes: 20 additions & 13 deletions
33
src/test/java/org/jabref/logic/search/LuceneQueryParserTest.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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
package org.jabref.logic.search; | ||
|
||
import java.util.EnumSet; | ||
import java.util.stream.Stream; | ||
|
||
import org.jabref.model.search.SearchFlags; | ||
import org.jabref.model.search.SearchQuery; | ||
import org.jabref.logic.cleanup.Formatter; | ||
import org.jabref.logic.layout.format.LatexToUnicodeFormatter; | ||
import org.jabref.model.search.SearchFieldConstants; | ||
|
||
import org.apache.lucene.analysis.core.WhitespaceAnalyzer; | ||
import org.apache.lucene.queryparser.classic.ParseException; | ||
import org.apache.lucene.queryparser.classic.QueryParser; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class LuceneQueryParserTest { | ||
private static final Formatter FORMATTER = new LatexToUnicodeFormatter(); | ||
|
||
public static Stream<Arguments> searchQuires() { | ||
return Stream.of( | ||
// unicode | ||
Arguments.of("preissinger", "preißinger"), | ||
Arguments.of("jesus", "jesús"), | ||
Arguments.of("breitenbucher", "breitenbücher"), | ||
Arguments.of("all:preissinger", "preißinger"), | ||
Arguments.of("all:jesus", "jesús"), | ||
Arguments.of("all:breitenbucher", "breitenbücher"), | ||
|
||
// latex | ||
Arguments.of("preissinger", "prei{\\ss}inger"), | ||
Arguments.of("jesus", "jes{\\'{u}}s"), | ||
Arguments.of("breitenbucher", "breitenb{\\\"{u}}cher") | ||
Arguments.of("all:preissinger", "prei{\\ss}inger"), | ||
Arguments.of("all:jesus", "jes{\\'{u}}s"), | ||
Arguments.of("all:breitenbucher", "breitenb{\\\"{u}}cher"), | ||
|
||
Arguments.of("groups:/exclude", "groups:\\/exclude") | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void searchQuires(String expected, String query) { | ||
expected = "(all:" + expected + ")^4.0"; | ||
SearchQuery searchQuery = new SearchQuery(query, EnumSet.noneOf(SearchFlags.class)); | ||
assertEquals(expected, searchQuery.getParsedQuery().toString()); | ||
void searchQuires(String expected, String query) throws ParseException { | ||
QueryParser parser = new QueryParser(SearchFieldConstants.DEFAULT_FIELD.toString(), new WhitespaceAnalyzer()); | ||
query = FORMATTER.format(query); | ||
String result = parser.parse(query).toString(); | ||
assertEquals(expected, result); | ||
} | ||
} |
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