Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-4142 Support projection id from stub backend
- Loading branch information
Showing
5 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...pl/integrationtest/common/stub/backend/search/projection/impl/StubIdSearchProjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.projection.impl; | ||
|
||
import org.hibernate.search.engine.backend.common.DocumentReference; | ||
import org.hibernate.search.engine.backend.types.converter.spi.DocumentIdentifierValueConverter; | ||
import org.hibernate.search.engine.search.loading.spi.LoadingResult; | ||
import org.hibernate.search.engine.search.loading.spi.ProjectionHitMapper; | ||
import org.hibernate.search.engine.search.projection.SearchProjection; | ||
import org.hibernate.search.engine.search.projection.spi.IdProjectionBuilder; | ||
|
||
public class StubIdSearchProjection<I> implements StubSearchProjection<I> { | ||
|
||
private final DocumentIdentifierValueConverter<? extends I> identifierValueConverter; | ||
|
||
private StubIdSearchProjection(DocumentIdentifierValueConverter<? extends I> identifierValueConverter) { | ||
this.identifierValueConverter = identifierValueConverter; | ||
} | ||
|
||
@Override | ||
public Object extract(ProjectionHitMapper<?, ?> projectionHitMapper, Object projectionFromIndex, | ||
StubSearchProjectionContext context) { | ||
return projectionFromIndex; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public I transform(LoadingResult<?, ?> loadingResult, Object extractedData, | ||
StubSearchProjectionContext context) { | ||
DocumentReference documentReference = (DocumentReference) extractedData; | ||
|
||
context.fromDocumentFieldValueConvertContext(); | ||
return identifierValueConverter.convertToSource( | ||
documentReference.id(), context.fromDocumentIdentifierValueConvertContext() ); | ||
} | ||
|
||
public static class Builder<I> implements IdProjectionBuilder<I> { | ||
|
||
private final StubSearchProjection<I> projection; | ||
|
||
public Builder(DocumentIdentifierValueConverter<?> identifierValueConverter, Class<I> identifierType) { | ||
// check expected identifier type: | ||
identifierValueConverter.requiresType( identifierType ); | ||
@SuppressWarnings("uncheked") // just checked | ||
DocumentIdentifierValueConverter<? extends I> casted = (DocumentIdentifierValueConverter<? extends I>) identifierValueConverter; | ||
|
||
projection = new StubIdSearchProjection( casted ); | ||
} | ||
|
||
@Override | ||
public SearchProjection<I> build() { | ||
return projection; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters