(query-api) Make the search set identifier a string value in the API

This will free the core marginalia search engine to use arbitrary search set definitions, while the app can use its hardcoded defaults.
This commit is contained in:
Viktor Lofgren 2024-01-16 10:55:24 +01:00
parent ec8fe9f031
commit 5a62b3058f
13 changed files with 34 additions and 29 deletions

View File

@ -15,7 +15,7 @@ public class SearchSpecification {
/** If present and not empty, limit the search to these domain IDs */
public List<Integer> domains;
public SearchSetIdentifier searchSetIdentifier;
public String searchSetIdentifier;
public final String humanQuery;

View File

@ -31,7 +31,7 @@ public class QueryProtobufCodec {
builder.addSubqueries(IndexProtobufCodec.convertSearchSubquery(subquery));
}
builder.setSearchSetIdentifier(query.specs.searchSetIdentifier.name());
builder.setSearchSetIdentifier(query.specs.searchSetIdentifier);
builder.setHumanQuery(request.getHumanQuery());
builder.setQuality(convertSpecLimit(query.specs.quality));
@ -62,7 +62,7 @@ public class QueryProtobufCodec {
convertSpecLimit(request.getDomainCount()),
request.getDomainIdsList(),
IndexProtobufCodec.convertQueryLimits(request.getQueryLimits()),
SearchSetIdentifier.valueOf(request.getSearchSetIdentifier()));
request.getSearchSetIdentifier());
}
@ -133,7 +133,7 @@ public class QueryProtobufCodec {
return new SearchSpecification(
subqueries,
specs.getDomainsList(),
SearchSetIdentifier.valueOf(specs.getSearchSetIdentifier()),
specs.getSearchSetIdentifier(),
specs.getHumanQuery(),
IndexProtobufCodec.convertSpecLimit(specs.getQuality()),
IndexProtobufCodec.convertSpecLimit(specs.getYear()),
@ -159,7 +159,7 @@ public class QueryProtobufCodec {
.setYear(convertSpecLimit(params.year()))
.setSize(convertSpecLimit(params.size()))
.setRank(convertSpecLimit(params.rank()))
.setSearchSetIdentifier(params.identifier().name());
.setSearchSetIdentifier(params.identifier());
if (params.nearDomain() != null)
builder.setNearDomain(params.nearDomain());

View File

@ -23,10 +23,10 @@ public record QueryParams(
SpecificationLimit domainCount,
List<Integer> domainIds,
QueryLimits limits,
SearchSetIdentifier identifier
String identifier
)
{
public QueryParams(String query, QueryLimits limits, SearchSetIdentifier identifier) {
public QueryParams(String query, QueryLimits limits, String identifier) {
this(query, null,
List.of(),
List.of(),

View File

@ -55,7 +55,7 @@ public class ApiSearchOperator {
Math.min(100, count),
150,
8192),
searchSet);
searchSet.name());
}
private SearchSetIdentifier selectSearchSet(int index) {

View File

@ -35,7 +35,7 @@ public class SearchQueryParamFactory {
SpecificationLimit.none(),
List.of(),
new QueryLimits(1, 25, 200, 8192),
profile.searchSetIdentifier
profile.searchSetIdentifier.name()
);
}
@ -54,7 +54,7 @@ public class SearchQueryParamFactory {
SpecificationLimit.none(),
List.of(),
new QueryLimits(count, count, 100, 512),
SearchSetIdentifier.NONE
SearchSetIdentifier.NONE.name()
);
}
@ -72,7 +72,7 @@ public class SearchQueryParamFactory {
SpecificationLimit.none(),
List.of(),
new QueryLimits(100, 100, 100, 512),
SearchSetIdentifier.NONE
SearchSetIdentifier.NONE.name()
);
}
@ -90,7 +90,7 @@ public class SearchQueryParamFactory {
SpecificationLimit.none(),
List.of(),
new QueryLimits(100, 100, 100, 512),
SearchSetIdentifier.NONE
SearchSetIdentifier.NONE.name()
);
}
}

View File

@ -79,7 +79,7 @@ public class SearchToBanService {
private Object executeQuery(Context ctx, String query) {
return queryClient.search(ctx, new QueryParams(
query, new QueryLimits(2, 200, 250, 8192),
SearchSetIdentifier.NONE
"NONE"
));
}
}

