user1391574
user1391574

Reputation: 21

Solr wildcard search, need to only highlight the matched part not the entire word

My text is like this: The searched word WildCard shall be partially highlighted

I search using wildcard expression "wild*".

What I need is to have the highlight snippet to be [tag]Wild[/tag]Card. What I got was [tag]WildCard[/tag], and I spent lots of time researching it, but could not find an answer.

This behavior can be illustrated on linkedin.com, where you type other people's name at the top right corner.

Once this is figured out, I will have a follow-up questions.

Thanks,

Upvotes: 2

Views: 790

Answers (2)

harmstyler
harmstyler

Reputation: 1401

This is not possible with Solr. What you need to do is change the characters Solr uses to highlight found words to something you can easily remove (maybe an html comment) and then build a highlight yourself. You are likely already storing your query in a variable, so just scan the search return docs and highlight all instances of your query.

Upvotes: 0

Persimmonium
Persimmonium

Reputation: 15789

I am not sure if you can achieve what you want directly in solr. The obvious solution is to parse the returned doc yourself searching for [tag]WildCard[/tag] and find out what part of the term you need to highlight.

Upvotes: 1

Related Questions