(search) Experimental support for clustering search results

Improves clustering of results.
This commit is contained in:
Viktor Lofgren 2024-02-11 19:58:55 +01:00
parent a77846373b
commit 7cc8b0fed5
2 changed files with 0 additions and 17 deletions

View file

@ -1,7 +1,6 @@
package nu.marginalia.search;
import nu.marginalia.query.model.QueryResponse;
import nu.marginalia.search.command.SearchParameters;
import nu.marginalia.search.model.ClusteredUrlDetails;
import nu.marginalia.search.model.UrlDetails;
@ -46,7 +45,6 @@ public class SearchResultClusterer {
)
.values().stream()
.map(ClusteredUrlDetails::new)
.mapMulti(ClusteredUrlDetails::splitSmallClusters) // split small clusters into singletons
.sorted()
.limit(total)
.toList();

View file

@ -6,7 +6,6 @@ import nu.marginalia.model.idx.WordFlags;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/** A class to hold a list of UrlDetails, grouped by domain, where the first one is the main result
@ -72,20 +71,6 @@ public class ClusteredUrlDetails implements Comparable<ClusteredUrlDetails> {
@Getter
public final List<UrlDetails> rest;
public void splitSmallClusters(Consumer<ClusteredUrlDetails> consumer) {
if (rest.isEmpty())
consumer.accept(this);
else if (rest.size() < 2) { // Only one additional result
consumer.accept(new ClusteredUrlDetails(first));
rest.stream()
.map(ClusteredUrlDetails::new)
.forEach(consumer);
}
else {
consumer.accept(this);
}
}
public EdgeDomain getDomain() {
return first.url.getDomain();
}