forked from dadoonet/fscrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a filter by content option (dadoonet#585)
You can filter out documents you would like to index by adding one or more regular expression that match the extracted content. Documents which are not matching will be simply ignored and not indexed. If you define the following `fs.filters` property in your `~/.fscrawler/test/_settings.json` file: ```json { "name" : "test", "fs": { "filters": [ ".*foo.*", "^4\\d{3}([\\ \\-]?)\\d{4}\\1\\d{4}\\1\\d{4}$" ] } } ``` With this example, only documents which contains the word `foo` and a VISA credit card number with the form like `4012888888881881`, `4012 8888 8888 1881` or `4012-8888-8888-1881` will be indexed. Closes dadoonet#463.
- Loading branch information
Showing
20 changed files
with
355 additions
and
52 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
57 changes: 57 additions & 0 deletions
57
...test/java/fr/pilato/elasticsearch/crawler/fs/test/integration/FsCrawlerTestFiltersIT.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,57 @@ | ||
/* | ||
* Licensed to David Pilato (the "Author") under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Author licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package fr.pilato.elasticsearch.crawler.fs.test.integration; | ||
|
||
import fr.pilato.elasticsearch.crawler.fs.settings.Fs; | ||
import org.elasticsearch.action.search.SearchRequest; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test filters crawler settings | ||
*/ | ||
public class FsCrawlerTestFiltersIT extends AbstractFsCrawlerITCase { | ||
@Test | ||
public void test_filter_one_term() throws Exception { | ||
Fs fs = startCrawlerDefinition() | ||
.addFilter(".*foo.*") | ||
.build(); | ||
startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null); | ||
countTestHelper(new SearchRequest(getCrawlerName()), 2L, null); | ||
} | ||
|
||
@Test | ||
public void test_filter_visa_pattern() throws Exception { | ||
Fs fs = startCrawlerDefinition() | ||
.addFilter("^4\\d{3}([\\ \\-]?)\\d{4}\\1\\d{4}\\1\\d{4}$") | ||
.build(); | ||
startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null); | ||
countTestHelper(new SearchRequest(getCrawlerName()), 2L, null); | ||
} | ||
|
||
@Test | ||
public void test_filter_visa_pattern_plus_foo() throws Exception { | ||
Fs fs = startCrawlerDefinition() | ||
.addFilter("^4\\d{3}([\\ \\-]?)\\d{4}\\1\\d{4}\\1\\d{4}$") | ||
.addFilter(".*foo.*") | ||
.build(); | ||
startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null); | ||
countTestHelper(new SearchRequest(getCrawlerName()), 1L, null); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
integration-tests/src/test/resources-binary/samples/test_filter_one_term/foo.txt
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 @@ | ||
This is containing foo as one of the words. |
1 change: 1 addition & 0 deletions
1
integration-tests/src/test/resources-binary/samples/test_filter_one_term/sample.txt
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 @@ | ||
This file contains some words. |
8 changes: 8 additions & 0 deletions
8
...ion-tests/src/test/resources-binary/samples/test_filter_one_term/visa-number-with-foo.txt
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,8 @@ | ||
This file contains | ||
|
||
4012-8888-8888-1881 | ||
|
||
^^^ This is a fake VISA number. | ||
|
||
This will be indexed unless we check for a word which | ||
is not inside this text, like "foo". |
8 changes: 8 additions & 0 deletions
8
integration-tests/src/test/resources-binary/samples/test_filter_one_term/visa-number.txt
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,8 @@ | ||
This file contains | ||
|
||
4012-8888-8888-1881 | ||
|
||
^^^ This is a fake VISA number. | ||
|
||
This will be indexed unless we check for a word which | ||
is not inside this text, like "f o o" without the spaces. |
1 change: 1 addition & 0 deletions
1
integration-tests/src/test/resources-binary/samples/test_filter_visa_pattern/foo.txt
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 @@ | ||
This is containing foo as one of the words. |
1 change: 1 addition & 0 deletions
1
integration-tests/src/test/resources-binary/samples/test_filter_visa_pattern/sample.txt
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 @@ | ||
This file contains some words. |
8 changes: 8 additions & 0 deletions
8
...tests/src/test/resources-binary/samples/test_filter_visa_pattern/visa-number-with-foo.txt
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,8 @@ | ||
This file contains | ||
|
||
4012-8888-8888-1881 | ||
|
||
^^^ This is a fake VISA number. | ||
|
||
This will be indexed unless we check for a word which | ||
is not inside this text, like "foo". |
8 changes: 8 additions & 0 deletions
8
integration-tests/src/test/resources-binary/samples/test_filter_visa_pattern/visa-number.txt
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,8 @@ | ||
This file contains | ||
|
||
4012-8888-8888-1881 | ||
|
||
^^^ This is a fake VISA number. | ||
|
||
This will be indexed unless we check for a word which | ||
is not inside this text, like "f o o" without the spaces. |
1 change: 1 addition & 0 deletions
1
...gration-tests/src/test/resources-binary/samples/test_filter_visa_pattern_plus_foo/foo.txt
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 @@ | ||
This is containing foo as one of the words. |
1 change: 1 addition & 0 deletions
1
...tion-tests/src/test/resources-binary/samples/test_filter_visa_pattern_plus_foo/sample.txt
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 @@ | ||
This file contains some words. |
8 changes: 8 additions & 0 deletions
8
.../test/resources-binary/samples/test_filter_visa_pattern_plus_foo/visa-number-with-foo.txt
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,8 @@ | ||
This file contains | ||
|
||
4012-8888-8888-1881 | ||
|
||
^^^ This is a fake VISA number. | ||
|
||
This will be indexed unless we check for a word which | ||
is not inside this text, like "foo". |
8 changes: 8 additions & 0 deletions
8
...tests/src/test/resources-binary/samples/test_filter_visa_pattern_plus_foo/visa-number.txt
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,8 @@ | ||
This file contains | ||
|
||
4012-8888-8888-1881 | ||
|
||
^^^ This is a fake VISA number. | ||
|
||
This will be indexed unless we check for a word which | ||
is not inside this text, like "f o o" without the spaces. |
Oops, something went wrong.