doks
doks copied to clipboard
flexsearch show results including 'title and content', content maybe too long
Summary
if content is too long, we may truncate the data, and append "...read more" instead. If so, we can display up to 5 results successfully.
Basic example
For example, we expect following results when searching:
But If I didn't set the liquid tag description neither summary, the body will be returned by index.search
, the body length maybe too long to take up all the display space. The following results will not be shown.
Motivation
To display all the results normally.
Solution
In the show_results function, we can add following code to achive this.
159 const description = document.createElement('span');
160 if (doc.description.length > 128) {
161 description.textContent = doc.description.substring(0, 128)+"...read more";
162 } else {
163 description.textContent = doc.description;
164 }
If this feature request will be admitted, I can submit a PR.
@james-d-elliott, what's your opinion on this /do you expect it to play nicely with your work on the search part?
Shouldn't be an issue. The area I've currently modified is what pages to be included in the index, this looks like the actual text in the index.
I was thinking it would also be nice to show the matched result in context (i.e. if it matches a portion of the body of a document to make sure that's shown rather than the description) but not entirely sure how.
@hitzhangjie, nice one. If you could make this a PR, yes please!
Also side note, if you merge this one before my one, I'm happy to resolve conflicts locally if they occur.
I prefer something like this:
resultIndex = doc.description.indexOf(searchQuery);
description.textContent = doc.description.substring(resultIndex-64, resultIndex+64)+"...read more";
And it would be nice if we can highlight the result in the content.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.