-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imlement scoring in elk for search elements #148
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a80bf21
implement decendent
jamal-khey 499b4dc
re-index update the full path
jamal-khey e502a84
remove full pathName
jamal-khey ce5eefa
Merge branch 'refs/heads/main' into jamal-khey/store-path-in-elastic-…
jamal-khey 871a8db
fix build
jamal-khey 5dff01c
implement scoring
jamal-khey 1d4257e
Merge branch 'refs/heads/main' into jamal-khey/store-path-in-elastic-…
jamal-khey 7791be7
Merge branch 'main' into jamal-khey/store-path-in-elastic-search
jamal-khey f5e0cff
fix reindex test
jamal-khey 78842e8
fix sonar
jamal-khey c7866f5
adjust sciring
jamal-khey 0899d3c
add base test for scoring
jamal-khey 6cc8436
add unit test for testing search results
jamal-khey cc28696
refactor code
jamal-khey abdc408
improve test cases
jamal-khey 7d7e779
filter the Orphan elements from search results
jamal-khey 9a221de
fix sonar issues
jamal-khey cbf8b95
Merge branch 'main' of https://github.com/gridsuite/directory-server …
bd27a46
add test , multiple file in the same dir
jamal-khey b22990d
fix styles
jamal-khey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
*/ | ||
package org.gridsuite.directory.server.services; | ||
|
||
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery; | ||
import co.elastic.clients.elasticsearch._types.FieldValue; | ||
import co.elastic.clients.elasticsearch._types.query_dsl.*; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import org.gridsuite.directory.server.dto.elasticsearch.DirectoryElementInfos; | ||
|
@@ -15,7 +16,6 @@ | |
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.elasticsearch.client.elc.NativeQuery; | ||
import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder; | ||
import org.springframework.data.elasticsearch.client.elc.Queries; | ||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations; | ||
import org.springframework.data.elasticsearch.core.SearchHit; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -35,6 +35,8 @@ public class DirectoryElementInfosService { | |
private final ElasticsearchOperations elasticsearchOperations; | ||
|
||
private static final String ELEMENT_NAME = "name.fullascii"; | ||
private static final String FULL_PATH_UUID = "fullPathUuid"; | ||
private static final String PARENT_ID = "parentId"; | ||
static final String ELEMENT_TYPE = "type.keyword"; | ||
|
||
@Value(ESConfig.DIRECTORY_ELEMENT_INFOS_INDEX_NAME) | ||
|
@@ -45,10 +47,48 @@ public DirectoryElementInfosService(ElasticsearchOperations elasticsearchOperati | |
this.elasticsearchOperations = elasticsearchOperations; | ||
} | ||
|
||
public List<DirectoryElementInfos> searchElements(@NonNull String userInput) { | ||
public List<DirectoryElementInfos> searchElements(@NonNull String userInput, String currentDirectoryUuid) { | ||
|
||
// We dont want to show the directories | ||
Query directory = TermQuery.of(m -> m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Queries.termQuery(ELEMENT_TYPE, DIRECTORY)._toQuery() ? |
||
.field(ELEMENT_TYPE) | ||
.value(DIRECTORY) | ||
)._toQuery(); | ||
|
||
// This query is used to search for elements whose name contains the user input. | ||
Query elementNameContainSearchTerm = WildcardQuery.of(m -> m | ||
.field(ELEMENT_NAME) | ||
.wildcard("*" + escapeLucene(userInput) + "*") | ||
)._toQuery(); | ||
|
||
// This query is used to search for elements whose name exactly matches the user input. | ||
Query exactMatchName = MatchQuery.of(m -> m | ||
.field(ELEMENT_NAME) | ||
.query(escapeLucene(userInput)) | ||
.boost(4.0f) | ||
)._toQuery(); | ||
|
||
// the element is in path | ||
TermsQueryField termsQueryField = new TermsQueryField.Builder() | ||
.value(List.of(FieldValue.of(currentDirectoryUuid))) | ||
.build(); | ||
Query fullPathQuery = TermsQuery.of(t -> t | ||
.field(FULL_PATH_UUID) | ||
.terms(termsQueryField) | ||
.boost(1.0f) | ||
)._toQuery(); | ||
|
||
// boost the result if the element is in the current search directory | ||
Query parentIdQuery = MatchQuery.of(m -> m | ||
.field(PARENT_ID) | ||
.query(currentDirectoryUuid) | ||
.boost(1.0f) | ||
)._toQuery(); | ||
|
||
BoolQuery query = new BoolQuery.Builder() | ||
.mustNot(Queries.termQuery(ELEMENT_TYPE, DIRECTORY)._toQuery()) | ||
.must(Queries.wildcardQuery(ELEMENT_NAME, "*" + escapeLucene(userInput) + "*")._toQuery()) | ||
.mustNot(directory) | ||
.must(elementNameContainSearchTerm) // if a doccument doesn’t match the must clause, it will be filtered out. | ||
.should(fullPathQuery, parentIdQuery, exactMatchName) // boost the query the document match | ||
.build(); | ||
|
||
NativeQuery nativeQuery = new NativeQueryBuilder() | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SlimaneAmar in case of deletion of a directory , we can still have Orphans