0

I am using Examine for a search and have descriptions on the pages that match the search terms. So for example someone searches 'flims about dogs', the search brings back everything for 'films', 'about', and 'dogs'. In my case 'dogs' is probably the most relevant word. However, in the search results, I don't want to show 2 paragraphs of text and highlight the word 'dogs' only. I would like to truncate everything before and a certain amount after the word or phrase that matches from the description fields I have displaying.

We are also using Umbraco and Razor.

 @foreach (var item in searchResults)
  {
    <p>@item.GetPropertyValue("Description")</p> //Probably truncate here 
  }
ClosDesign
  • 3,894
  • 9
  • 39
  • 62
  • I am not completely clear on your question, but it sounds really simple. You have a big string; you want to display a substring of that big string (e.g. starting with "dog' and maybe N characters afterward). Is that right? Examine, Razor, Umbraco, etc. seem to have nothing to do with the question, correct? – John Wu Apr 29 '19 at 20:18
  • @JohnWu, more or less, Sorry for not making it more clear. I was just trying to add a bit more of what I am using the get the results that I have in my output. I would like to take the @item.GetPropertyValue("Description") and truncate prior and after by a certain amount of characters (50 both ways). – ClosDesign Apr 29 '19 at 20:28
  • `@item.GetPropertyValue("Description").Substring(@item.GetPropertyValue("Description").IndexOf("dogs") - 50, 100)` – rene Apr 29 '19 at 20:34
  • Instead bringing the whole node and highlighting a chunk of text you can take the text from the Lucene index with the chunk already highlighted. This might help: https://our.umbraco.com/forum/using-umbraco-and-getting-started/90477-umbraco-examine-search-result-highlighting – Mario Lopez Apr 30 '19 at 03:22

0 Answers0