Fix search highlighting
This commit is contained in:
@@ -644,8 +644,8 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
// Build rich text with highlights for search results
|
// Build rich text with highlights for search results
|
||||||
List<InlineSpan> _buildHighlightedText(String highlightedText) {
|
List<InlineSpan> _buildHighlightedText(String highlightedText) {
|
||||||
List<InlineSpan> spans = [];
|
List<InlineSpan> spans = [];
|
||||||
// The text comes with <b>highlighted parts</b>
|
// The text comes with <highlight>highlighted parts</highlight>
|
||||||
RegExp exp = RegExp(r'<b>(.*?)</b>');
|
RegExp exp = RegExp(r'<highlight>(.*?)</highlight>');
|
||||||
|
|
||||||
int lastIndex = 0;
|
int lastIndex = 0;
|
||||||
for (final match in exp.allMatches(highlightedText)) {
|
for (final match in exp.allMatches(highlightedText)) {
|
||||||
@@ -656,7 +656,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
text: highlightedText.substring(lastIndex, match.start),
|
text: highlightedText.substring(lastIndex, match.start),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
), // Smaller font for regular text
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -669,7 +669,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
backgroundColor: Colors.yellow,
|
backgroundColor: Colors.yellow,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
fontSize: 13, // Smaller font for highlighted text
|
fontSize: 13,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -682,7 +682,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
spans.add(
|
spans.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: highlightedText.substring(lastIndex),
|
text: highlightedText.substring(lastIndex),
|
||||||
style: const TextStyle(fontSize: 13), // Smaller font for regular text
|
style: const TextStyle(fontSize: 13),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -805,24 +805,13 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
12, // Smaller font for date
|
12, // Smaller font for date
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
subtitle:
|
subtitle: Text.rich(
|
||||||
note.snippet != null
|
TextSpan(
|
||||||
? Text.rich(
|
children: _buildHighlightedText(
|
||||||
TextSpan(
|
note.snippet ?? note.content,
|
||||||
children:
|
),
|
||||||
_buildHighlightedText(
|
),
|
||||||
note.snippet!,
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Text(
|
|
||||||
note.content.length > 200
|
|
||||||
? '${note.content.substring(0, 200)}...'
|
|
||||||
: note.content,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
), // Smaller font for content
|
|
||||||
),
|
|
||||||
isThreeLine: true,
|
isThreeLine: true,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
// Save current note if needed
|
// Save current note if needed
|
||||||
|
@@ -184,8 +184,8 @@ Future<List<Note>> searchNotes(String query) async {
|
|||||||
limit: 10,
|
limit: 10,
|
||||||
attributesToHighlight: ['content'],
|
attributesToHighlight: ['content'],
|
||||||
showRankingScore: true,
|
showRankingScore: true,
|
||||||
highlightPreTag: '<b>',
|
highlightPreTag: '<highlight>',
|
||||||
highlightPostTag: '</b>',
|
highlightPostTag: '</highlight>',
|
||||||
);
|
);
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
||||||
@@ -201,7 +201,8 @@ Future<List<Note>> searchNotes(String query) async {
|
|||||||
(hit) => Note(
|
(hit) => Note(
|
||||||
id: hit['id'] as String,
|
id: hit['id'] as String,
|
||||||
epochTime: hit['date'] as int,
|
epochTime: hit['date'] as int,
|
||||||
content: hit['_formatted']['content'] as String,
|
content: hit['content'] as String,
|
||||||
|
snippet: hit['_formatted']['content'] as String,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
Reference in New Issue
Block a user