Search Results: Preview search term in result text

Hello,

Long story short, there is interest to add preview text to the results on our search page, like one might find in a search engine’s result.

Something like this:

Mockup of search results with segment of target's text included, the search term in the text highlighted.

This seems like it could be possible, somehow, but I can’t wrap my head around it.

  • Has anyone done something like this using the LiveWhale widgets/search?
  • Does anyone have ideas for if/how to achieve this using LiveWhale widgets/search?

Thanks,
Nick

You can use the {description} var in your widget format. I believe that even bolds words that match the search term. It might not be exactly what you want though, as I believe it just uses the first X characters from the text of the page instead of a snippet from the page that is relevant to the search term.

do you mean something like this:?

https://www.brockport.edu/academics/academic-affairs/faculty-accomplishments/archive/?q=fish

It is searching profiles rather than pages but I suppose it would be more or less the same approach in the widget that shows the results…

if it helps here’s the code:

<style>
	.fs_result_header {
		font-weight: normal;
		font-size: 2rem;
	}

	.fs_result_name {
		font-size: 2rem;
	}

	.fs_result_collaborators {
		font-size: 1.7rem;

	.fs_result_title {
		font-style: italic;
		font-weight: normal;
	}
</style>

<xphp content="true">
	<if var="q" type="GET" value=""/>
	<content>
<!-- 		<widget id="354_profiles_faculty_success_archive"></widget> -->
	</content>
	<else content="true">
		<content>
			<widget type="profiles">
				<arg id="type">Faculty Accomplishments</arg>
				<arg id="search"><xphp var="q" type="get"/></arg>
				<arg id="clean_markup">true</arg>
				<arg id="paginate">25</arg>
				<arg id="group">Faculty Accomplishments</arg>
				<arg id="exclude_tag">exclude from search</arg>
				<arg id="filter_mode">any</arg>
				<arg id="filter" name="title" action="matches"><xphp var="q" type="get"/></arg>
				<arg id="filter" name="profiles_156" action="matches"><xphp var="q" type="get"/></arg>
				<arg id="filter" name="profiles_160" action="matches"><xphp var="q" type="get"/></arg>
				<arg id="format">
				<div class="result m-4">
					<div class="h4 mb-0">
						<p>
							<span class='fs_result_header'>{profiles_154} — {profiles_155}</span><br />
							<span class='fs_result_name'>{profiles_156}</span><br />
							<field content="true">
								<if var="profiles_160"/>
								<content>
									<span class='fs_result_collaborators'>{profiles_160}</span><br />
								</content>
							</field>
							<span class='fs_result_title'><a href="{href}" class="header-link">{title_clean}</a></span>
						</p>
					</div>
				</div>
				</arg>
				<arg id="format_widget">
					<h2 class="search-results-header">Search results for “<xphp var="q" type="get"/>” ({total})</h2>
					{widget}
				</arg>
			</widget>
		</content>
	</else>
</xphp>

Jon: Thanks for that. I mocked up a quick edit of Pages search on our dev site. As you identified, it does use the meta description or the first text of the main section of the page (rather than the desired location of first mention). It also does bold the search term, if it appears in the text shown, so that’s great.

Definitely a good compromise option I could bring back for consider, though I suspect we’ll need to evaluate a bunch of these pages to make sure their descriptions or starting text are good…

I also tried quickly with Stories. Styling aside, it seems it doesn’t have the same ability as Pages with the {summary} field. If its just pages, may have to rework the page layout to focus on pages.

Gian: Yes, but specifically pulling the first mention of the search term. Imagine instead of a sentence summary: you have a full abstract, the term searched is mentioned in the last sentence, and that’s the phrase/sentence you want to show in search results.