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 6067067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:34:06+00:00 2026-05-23T09:34:06+00:00

{ responseHeader: { status: 0, QTime: 32 }, response: { numFound: 21, start: 0,

  • 0
{
    "responseHeader": {
        "status": 0,
        "QTime": 32
    },
    "response": {
        "numFound": 21,
        "start": 0,
        "docs": [
            {
                "description": "The matte finish waves on this wedding band contrast with the high polish borders. This sharp and elegant design was finely crafted in Japan.",
                "UID_PK": "8252",

            },
            {
                "description": "This elegant ring has an Akoya cultured pearl with a band of bezel-set round diamonds making it perfect for her to wear to work or the night out.",
                "UID_PK": "8142",

            },

        ]
    },
    "highlighting": {
        "8252": {
            "description": [
                " and <em>elegant</em> design was finely crafted in Japan."
            ]
        },
        "8142": {
            "description": [
                "This <em>elegant</em> ring has an Akoya cultured pearl with a band of bezel-set round diamonds making"
            ]
        },

    }
}

This is JSON data I got from solr when i set hl=true and hl.fl=description. Here I got docs tag and highlighting tag. I need to parse highlighting tag to highlight “elegant” in description field which is in <em> tag…one more thing is UID_PK's(8252,8142) in <highlighting> are generated dynamically each time. Please suggest how can I do this if I am getting JSON data as

$.getJSON("http://192.168.1.9:8983/solr/db/select/?wt=json&&start=0&rows=20&q="+newquery+"&sort=price asc&hl=true&hl.fl=description&hl.usePhraseHighlighter=true&json.wrf=?", function(newresult){

and parsing it as

$.each(newresult.response.docs, function(i,item){

and

 $.each(newresult.highlighting, function(i,hitem){
  • 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-05-23T09:34:06+00:00Added an answer on May 23, 2026 at 9:34 am

    Assuming the response is always text and only the to be highlighted elements are enclosed in <em> tags and there is only one of them, you could do this:

    var highlight = {};
    
    $.each(newresult.highlighting, function(i, hitem){
        var match = hitem.description[0].match(/<em>(.*?)<\/em>/);
        highlight[i] = match[1];
    });
    
    $.each(newresult.response.docs, function(i, item){
        var word = highlight[item["UID_PK"]];
        var result = item.description.replace(new RegExp(word, 'g'), '<em>' + word + '</em>');
        // do something with the result
    });
    

    This only works if word does not contain nay special regular expression characters (in which case you’d have to escape them). If you know that the to be highlighted word only occurs once in the search results, you don’t have to use regex:

    item.description.replace(word, '<em>' + word + '</em>');
    

    DEMO

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

Sidebar

Related Questions

I understand there is a HTTP response header directive to disable page caching: Cache-Control:no-cache

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.