(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:
parent
ec8fe9f031
commit
5a62b3058f
@ -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;
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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(),
|
||||
|
@ -55,7 +55,7 @@ public class ApiSearchOperator {
|
||||
Math.min(100, count),
|
||||
150,
|
||||
8192),
|
||||
searchSet);
|
||||
searchSet.name());
|
||||
}
|
||||
|
||||
private SearchSetIdentifier selectSearchSet(int index) {
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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");
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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(),
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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),
|
||||
|
@ -49,7 +49,7 @@ public class QueryFactoryTest {
|
||||
SpecificationLimit.none(),
|
||||
null,
|
||||
new QueryLimits(100, 100, 100, 100),
|
||||
SearchSetIdentifier.BLOGS)).specs;
|
||||
"NONE")).specs;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user