Skip to content

Commit ee0e21f

Browse files
committed
Updated the matching text FTS ui and also updated the code.
1 parent 8fb0487 commit ee0e21f

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

devtracker.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,6 @@ def getCacheData(fileName)
894894
activityStatuses = 'AND activity_status_code:(2)'
895895
filters = prepareFilters(query.to_s, 'F')
896896
response = solrResponse(query, activityStatuses, 'F', 0, '', '')
897-
puts response
898897
if(response['response']['numFound'].to_i > 0)
899898
response['response'] = addTotalBudgetWithCurrency(response['response'])
900899
response = addHighlightingToFTSTerms(response)

helpers/solr_helper.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,20 @@ def addHighlightingToFTSTerms(response)
368368
hrt = solrConfig['HumanReadableTerms']
369369
highlightedTexts = response['highlighting']
370370
response['response']['docs'].each do |r|
371-
puts r['id']
372371
if highlightedTexts.has_key?(r['id'].to_s)
373372
if !highlightedTexts[r['id']].empty?
374373
firstElement = highlightedTexts[r['id'].to_s].first
374+
matchedText = firstElement[1].first.to_s
375+
startingTextIndex = matchedText.index('<em>')
376+
if startingTextIndex > 15
377+
matchedText = matchedText[(startingTextIndex-15),matchedText.length]
378+
end
379+
endingTextIndex = matchedText.index('</em>') #length is 7. found at spot 2+5.
380+
if matchedText.length > endingTextIndex + 5 + 12
381+
matchedText = matchedText[0..(endingTextIndex + 5 + 12)]
382+
end
375383
key = firstElement[0]
376-
val = firstElement[1]
384+
val = '... ' + matchedText + ' ....'
377385
r['highlightedKey'] = hrt[key]
378386
r['highlightedValue'] = val
379387
end

views/search/solrTemplate.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
<%if item.has_key?('highlightedKey')%>
230230
<span class="text-highlighting" style="color: grey">
231231
<%begin%>
232-
<p>Found a match in field: <%=item['highlightedKey']%></p>
232+
<p>Found a match in field: <%=item['highlightedKey']%> <span><%=item['highlightedValue']%></span></p>
233233
<%rescue%>
234234
<%end%>
235235
</span>

0 commit comments

Comments
 (0)