Skip to content

Commit

Permalink
make search more greedy
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Barz <[email protected]>
  • Loading branch information
micbar committed Oct 29, 2021
1 parent 7103663 commit 42a6d76
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 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
16 changes: 11 additions & 5 deletions lib/Search/ElasticSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,27 @@ public function fetchResults($query, $size, $page) {
$searchContent = false;
}
}
// build query
$querySegments = \explode(" ", $query);
$query = "";
foreach ($querySegments as $segment) {
$query .= "*" . $segment . "* ";
}
$query = \trim($query, " ");

$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\QueryString($query);
$es_bool->addShould($es_content_query);
}
$es_bool->addShould(new Query\MatchPhrasePrefix('name', $loweredQuery));
$es_bool->addShould(new Query\QueryString("name:" . $query));
$es_bool->setMinimumShouldMatch(1);

$es_query = new Query($es_bool);
$es_query->setHighlight([
'fields' => [
'file.content' => new \stdClass,
'file.content' => new \stdClass
],
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Feature: Search for content
| Carol |
And user "Alice" has shared folder "just-a-folder" with user "Brian"
And user "Brian" has shared folder "just-a-folder" with user "Carol"
When user "Carol" uploads file with content "files with changed content" to "/just-a-folder/upload.txt" using the WebDAV API
When user "Carol" uploads file with content "files with a change of content" to "/just-a-folder/upload.txt" using the WebDAV API
And the search index has been updated
And user "Alice" searches for "change" using the WebDAV API
Then the HTTP status code should be "207"
Expand Down
38 changes: 27 additions & 11 deletions tests/acceptance/features/webUISearchElastic/searchContent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,53 @@ 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 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)
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 and beginning of word missing)
When the user searches for "psu" 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

@issue-38
Scenario: Search content only (not full word - start of word missing)
When the user searches for "psum" 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
#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:
# """
# This is lorem text in the simple-folder.
# """
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:
"""
This is lorem text in the simple-folder.
"""

@issue-38
Scenario: Search content only (not full word - only middle part of word given)
When the user searches for "psu" 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
#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:
# """
# This is lorem text in the simple-folder.
# """
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:
"""
This is lorem text in the simple-folder.
"""

Scenario: Search pattern matches filename of one file and content of others
Given user "Brian" has uploaded file with content "content to search for" to "/new-file.txt"
Expand Down

0 comments on commit 42a6d76

Please sign in to comment.