Usage
- By default, all searchable attributes are highlighted.
- The special value
*may be used to highlight all attributes. - Pass an empty array (
[]) to turn off highlighting. - Algolia highlights the first 50,000 characters of the whole result set (5,000 logograms for CJK languages). This limit prevents impacting the user experience by ensuring a fast response time even with large results.
- When highlighting is enabled, each hit in the response contains a
_highlightResultobject. - When enabled, each hit includes a
_highlightResultobject with metadata about the matches.
_highlightResult
Hide child attributes
Hide child attributes
string
Matching text, surrounded by HTML tags defined in the
highlightPreTag
and highlightPostTag settings.enum<string>
Indicates how well the attribute matched the search query.
Possible values are
none, partial, full.list<string>
List of query words that matched the record.
boolean
Whether the entire attribute value is highlighted.
Examples
Set default list of attributes to highlight
Current API clients
Current API clients
var response = await client.SetSettingsAsync(
"INDEX_NAME",
new IndexSettings
{
AttributesToHighlight = new List<string> { "author", "title", "content" },
}
);
final response = await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(
attributesToHighlight: [
"author",
"title",
"content",
],
),
);
response, err := client.SetSettings(client.NewApiSetSettingsRequest(
"INDEX_NAME",
search.NewEmptyIndexSettings().SetAttributesToHighlight(
[]string{"author", "title", "content"})))
if err != nil {
// handle the eventual error
panic(err)
}
UpdatedAtResponse response = client.setSettings(
"INDEX_NAME",
new IndexSettings().setAttributesToHighlight(Arrays.asList("author", "title", "content"))
);
const response = await client.setSettings({
indexName: 'theIndexName',
indexSettings: { attributesToHighlight: ['author', 'title', 'content'] },
});
var response =
client.setSettings(
indexName = "INDEX_NAME",
indexSettings = IndexSettings(attributesToHighlight = listOf("author", "title", "content")),
)
$response = $client->setSettings(
'INDEX_NAME',
['attributesToHighlight' => [
'author',
'title',
'content',
],
],
);
response = client.set_settings(
index_name="INDEX_NAME",
index_settings={
"attributesToHighlight": [
"author",
"title",
"content",
],
},
)
response = client.set_settings(
"INDEX_NAME",
Algolia::Search::IndexSettings.new(attributes_to_highlight: ["author", "title", "content"])
)
val response = Await.result(
client.setSettings(
indexName = "INDEX_NAME",
indexSettings = IndexSettings(
attributesToHighlight = Some(Seq("author", "title", "content"))
)
),
Duration(100, "sec")
)
let response = try await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(attributesToHighlight: ["author", "title", "content"])
)
Legacy API clients
Legacy API clients
IndexSettings settings = new IndexSettings()
settings.AttributesToHighlight = new List
{
"author",
"title",
"content"
};
index.SetSettings(settings);
res, err := index.SetSettings(search.Settings{
AttributesToHighlight: opt.AttributesToHighlight(
"author",
"title",
"content",
),
})
index.setSettings(
new IndexSettings()
.setAttributesToHighlight(Arrays.asList(
"author",
"title",
"content"
))
);
index
.setSettings({
attributesToHighlight: ["author", "title", "content"],
})
.then(() => {
// done
});
val settings = settings {
attributesToHighlight {
+"author"
+"title"
+"content"
}
}
index.setSettings(settings)
$index->setSettings([
'attributesToHighlight' => [
"author",
"title",
"content"
]
]);
index.set_settings({"attributesToHighlight": ["author", "title", "content"]})
index.set_settings(
{
attributesToHighlight: [
"author",
"title",
"content"
]
}
)
client.execute {
setSettings of "myIndex" `with` IndexSettings(
attributesToHighlight = Some(Seq(
"author",
"title",
"content",
))
)
}
let settings = Settings()
.set(\.attributesToHighlight, to: [
"author",
"title",
"content"
])
index.setSettings(settings) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
Make all attributes highlighted by default
Current API clients
Current API clients
var response = await client.SetSettingsAsync(
"INDEX_NAME",
new IndexSettings { AttributesToHighlight = new List<string> { "*" } }
);
final response = await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(
attributesToHighlight: [
"*",
],
),
);
response, err := client.SetSettings(client.NewApiSetSettingsRequest(
"INDEX_NAME",
search.NewEmptyIndexSettings().SetAttributesToHighlight(
[]string{"*"})))
if err != nil {
// handle the eventual error
panic(err)
}
UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setAttributesToHighlight(Arrays.asList("*")));
const response = await client.setSettings({
indexName: 'theIndexName',
indexSettings: { attributesToHighlight: ['*'] },
});
var response =
client.setSettings(
indexName = "INDEX_NAME",
indexSettings = IndexSettings(attributesToHighlight = listOf("*")),
)
$response = $client->setSettings(
'INDEX_NAME',
['attributesToHighlight' => [
'*',
],
],
);
response = client.set_settings(
index_name="INDEX_NAME",
index_settings={
"attributesToHighlight": [
"*",
],
},
)
response = client.set_settings(
"INDEX_NAME",
Algolia::Search::IndexSettings.new(attributes_to_highlight: ["*"])
)
val response = Await.result(
client.setSettings(
indexName = "INDEX_NAME",
indexSettings = IndexSettings(
attributesToHighlight = Some(Seq("*"))
)
),
Duration(100, "sec")
)
let response = try await client.setSettings(
indexName: "INDEX_NAME",
indexSettings: IndexSettings(attributesToHighlight: ["*"])
)
Legacy API clients
Legacy API clients
IndexSettings settings = new IndexSettings()
settings.AttributesToHighlight = new List
{
"*"
};
index.SetSettings(settings);
res, err := index.SetSettings(search.Settings{
AttributesToHighlight: opt.AttributesToHighlight(
"*",
),
})
index.setSettings(
new IndexSettings()
.setAttributesToHighlight(Arrays.asList(
"*"
))
);
index
.setSettings({
attributesToHighlight: ["*"],
})
.then(() => {
// done
});
val query = query("query") {
attributesToHighlight {
+"*"
}
}
index.search(query)
$index->setSettings([
'attributesToHighlight' => [
"*"
]
]);
index.set_settings({"attributesToHighlight": ["*"]})
index.set_settings(
{
attributesToHighlight: [
"*"
]
}
)
client.execute {
setSettings of "myIndex" `with` IndexSettings(
attributesToHighlight = Some(Seq(
"*"
))
)
}
let settings = Settings()
.set(\.attributesToHighlight, to: [
"*"
])
index.setSettings(settings) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
Override list of attributes to highlight for the current search
Current API clients
Current API clients
var response = await client.SearchSingleIndexAsync<Hit>(
"INDEX_NAME",
new SearchParams(
new SearchParamsObject
{
Query = "query",
AttributesToHighlight = new List<string> { "title", "content" },
}
)
);
final response = await client.searchSingleIndex(
indexName: "INDEX_NAME",
searchParams: SearchParamsObject(
query: "query",
attributesToHighlight: [
"title",
"content",
],
),
);
response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
"INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
search.NewEmptySearchParamsObject().SetQuery("query").SetAttributesToHighlight(
[]string{"title", "content"}))))
if err != nil {
// handle the eventual error
panic(err)
}
SearchResponse response = client.searchSingleIndex(
"INDEX_NAME",
new SearchParamsObject().setQuery("query").setAttributesToHighlight(Arrays.asList("title", "content")),
Hit.class
);
const response = await client.searchSingleIndex({
indexName: 'indexName',
searchParams: { query: 'query', attributesToHighlight: ['title', 'content'] },
});
var response =
client.searchSingleIndex(
indexName = "INDEX_NAME",
searchParams =
SearchParamsObject(query = "query", attributesToHighlight = listOf("title", "content")),
)
$response = $client->searchSingleIndex(
'INDEX_NAME',
['query' => 'query',
'attributesToHighlight' => [
'title',
'content',
],
],
);
response = client.search_single_index(
index_name="INDEX_NAME",
search_params={
"query": "query",
"attributesToHighlight": [
"title",
"content",
],
},
)
response = client.search_single_index(
"INDEX_NAME",
Algolia::Search::SearchParamsObject.new(query: "query", attributes_to_highlight: ["title", "content"])
)
val response = Await.result(
client.searchSingleIndex(
indexName = "INDEX_NAME",
searchParams = Some(
SearchParamsObject(
query = Some("query"),
attributesToHighlight = Some(Seq("title", "content"))
)
)
),
Duration(100, "sec")
)
let response: SearchResponse<Hit> = try await client.searchSingleIndex(
indexName: "INDEX_NAME",
searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
query: "query",
attributesToHighlight: ["title", "content"]
))
)
Legacy API clients
Legacy API clients
index.Search(new Query("query")
{
AttributesToHighlight = new List { "title", "content" }
});
res, err := index.Search(
"query",
opt.AttributesToHighlight("title", "content"),
)
index.search(
new Query("query")
.setAttributesToHighlight(
Arrays.asList(
"title",
"content"
)
)
);
index
.search("query", {
attributesToHighlight: ["title", "content"],
})
.then(({ hits }) => {
console.log(hits);
});
$results = $index->search('query', [
'attributesToHighlight' => [
"title",
"content"
]
]);
results = index.search("query", {"attributesToHighlight": ["title", "content"]})
results = index.search(
"query",
{
attributesToHighlight: [
"title",
"content"
]
}
)
client.execute {
search into "myIndex" query Query(
query = Some("query"),
attributesToHighlight = Some(Seq(
"title",
"content"
))
)
}
let query = Query("query")
.set(\.attributesToHighlight, to: [
"title",
"content"
])
index.search(query: query) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}