doks icon indicating copy to clipboard operation
doks copied to clipboard

flexsearch show results including 'title and content', content maybe too long

Open hitzhangjie opened this issue 2 years ago • 7 comments

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: image

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.

hitzhangjie avatar Jun 25 '22 15:06 hitzhangjie

@james-d-elliott, what's your opinion on this /do you expect it to play nicely with your work on the search part?

h-enk avatar Jul 01 '22 09:07 h-enk

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.

james-d-elliott avatar Jul 04 '22 01:07 james-d-elliott

@hitzhangjie, nice one. If you could make this a PR, yes please!

h-enk avatar Jul 04 '22 05:07 h-enk

Also side note, if you merge this one before my one, I'm happy to resolve conflicts locally if they occur.

james-d-elliott avatar Jul 04 '22 05:07 james-d-elliott

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.

Mythologyli avatar Jul 19 '22 11:07 Mythologyli

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.

github-actions[bot] avatar Aug 19 '22 00:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Aug 25 '22 00:08 github-actions[bot]