mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 18:26:16 +01:00
Refactor Search API and allow analyzer per field (#1755)
The Search api is now simpler, because it provides useful defaults. Only if you want to deviate from the defaults, you can set these values. This is mostly reached by using the builder pattern. Furthermore it is now possible to configure an analyzer per field. The default analyzer is still the one which is derived from the index options, but it is possible to configure a new indexer with the analyzer attribute of the indexed annotation. The attribute allows the configuration for code, identifiers and path. The current implementation uses the same analyzer code, identifiers and path. The new implemented splits tokens on more delimiters as the default analyzer e.g.: dots, underscores etc. Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -30,9 +30,8 @@ import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.search.HandlerEventIndexSyncer;
|
||||
import sonia.scm.search.Id;
|
||||
import sonia.scm.search.Index;
|
||||
import sonia.scm.search.IndexNames;
|
||||
import sonia.scm.search.IndexQueue;
|
||||
import sonia.scm.search.Indexer;
|
||||
import sonia.scm.search.SearchEngine;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@@ -41,18 +40,16 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class UserIndexer implements Indexer<User> {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String INDEX = IndexNames.DEFAULT;
|
||||
@VisibleForTesting
|
||||
static final int VERSION = 1;
|
||||
|
||||
private final UserManager userManager;
|
||||
private final IndexQueue queue;
|
||||
private final SearchEngine searchEngine;
|
||||
|
||||
@Inject
|
||||
public UserIndexer(UserManager userManager, IndexQueue queue) {
|
||||
public UserIndexer(UserManager userManager, SearchEngine searchEngine) {
|
||||
this.userManager = userManager;
|
||||
this.queue = queue;
|
||||
this.searchEngine = searchEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,11 +57,6 @@ public class UserIndexer implements Indexer<User> {
|
||||
return User.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndex() {
|
||||
return INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return VERSION;
|
||||
@@ -77,15 +69,15 @@ public class UserIndexer implements Indexer<User> {
|
||||
|
||||
@Override
|
||||
public Updater<User> open() {
|
||||
return new UserIndexUpdater(userManager, queue.getQueuedIndex(INDEX));
|
||||
return new UserIndexUpdater(userManager, searchEngine.forType(User.class).getOrCreate());
|
||||
}
|
||||
|
||||
public static class UserIndexUpdater implements Updater<User> {
|
||||
|
||||
private final UserManager userManager;
|
||||
private final Index index;
|
||||
private final Index<User> index;
|
||||
|
||||
private UserIndexUpdater(UserManager userManager, Index index) {
|
||||
private UserIndexUpdater(UserManager userManager, Index<User> index) {
|
||||
this.userManager = userManager;
|
||||
this.index = index;
|
||||
}
|
||||
@@ -97,12 +89,12 @@ public class UserIndexer implements Indexer<User> {
|
||||
|
||||
@Override
|
||||
public void delete(User user) {
|
||||
index.delete(Id.of(user), User.class);
|
||||
index.delete().byType().byId(Id.of(user));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reIndexAll() {
|
||||
index.deleteByType(User.class);
|
||||
index.delete().byType().all();
|
||||
for (User user : userManager.getAll()) {
|
||||
store(user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user