Skip to content

Commit

Permalink
Clean up single forward slashes in search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Aug 31, 2018
1 parent 8ba3691 commit 8e1bbeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/modules/IndexComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ public SearchResponse query(String q, String filter, int from, int size) {

@Override
public QueryStringQueryBuilder queryStringQuery(String q) {
// Clean up single forward slash, but keep regular /expressions/
q = q.indexOf('/') == q.lastIndexOf('/') ? q.replace("/", " ") : q;
return QueryBuilders.queryStringQuery(q).defaultOperator(Operator.AND);
}
}
6 changes: 6 additions & 0 deletions test/modules/IndexQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public void testBooleanSearch() {
Assert.assertEquals(6, index.query("twain OR schriftsteller").getHits().getTotalHits());
}

@Test
public void testSlashInQuery() {
Assert.assertEquals(1, index.query("Hauptschule / Lehrer").getHits().getTotalHits());
Assert.assertEquals(1, index.query("/[Hh]auptschulen?/").getHits().getTotalHits());
}

@Test
public void testContextQuery() {
Assert.assertEquals(0, index.query("context.jsonld").getHits().getTotalHits());
Expand Down

0 comments on commit 8e1bbeb

Please sign in to comment.