| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.collection; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 2 | |
| 3 | import java.util.*; |
| 4 | |
| 5 | import org.apache.lucene.search.RegexpQuery; |
| 6 | import org.apache.lucene.index.Term; |
| 7 | |
| 8 | /** |
| 9 | * @author Nils Diewald |
| 10 | * |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 11 | * RegexFilter implements a helper object for |
| 12 | * regular expressions used in KorapFilter |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 13 | * constraints. |
| 14 | */ |
| 15 | |
| 16 | public class RegexFilter { |
| 17 | String regex; |
| 18 | |
| 19 | public RegexFilter (String regex) { |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 20 | this.regex = regex; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | public RegexpQuery toQuery (String field) { |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 24 | return new RegexpQuery( |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 25 | new Term(field, this.regex) |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 26 | ); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 27 | }; |
| 28 | }; |