View File

@ -261,9 +261,7 @@ public class IndexQueryService extends IndexApiImplBase {
return new SmallSearchSet(request.getDomainsList());
}
return searchSetsService.getSearchSetByName(
SearchSetIdentifier.valueOf(request.getSearchSetIdentifier())
);
return searchSetsService.getSearchSetByName(request.getSearchSetIdentifier());
}
private SearchResultSet executeSearch(SearchParameters params) throws SQLException {

View File

@ -80,16 +80,19 @@ public class IndexSearchSetsService {
return domainRankings;
}
public SearchSet getSearchSetByName(SearchSetIdentifier searchSetIdentifier) {
public SearchSet getSearchSetByName(String searchSetIdentifier) {
if (null == searchSetIdentifier) {
return anySet;
}
return switch (searchSetIdentifier) {
case NONE -> anySet;
case POPULAR -> popularSet;
case ACADEMIA -> academiaSet;
case SMALLWEB -> smallWebSet;
case BLOGS -> blogsSet;
case "POPULAR" -> popularSet;
case "ACADEMIA" -> academiaSet;
case "SMALLWEB" -> smallWebSet;
case "BLOGS" -> blogsSet;
case "NONE", "" -> anySet;
default -> throw new IllegalArgumentException("Unknown search set");
};
}

View File

@ -129,7 +129,7 @@ public class IndexQueryServiceIntegrationSmokeTest {
.domainCount(SpecificationLimit.none())
.rankingParams(ResultRankingParameters.sensibleDefaults())
.domains(new ArrayList<>())
.searchSetIdentifier(SearchSetIdentifier.NONE)
.searchSetIdentifier("NONE")
.subqueries(List.of(new SearchSubquery(
List.of("3", "5", "2"), List.of("4"), Collections.emptyList(), Collections.emptyList(),
Collections.emptyList()))).build());
@ -207,7 +207,7 @@ public class IndexQueryServiceIntegrationSmokeTest {
.rank(SpecificationLimit.none())
.domainCount(SpecificationLimit.none())
.queryStrategy(QueryStrategy.SENTENCE)
.searchSetIdentifier(SearchSetIdentifier.NONE)
.searchSetIdentifier("NONE")
.rankingParams(ResultRankingParameters.sensibleDefaults())
.subqueries(List.of(new SearchSubquery(
List.of("4"), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),

View File

@ -431,7 +431,7 @@ public class IndexQueryServiceIntegrationTest {
.domainCount(SpecificationLimit.none())
.rankingParams(ResultRankingParameters.sensibleDefaults())
.domains(new ArrayList<>())
.searchSetIdentifier(SearchSetIdentifier.NONE)
.searchSetIdentifier("NONE")
.subqueries(List.of());
return mutator.apply(builder).build();

View File

@ -69,7 +69,7 @@ public class IndexQueryServiceIntegrationTestModule extends AbstractModule {
bind(ProcessHeartbeat.class).toInstance(new FakeProcessHeartbeat());
IndexSearchSetsService setsServiceMock = Mockito.mock(IndexSearchSetsService.class);
when(setsServiceMock.getSearchSetByName(SearchSetIdentifier.NONE)).thenReturn(new SearchSetAny());
when(setsServiceMock.getSearchSetByName("NONE")).thenReturn(new SearchSetAny());
when(setsServiceMock.getDomainRankings()).thenReturn(new DomainRankings());
bind(IndexSearchSetsService.class).toInstance(setsServiceMock);

View File

@ -44,9 +44,13 @@ public class QueryBasicInterface {
if (queryParam == null) {
return renderer.render(new Object());
}
int count = request.queryParams("count") == null ? 10 : Integer.parseInt(request.queryParams("count"));
String set = request.queryParams("set") == null ? "" : request.queryParams("set");
var query = queryFactory.createQuery(new QueryParams(queryParam, new QueryLimits(
1, 10, 250, 8192
), SearchSetIdentifier.NONE));
1, count, 250, 8192
), set));
var rsp = indexClient.query(
Context.fromRequest(request),

View File

@ -49,7 +49,7 @@ public class QueryFactoryTest {
SpecificationLimit.none(),
null,
new QueryLimits(100, 100, 100, 100),
SearchSetIdentifier.BLOGS)).specs;
"NONE")).specs;
}
@Test