Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:13:43+00:00 2026-06-16T16:13:43+00:00

I am new to solr and have been asked to implement search result highlighting.

  • 0

I am new to solr and have been asked to implement search result highlighting. My search query is something like this,

query = text like ‘searchterm1’ AND ‘searchterm2’

Now I need to instruct solr to highlight ‘searchterm1’, ‘searchterm2’ in yellow and blue colors respectively. Is this even possible to do with solr? and if yes how do I go about it?

This is the code snippet that is currently highlighting the search result.

    private AbstractSolrQuery _query = new SolrQuery(searchterm1) && new SolrQuery(searchterm2);

    public SolrQueryResults<Document> Execute(string defaultField)
    {
        var results = _solr.Query(_query, new QueryOptions
        {
            Rows = 100,
            Fields = Document.GetPropertiesExceptList(new List<string>{"text","text_exact"}).ToArray(),
            ExtraParams = new Dictionary<string, string> {
                    { "df", defaultField },
                    { "hl.fragsize", "0" },
                    { "hl", "true" }
            }
        });

        Highlight(results);
        return results;
    }

    private void Highlight(SolrQueryResults<Document> results)
    {
        foreach (var result in results)
        {
            foreach (var highlightedSnippet in results.Highlights[result.Id.ToString()])
            {
                result.SetProperty("content", highlightedSnippet.Value.ToList());
            }
        }
    }

Any help with this would be very much appreciated,

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:13:44+00:00Added an answer on June 16, 2026 at 4:13 pm

    You can check upon hl.fragmentsBuilder which will allow you to return the snippets in different color. I am just not sure if it applies to search terms, matches or field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to Apache SOlr and have recently been working with DIH,
I tried to insert this into sole using the update/json handler: [{id:abc,text:you have been
I am new to Solr/Sunspot and i'm sure i've done something wrong. I have
I'm new to Solr. Using Solr 1.4.1 I have a schema.xml that have this
I am new to Solr. I have been following the documentation provided in the
I have this problem, right now when I do a search like: really long
ok, I'm totally new to SOLR and Lucene, but have got Solr running out-of-the-box
I am completely new to java and I am using Solr search server. It
New to PHP and MySQL, have heard amazing things about this website from Leo
I am new for solr. I have installed apache tomcat 7.0 on my server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.