(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 */
|
/** If present and not empty, limit the search to these domain IDs */
|
||||||
public List<Integer> domains;
|
public List<Integer> domains;
|
||||||
|
|
||||||
public SearchSetIdentifier searchSetIdentifier;
|
public String searchSetIdentifier;
|
||||||
|
|
||||||
public final String humanQuery;
|
public final String humanQuery;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class QueryProtobufCodec {
|
|||||||
builder.addSubqueries(IndexProtobufCodec.convertSearchSubquery(subquery));
|
builder.addSubqueries(IndexProtobufCodec.convertSearchSubquery(subquery));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setSearchSetIdentifier(query.specs.searchSetIdentifier.name());
|
builder.setSearchSetIdentifier(query.specs.searchSetIdentifier);
|
||||||
builder.setHumanQuery(request.getHumanQuery());
|
builder.setHumanQuery(request.getHumanQuery());
|
||||||
|
|
||||||
builder.setQuality(convertSpecLimit(query.specs.quality));
|
builder.setQuality(convertSpecLimit(query.specs.quality));
|
||||||
@ -62,7 +62,7 @@ public class QueryProtobufCodec {
|
|||||||
convertSpecLimit(request.getDomainCount()),
|
convertSpecLimit(request.getDomainCount()),
|
||||||
request.getDomainIdsList(),
|
request.getDomainIdsList(),
|
||||||
IndexProtobufCodec.convertQueryLimits(request.getQueryLimits()),
|
IndexProtobufCodec.convertQueryLimits(request.getQueryLimits()),
|
||||||
SearchSetIdentifier.valueOf(request.getSearchSetIdentifier()));
|
request.getSearchSetIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ public class QueryProtobufCodec {
|
|||||||
return new SearchSpecification(
|
return new SearchSpecification(
|
||||||
subqueries,
|
subqueries,
|
||||||
specs.getDomainsList(),
|
specs.getDomainsList(),
|
||||||
SearchSetIdentifier.valueOf(specs.getSearchSetIdentifier()),
|
specs.getSearchSetIdentifier(),
|
||||||
specs.getHumanQuery(),
|
specs.getHumanQuery(),
|
||||||
IndexProtobufCodec.convertSpecLimit(specs.getQuality()),
|
IndexProtobufCodec.convertSpecLimit(specs.getQuality()),
|
||||||
IndexProtobufCodec.convertSpecLimit(specs.getYear()),
|
IndexProtobufCodec.convertSpecLimit(specs.getYear()),
|
||||||
@ -159,7 +159,7 @@ public class QueryProtobufCodec {
|
|||||||
.setYear(convertSpecLimit(params.year()))
|
.setYear(convertSpecLimit(params.year()))
|
||||||
.setSize(convertSpecLimit(params.size()))
|
.setSize(convertSpecLimit(params.size()))
|
||||||
.setRank(convertSpecLimit(params.rank()))
|
.setRank(convertSpecLimit(params.rank()))
|
||||||
.setSearchSetIdentifier(params.identifier().name());
|
.setSearchSetIdentifier(params.identifier());
|
||||||
|
|
||||||
if (params.nearDomain() != null)
|
if (params.nearDomain() != null)
|
||||||
builder.setNearDomain(params.nearDomain());
|
builder.setNearDomain(params.nearDomain());
|
||||||
|
@ -23,10 +23,10 @@ public record QueryParams(
|
|||||||
SpecificationLimit domainCount,
|
SpecificationLimit domainCount,
|
||||||
List<Integer> domainIds,
|
List<Integer> domainIds,
|
||||||
QueryLimits limits,
|
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,
|
this(query, null,
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(),
|
List.of(),
|
||||||
|
@ -55,7 +55,7 @@ public class ApiSearchOperator {
|
|||||||
Math.min(100, count),
|
Math.min(100, count),
|
||||||
150,
|
150,
|
||||||
8192),
|
8192),
|
||||||
searchSet);
|
searchSet.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchSetIdentifier selectSearchSet(int index) {
|
private SearchSetIdentifier selectSearchSet(int index) {
|
||||||
|
@ -35,7 +35,7 @@ public class SearchQueryParamFactory {
|
|||||||
SpecificationLimit.none(),
|
SpecificationLimit.none(),
|
||||||
List.of(),
|
List.of(),
|
||||||
new QueryLimits(1, 25, 200, 8192),
|
new QueryLimits(1, 25, 200, 8192),
|
||||||
profile.searchSetIdentifier
|
profile.searchSetIdentifier.name()
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ public class SearchQueryParamFactory {
|
|||||||
SpecificationLimit.none(),
|
SpecificationLimit.none(),
|
||||||
List.of(),
|
List.of(),
|
||||||
new QueryLimits(count, count, 100, 512),
|
new QueryLimits(count, count, 100, 512),
|
||||||
SearchSetIdentifier.NONE
|
SearchSetIdentifier.NONE.name()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class SearchQueryParamFactory {
|
|||||||
SpecificationLimit.none(),
|
SpecificationLimit.none(),
|
||||||
List.of(),
|
List.of(),
|
||||||
new QueryLimits(100, 100, 100, 512),
|
new QueryLimits(100, 100, 100, 512),
|
||||||
SearchSetIdentifier.NONE
|
SearchSetIdentifier.NONE.name()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ public class SearchQueryParamFactory {
|
|||||||
SpecificationLimit.none(),
|
SpecificationLimit.none(),
|
||||||
List.of(),
|
List.of(),
|
||||||
new QueryLimits(100, 100, 100, 512),
|
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) {
|
private Object executeQuery(Context ctx, String query) {
|
||||||
return queryClient.search(ctx, new QueryParams(
|
return queryClient.search(ctx, new QueryParams(
|
||||||
query, new QueryLimits(2, 200, 250, 8192),
|
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 new SmallSearchSet(request.getDomainsList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return searchSetsService.getSearchSetByName(
|
return searchSetsService.getSearchSetByName(request.getSearchSetIdentifier());
|
||||||
SearchSetIdentifier.valueOf(request.getSearchSetIdentifier())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
private SearchResultSet executeSearch(SearchParameters params) throws SQLException {
|
private SearchResultSet executeSearch(SearchParameters params) throws SQLException {
|
||||||
|
|
||||||
|
@ -80,16 +80,19 @@ public class IndexSearchSetsService {
|
|||||||
return domainRankings;
|
return domainRankings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchSet getSearchSetByName(SearchSetIdentifier searchSetIdentifier) {
|
public SearchSet getSearchSetByName(String searchSetIdentifier) {
|
||||||
|
|
||||||
if (null == searchSetIdentifier) {
|
if (null == searchSetIdentifier) {
|
||||||
return anySet;
|
return anySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
return switch (searchSetIdentifier) {
|
return switch (searchSetIdentifier) {
|
||||||
case NONE -> anySet;
|
case "POPULAR" -> popularSet;
|
||||||
case POPULAR -> popularSet;
|
case "ACADEMIA" -> academiaSet;
|
||||||
case ACADEMIA -> academiaSet;
|
case "SMALLWEB" -> smallWebSet;
|
||||||
case SMALLWEB -> smallWebSet;
|
case "BLOGS" -> blogsSet;
|
||||||
case BLOGS -> blogsSet;
|
case "NONE", "" -> anySet;
|
||||||
|
default -> throw new IllegalArgumentException("Unknown search set");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public class IndexQueryServiceIntegrationSmokeTest {
|
|||||||
.domainCount(SpecificationLimit.none())
|
.domainCount(SpecificationLimit.none())
|
||||||
.rankingParams(ResultRankingParameters.sensibleDefaults())
|
.rankingParams(ResultRankingParameters.sensibleDefaults())
|
||||||
.domains(new ArrayList<>())
|
.domains(new ArrayList<>())
|
||||||
.searchSetIdentifier(SearchSetIdentifier.NONE)
|
.searchSetIdentifier("NONE")
|
||||||
.subqueries(List.of(new SearchSubquery(
|
.subqueries(List.of(new SearchSubquery(
|
||||||
List.of("3", "5", "2"), List.of("4"), Collections.emptyList(), Collections.emptyList(),
|
List.of("3", "5", "2"), List.of("4"), Collections.emptyList(), Collections.emptyList(),
|
||||||
Collections.emptyList()))).build());
|
Collections.emptyList()))).build());
|
||||||
@ -207,7 +207,7 @@ public class IndexQueryServiceIntegrationSmokeTest {
|
|||||||
.rank(SpecificationLimit.none())
|
.rank(SpecificationLimit.none())
|
||||||
.domainCount(SpecificationLimit.none())
|
.domainCount(SpecificationLimit.none())
|
||||||
.queryStrategy(QueryStrategy.SENTENCE)
|
.queryStrategy(QueryStrategy.SENTENCE)
|
||||||
.searchSetIdentifier(SearchSetIdentifier.NONE)
|
.searchSetIdentifier("NONE")
|
||||||
.rankingParams(ResultRankingParameters.sensibleDefaults())
|
.rankingParams(ResultRankingParameters.sensibleDefaults())
|
||||||
.subqueries(List.of(new SearchSubquery(
|
.subqueries(List.of(new SearchSubquery(
|
||||||
List.of("4"), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
|
List.of("4"), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
|
||||||
|
@ -431,7 +431,7 @@ public class IndexQueryServiceIntegrationTest {
|
|||||||
.domainCount(SpecificationLimit.none())
|
.domainCount(SpecificationLimit.none())
|
||||||
.rankingParams(ResultRankingParameters.sensibleDefaults())
|
.rankingParams(ResultRankingParameters.sensibleDefaults())
|
||||||
.domains(new ArrayList<>())
|
.domains(new ArrayList<>())
|
||||||
.searchSetIdentifier(SearchSetIdentifier.NONE)
|
.searchSetIdentifier("NONE")
|
||||||
.subqueries(List.of());
|
.subqueries(List.of());
|
||||||
|
|
||||||
return mutator.apply(builder).build();
|
return mutator.apply(builder).build();
|
||||||
|
@ -69,7 +69,7 @@ public class IndexQueryServiceIntegrationTestModule extends AbstractModule {
|
|||||||
bind(ProcessHeartbeat.class).toInstance(new FakeProcessHeartbeat());
|
bind(ProcessHeartbeat.class).toInstance(new FakeProcessHeartbeat());
|
||||||
|
|
||||||
IndexSearchSetsService setsServiceMock = Mockito.mock(IndexSearchSetsService.class);
|
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());
|
when(setsServiceMock.getDomainRankings()).thenReturn(new DomainRankings());
|
||||||
bind(IndexSearchSetsService.class).toInstance(setsServiceMock);
|
bind(IndexSearchSetsService.class).toInstance(setsServiceMock);
|
||||||
|
|
||||||
|
@ -44,9 +44,13 @@ public class QueryBasicInterface {
|
|||||||
if (queryParam == null) {
|
if (queryParam == null) {
|
||||||
return renderer.render(new Object());
|
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(
|
var query = queryFactory.createQuery(new QueryParams(queryParam, new QueryLimits(
|
||||||
1, 10, 250, 8192
|
1, count, 250, 8192
|
||||||
), SearchSetIdentifier.NONE));
|
), set));
|
||||||
|
|
||||||
var rsp = indexClient.query(
|
var rsp = indexClient.query(
|
||||||
Context.fromRequest(request),
|
Context.fromRequest(request),
|
||||||
|
@ -49,7 +49,7 @@ public class QueryFactoryTest {
|
|||||||
SpecificationLimit.none(),
|
SpecificationLimit.none(),
|
||||||
null,
|
null,
|
||||||
new QueryLimits(100, 100, 100, 100),
|
new QueryLimits(100, 100, 100, 100),
|
||||||
SearchSetIdentifier.BLOGS)).specs;
|
"NONE")).specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user