Skip to content

Commit

Permalink
use SimpleQueryString search
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Barz <[email protected]>
  • Loading branch information
micbar committed Sep 6, 2021
1 parent 7103663 commit f4c2866
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def phpstan(ctx):
return pipelines

default = {
"phpVersions": ["7.3"],
"phpVersions": ["7.4"],
"logLevel": "2",
"extraApps": {},
"enableApp": True,
Expand Down
8 changes: 4 additions & 4 deletions lib/Search/ElasticSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ public function fetchResults($query, $size, $page) {

$es_bool = new BoolQuery();
$es_bool->addFilter($es_filter);
// wildcard queries are not analyzed, so ignore case. See http://stackoverflow.com/a/17280591
$loweredQuery = \strtolower($query);
if ($searchContent) {
$es_bool->addShould(new Query\MatchPhrasePrefix('file.content', $loweredQuery));
$es_content_query = new Query\SimpleQueryString($query, ['file.content']);
$es_content_query->setParam('analyze_wildcard', true);
$es_bool->addShould($es_content_query);
}
$es_bool->addShould(new Query\MatchPhrasePrefix('name', $loweredQuery));
$es_bool->addShould(new Query\SimpleQueryString($query, ['name']));
$es_bool->setMinimumShouldMatch(1);

$es_query = new Query($es_bool);
Expand Down
22 changes: 20 additions & 2 deletions tests/acceptance/features/webUISearchElastic/searchContent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,38 @@ Feature: Search
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
"""

Scenario: Search content only more than one word
When the user searches for "lorem ipsum sit" using the webUI
Then file "lorem.txt" with path "/simple-folder" should be listed in the search results in the other folders section on the webUI with highlights containing:
"""
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
"""

Scenario: Search content only (exact match)
When the user searches for "query" using the webUI
"""
"lorem ipsum sit"
"""
Then file "lorem.txt" with path "/simple-folder" should not be listed in the search results in the other folders section on the webUI

Scenario: Search content only (not exact case)
When the user searches for "iPsUM" using the webUI
Then file "lorem.txt" with path "/simple-folder" should be listed in the search results in the other folders section on the webUI with highlights containing:
"""
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
"""

Scenario: Search content only (not full word - end of word missing)
When the user searches for "ipsu" using the webUI
Scenario: Search content only (not full word - wildcard used)
When the user searches for "ipsu*" using the webUI
Then file "lorem.txt" with path "/simple-folder" should be listed in the search results in the other folders section on the webUI with highlights containing:
"""
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
"""

Scenario: Search content only (not full word - end of word missing)
When the user searches for "ipsu" using the webUI
Then file "lorem.txt" with path "/simple-folder" should not be listed in the search results in the other folders section on the webUI

@issue-38
Scenario: Search content only (not full word - start of word missing)
When the user searches for "psum" using the webUI
Expand Down

0 comments on commit f4c2866

Please sign in to comment.