Skip to content

Commit 01c36ff

Browse files
committed
Fix syntax highlighting in Marko's post
1 parent 9b54350 commit 01c36ff

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

_posts/2024-08-01-search-standalone-mapper.adoc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ which will create the documents in the search index that we will later use to pe
5353
Generally speaking, mass indexing can be as simple as:
5454

5555
[source, java]
56-
====
5756
----
5857
@Inject
5958
SearchMapping searchMapping; // <1>
@@ -68,15 +67,13 @@ var future = searchMapping.scope(Object.class) // <2>
6867
In this case, all indexed entities should be targeted; hence, the `Object.class` can be used to create the scope.
6968
3. Create a mass indexer with the default configuration.
7069
4. Start the indexing process. Starting the process returns a future; the indexing happens in the background.
71-
====
7270

7371
For Hibernate Search to perform this operation, we must tell it how to load the indexed entities.
7472
We will use an `EntityLoadingBinder` to do that. It is a simple interface providing access to the binding context
7573
where we can define selection-loading strategies (for search) and mass-loading strategies (for indexing).
7674
Since, in our case, we are only interested in the mass indexer, it would be enough only to define the mass loading strategy:
7775

7876
[source, java]
79-
====
8077
----
8178
public class GuideLoadingBinder implements EntityLoadingBinder {
8279
@@ -91,12 +88,10 @@ public class GuideLoadingBinder implements EntityLoadingBinder {
9188
1. Implement the single `bind(..)` method of the `EntityLoadingBinder`.
9289
2. Specify the mass loading strategy for the `Guide` search entity.
9390
We'll discuss the implementation of the strategy later in this post.
94-
====
9591

9692
And then, with the entity loading binder defined, we can simply reference it within the `@SearchEntity` annotation:
9793

9894
[source, java]
99-
====
10095
----
10196
@SearchEntity(loadingBinder = @EntityLoadingBinderRef(type = GuideLoadingBinder.class)) // <1>
10297
@Indexed( ... )
@@ -112,7 +107,6 @@ public class Guide {
112107
As with many other Hibernate Search components,
113108
a CDI bean reference can be used here instead by providing the bean name,
114109
for example, if the loading binder requires access to some CDI beans and is a CDI bean itself.
115-
====
116110

117111
That is all that is needed to tie things together.
118112
The only open question is how to implement the mass loading strategy.
@@ -134,7 +128,6 @@ than just pass through the batch of received "identifiers", which are actual ent
134128
With that in mind, the mass-loading strategy may be implemented as:
135129

136130
[source, java]
137-
====
138131
----
139132
new MassLoadingStrategy<Guide, Guide>() {
140133
@Override
@@ -167,7 +160,6 @@ it is slightly trickier than the pass-through entity loader.
167160
Hence, we would want to take a closer look at it.
168161
2. An implementation of the pass-through entity loader.
169162
3. As explained above, we treat the search entities as identifiers and simply pass the entities we receive to the sink.
170-
====
171163

172164
NOTE: If passing entities as identifiers feels like a hack, it's because it is.
173165
Hibernate Search will, at some point, provide alternative APIs to achieve this more elegantly: link:https://hibernate.atlassian.net/browse/HSEARCH-5209[HSEARCH-5209]
@@ -178,7 +170,6 @@ We could do this by using the `MassLoadingOptions options`.
178170
These mass loading options provide access to the context objects passed to the mass indexer by the user.
179171

180172
[source, java]
181-
====
182173
----
183174
@Inject
184175
SearchMapping searchMapping; // <1>
@@ -198,6 +189,8 @@ for an example of how such context can be implemented.
198189
4. Set any other mass indexer configuration options as needed.
199190
5. Create a mass indexer.
200191
6. Start the indexing process.
192+
193+
[source, java]
201194
----
202195
public class GuideLoadingContext {
203196
@@ -220,14 +213,12 @@ public class GuideLoadingContext {
220213
2. Read the next batch of the guides from the iterator. We are using the batch size limit
221214
that we will retrieve from the mass-loading options
222215
and checking the iterator to see if there are any more entities to pull.
223-
====
224216

225217
Now, having the way of reading the entities in batches from the stream
226218
and knowing how to pass it to the mass indexer, implementing the identifier loader
227219
can be as easy as:
228220

229221
[source, java]
230-
====
231222
----
232223
@Override
233224
public MassIdentifierLoader createIdentifierLoader(LoadingTypeGroup<Guide> includedTypes,
@@ -270,7 +261,6 @@ for the current mass indexer.
270261
4. If the batch is empty, it means that the stream iterator has no more guides to return.
271262
Hence, we can notify the mass indexing sink that no more items will be provided by calling `.complete()`.
272263
5. If there are any guides in the loaded batch, we'll pass them to the sink to be processed.
273-
====
274264

275265
To sum up, here is a summary of the steps to take to index an unknown number of search entities from a datasource
276266
while reading each entity only once, and without relying on lookups by identifier:

0 commit comments

Comments
 (0)