Drupal Apache Solr Module Search Results Missing Title

After finally getting my Apache Solr EC2 instance connected I was able to index and search for results on my Drupal 7 website except low and behold, when I did a search the search results appeared without titles.

 

The first thing I did was look in the search result template file to see if the title was being called properly.

It was.

So I had to figure out why the title variable might not be populating.

I tuned on visible error logging for this Drupal site and saw a number of errors having to do with arrays.

Error messages give you all sorts of hints. I then dove into the module code to try to decipher what was going on. Why not start right where the error message says around line 1372 of the file, apachesolr_search.module

 

Here is the offending code:

function apachesolr_search_process_response($response, DrupalSolrQueryInterface $query) {

$fields = (array) $doc;
// Define our url options. They depend on the document language.
$url_options = array(‘absolute’ => TRUE);
if (isset($doc->ss_language) && isset($languages[$doc->ss_language])) {
$url_options[‘language’] = $languages[$doc->ss_language];
}
$result = array(
// link is a required field, so handle it centrally.
‘link’ => url($doc->path, $url_options),
// template_preprocess_search_result() runs check_plain() on the title
// again. Decode to correct the display.
‘title’ => htmlspecialchars_decode($doc->label, ENT_QUOTES),
// These values are not required by the search module but are provided
// to give entity callbacks and themers more flexibility.
‘score’ => $doc->score,
‘snippets’ => $snippets,
‘snippet’ => $snippet,
‘fields’ => $fields,
‘entity_type’ => $doc->entity_type,
‘bundle’ => $bundle,
);

You can see here that this code is treating the results as objects.

‘title’ => htmlspecialchars_decode($doc->label, ENT_QUOTES),

However, if you look at the JSON response of Apache Solr 6.x you will see the results are mostly array elements not objects. Note the brackets.

 


"response":{"numFound":11871,"start":0,"docs":[
{
"id":"noim8l/node/3050",
"site":["http://yeahchemistry.com/"],
"hash":["noim8l"],
"entity_id":[3050],
"entity_type":["node"],
"bundle":["forum"],
"bundle_name":["Questions"],
"ss_language":["und"],
"path":["node/3050"],
"url":["http://yeahchemistry.com/questions/electron-orbitalsperiodic-trends-there-book-covers"],
"path_alias":["questions/electron-orbitalsperiodic-trends-there-book-covers"],
"label":["Electron Orbitals/Periodic Trends- is there a book that covers this"],
"content":[" We've started our Atomic Theory unit and have just completed electron configuration/orbital properties/shapes and have moved on to periodic trends (shielding, Zeff, etc.). Needless to say, I am thoroughly confused. Is there any website or book (besides my chem book--Zumdahl 5th Edition) that I can look to for help? I think that chemistry is really interesting, I am just struggling a lot. It's discouraging, but I'm not giving up! "],
"teaser":[" We've started our Atomic Theory unit and have just completed electron configuration/orbital properties/shapes and have moved on to periodic trends (shielding, Zeff, etc.). Needless to say, I am thoroughly confused. Is there any website or book (besides my chem book--Zumdahl 5th Edition) that I"],
"ss_name":["caileywailey"],
"tos_name":["caileywailey"],
"ss_name_formatted":["caileywailey"],
"tos_name_formatted":["caileywailey"],
"is_uid":[1784],
"bs_status":[1],

So it stands to reason that if the JSON element “label” is returning an array not an object then I should do the same in the Drupal module code.

$fields = (array) $doc;
// Define our url options. They depend on the document language.
$url_options = array(‘absolute’ => TRUE);
if (isset($doc->ss_language) && isset($languages[$doc->ss_language])) {
$url_options[‘language’] = $languages[$doc->ss_language];
}
$result = array(
// link is a required field, so handle it centrally.
‘link’ => url($doc->path[0], $url_options),
// template_preprocess_search_result() runs check_plain() on the title
// again. Decode to correct the display.
‘title’ => htmlspecialchars_decode($doc->label[0], ENT_QUOTES),
// These values are not required by the search module but are provided
// to give entity callbacks and themers more flexibility.
‘score’ => $doc->score,
‘snippets’ => $snippets,
‘snippet’ => $snippet,
‘fields’ => $fields,
‘entity_type’ => $doc->entity_type,
‘bundle’ => $bundle,
);

 

And now we are correctly populating the title variable and we get our search result title links.

 

To clean up all the errors you need to do this is many places. Let the errors lead you there, but you get the gist of it.

..

375 days of sobriety: An Opportunity to Build Strength.

“You should use every opportunity to build strength,” Marsha says to me. It was probably more of a reprimand now that I think of it. She caught me being lazy in a pose. She has this way of discipling you in the sweetest way as her feet patter off to help another student.

It resonated, and I continue to repeat it in my head. This casual comment has become a fundamental precept for me.

Stoic maxims have made all the difference in my life. “Some things are in our control and others not.” – Epictetus

I now have a new one. “Use every opportunity to build strength” – Marsha Mcknight

Many things are out of my control; taking every opportunity to build strength is in my control.

During my practice I am repeatedly faced with a decision. Do I attempt to jump back or jump through? Or skip this vinyasa? I think I can’t do it. But I can. I can lift up then crawl through. That’s better than skipping. I can’t lift up anymore, but I can press into the ground and transition.
Why am I not trying to straighten my leg and lift it as high as I can? Or activating my quads and pressing into my hands? Choose to build strength, Butler. It does not have to be perfect; the strength is built in the trying.

Each repetition of this decision makes me stronger.
The second to last asana is Utplutih. You lift yourself and hold for 100 breaths. By this point I am exhausted, but it is one of my greatest opportunities to build strength. If you can’t lift for 100 breaths, lift for 10. If you can’t lift completely, use your feet to help levitate. If you can’t lift at all, press the ground with your hands and raise your knees.

Build the strength you need.

Recently, a relationship ended with an amazing person. An ending like this always leaves one with questions, questions probably best left unanswered even if they could be. Previously I would have beat myself up wondering what I did wrong or how I could be different. I now see it as an opportunity to build strength in myself. I am strengthening my resolve that I am happy with who I am and who I am becoming. I am strong on my own.

Year 1. I have been sober for one year.

“Get busy with life’s purpose, toss aside empty hopes, get active in your own rescue – if you care for yourself at all – and do it while you can.” Meditation 3.14

Last week I found writings from Jan 1st 2017. I forgot I wrote them. I described myself as riddled with anxiety and depression, wishing I was more articulate, and drinking too much, yet encouraged I had found new interests in philosophy and art.

“I want to figure out the type of man I want to be and think through how that man might conduct himself.”

“Oh yeah and I’ve committed to 60 days of no drinking.”

Even though drinking was destroying my mind, body and relationships, I was afraid to stop completely. My entire identity was wrapped up in it. Rarely did you see me without a glass of whiskey. I didn’t know who I’d be if I stopped. I didn’t think anyone would like me.

I decided on that day to to grow a beard and write publicly for the duration of my “experiment” with not drinking.

Whether you believe it to be circumstance or providence, the universe, through the love of friends, teachers, coworkers, and strangers, gave me the foothold I needed to continue my sober journey. I listened to my own body and soul. I held on.

A year later, at nearly 42, I’m the healthiest I have ever been. I understand myself better, and I am learning how to be in healthy relationships.

A year ago, my character was not equal to the love and opportunity that was being given to me. I have a long way to go, but I now feel better about what I am giving back.

Previously I was a man of no faith. I now have a practical faith. It is rooted in this sutra.

Sutra 2.1: tapah svadhyaya ishvara-pranidhana kriya-yogah

1) Practice and accept pain as part of the soul’s purification.

2) Study both yourself and the ancient scriptures

3) Surrender to God

Practice. Study. Surrender.

I set out this year to find and heal myself. I am happy, and at peace with who I am becoming and how I am living.

I’m getting closer.

My wish for you is if there is anything you need to change that you find the courage and strength to change it.

Get active in your own rescue. Let me know if I can help.

I love y’all. Happy New Year!

Thank you for allowing me the space to share my journey with you. If you think this will help anyone please feel free to share.

I’ve been sober for 360 days

“I’m out at Papas on Holmes Cannery Rd. Roll through.”

“Which house? I was so drunk last time I don’t remember. I think I know but not completely sure.”

Dave called and gave me the address. I wasn’t even on the right road.

Dave drove us home for Christmas two years ago. I started drinking before we left Atlanta. I just didn’t want to deal with life. It wasn’t always that way, but it definitely became that way.

If you don’t know me well, Dave is my childhood best friend. We met around age 13 in a small Southern baptist church in Harrison, GA. He knows everything there is to know about me. We have had the good fortune to be in each other’s lives for 28 years. I can trust him to call me on my bullshit.

When we got to our first stop, his Papa’s, I was embarrassingly drunk. By the time I got home I could only open presents and pass out.

It’s incredible how much can change in two years, and how much can stay the same. This was my first sober Christmas. The joy I experienced watching my niece and nephew open gifts is indescribable. I love them so much. I want my parents to know a sober me. However, all the thoughts and feelings I numbed for so many years were still there, and even sober I wasn’t strong enough to fix everything.

As was driving back on I20 towards Atlanta, I began to sob. I thought maybe this year it wouldn’t happen. As I played Kenny and Dolly’s “Once Upon a Christmas,” the first tear fell. This song and album had been the soundtrack to so many childhood Christmases. I became overwhelmed with memories of a simpler time, and then I relived all the years since in my mind.

Feeling guilty for disturbing their Christmas, I selfishly reached out to friends, describing my thoughts and grasping for a frame of reference.

Drinking felt inevitable. I pulled over and dried my eyes the best I could so I could drop off gifts for my friends’ children.

Humbled, I posted to a support group. Even though I helped start this group with other sober yogis, I was still ashamed to write what I was thinking.

I sat in a parking lot awhile before heading to Christmas dinner. Love sustained me through the night. I don’t remember much more.

Today I am sober.

Drupal 8 REST API: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I was writing some JavaScript that needs to talk to a Drupal 8 site’s REST API.Te Drupal 8 instance runs on a separate domain . Due to the same origin policy the requests was blocked the browser

Due to the Origin policy, you cannot make a XMLHttpRequest from your domain to another domain. E.g. you cannot use http://twitter.com/… URLs unless your script was loaded from twitter.com. If your script is loaded from http://localhost/, the AJAX request also need to go to localhost.

Looking in Chrome’s console I can see that the GET is failing because the  an ‘Access-Control-Allow-Origin’ header is missing on the Drupal server. If you are not in charge of the Drupal site / server being requested you will have to contact the admin of that environment.

I’m always telling folks to read the error and logs closely.

This is not something you can get around with JavaScript easily and has to be addressed on the Drupal side.

Find:
.../sites/default/default.services.yml

Make a copy and rename the copy to:

.../sites/default/services.yml

Find this part of the code:


# Configure Cross-Site HTTP requests (CORS).
# Read https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
# for more information about the topic in general.
# Note: By default the configuration is disabled.
cors.config:
enabled: false
# Specify allowed headers, like 'x-allowed-header'.
allowedHeaders: []
# Specify allowed request methods, specify ['*'] to allow all possible ones.
allowedMethods: []
# Configure requests allowed from specific origins.
allowedOrigins: ['*']
# Sets the Access-Control-Expose-Headers header.
exposedHeaders: false
# Sets the Access-Control-Max-Age header.
maxAge: false
# Sets the Access-Control-Allow-Credentials header.
supportsCredentials: false

And change

enabled: true

The two important parts of the code are bolded below.

Find this part of the file:
# Configure Cross-Site HTTP requests (CORS).
# Read https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
# for more information about the topic in general.
# Note: By default the configuration is disabled.
cors.config:
enabled: true
# Specify allowed headers, like 'x-allowed-header'.
allowedHeaders: []
# Specify allowed request methods, specify ['*'] to allow all possible ones.
allowedMethods: []
# Configure requests allowed from specific origins.
allowedOrigins: ['*']
# Sets the Access-Control-Expose-Headers header.
exposedHeaders: false
# Sets the Access-Control-Max-Age header.
maxAge: false
# Sets the Access-Control-Allow-Credentials header.
supportsCredentials: false

Setting enabled to true allows turns on the configuration.

# Configure requests allowed from specific origins.
allowedOrigins: ['*']

allows access from all origins. You may want to limit this once you are further along in the development of your script.

Day 350 of Sobriety: I’ll Be Home for Christmas

Day 350 snuck up on me. It is crazy how quickly ten days (or your life) can pass. I have been sober almost a year now. So young in my sobriety I am still experiencing many things for the first time.

The holidays have always had strange effect on me. I love the season. I (too) often break out (poorly) singing Christmas songs in the office (sorry) from I’m Dreaming of a White Christmas to Wham’s Last Christmas. However, as the Christmas spirit grows around me I begin feeling more and more like I don’t belong anywhere and feel very alone in the world.

If you thought I drank a lot, I drank twice that during Christmas. Within minutes of arriving home, I would pour a glass of whiskey. I would sit, drink and go through the motions while ignoring both the past and the present. On Christmas Day, I would drive back, pick up a bottle and drink on the couch leading to crying for reasons I will never understand until I passed out.

I grew up with what would appear a storybook Southern Christmas. Most of my entire family lived in or near the small town of five hundred I grew up in. All the aunts, uncles and cousins would gather at my Granny Bootsie’s house. But holidays were always hard for me. I dreaded them. It seemed everyone had something to talk about but me. I felt like I had very little in common with the people around me. I was shy, nerdy and awkward. I didn’t want to play two hand touch in the backyard, and if I did or didn’t, I was made fun of. I didn’t hunt nor do I care to. I found myself just wishing I was at home playing with the Star Wars toys that Santa left under the tree. (Hint: Star Wars stuff is still favorite gift.) I just didn’t fit in.

Last Christmas was particularly impactful. As a drove home on Christmas Day I heard George Michael died. 54 was too young. Drunk, I texted mama and asked how old my grandfather was when he died. “57, heart attack complications due to alcoholism” Six days later I stopped drinking.

For the first time in two decades I will be sober on Christmas Day. For 20 years, every year, I would show up but not be there. This year I will be there Mama. I love y’all.

Day 340: Thanks Taylor Hunt

I have been sober 340 days.

This passage from The Bhagavad Gita makes me think of Taylor Hunt.

“What the outstanding person does, others will try to do. The standards such people create will be followed by the whole world.” 3.21

December 31st, 2016 was my last drink of whiskey. I wish I could say I committed to being sober the next day but I didn’t. I knew I was destroying my body and my relationships. I knew I needed to stop drinking for good, but I gave myself an out. I was going to “experiment” with not drinking for 120 days.

In March 2017, I traveled to St. John for vacation. This was my first sober vacation. The friends I was with were overwhelming supportive. I brought a book I bought at my shala, “A Way from Darkness” by Taylor Hunt. It is a book about his journey in life. Every morning I read his story over breakfast highlighting all the sentences that resonated with my experience.

On vacation, I joined the Trini Foundation Instagram yoga challenge. Now, I am the last person who should be doing this. On my best day I am an awkward unathletic Southern boy doing yoga and most days more like a sweaty walrus. But maybe if I could get on his radar it would push me to commit to being sober.

Holy shit, I am one of the winners. How in the fuck did that happen? I won a workshop with Taylor. There was no way I could go to this workshop and tell this man I had started drinking again.

Eight months later I met Taylor for the first time in Atlanta. I was still sober and sharing openly about my struggles and sobriety. It was my first Ashtanga workshop. I had lived in fear I was not “good enough” to do one. I did it.

Last week I went out of country for the first time. I traveled to Costa Rica to practice with Taylor and many other amazing humans. Taylor shared that he knew of me before the yoga challenge; that my teachers cared a lot about me and had reached out to him for advice on how to help me back when I was drinking. He selected me as a winner in the the yoga challenge so I would have to meet him at a workshop.

Why one man chose to help someone he didn’t know, I don’t know, but I do know I want to be more like that. Time to do the yoga!

Thank you, Taylor.

“You should meditate often on the connection of all things in the universe and their relationships to each other. In a way all things are interwoven and therefore have a family feeling for each other: one thing follows another in due order through the tension of movement, the common spirit inspiring them, and the unity of all being.” Meditations 6.38

Day 320: Sober and Grateful to Boot

I’ve been completely sober for 320 days.

5:10 am.

Alarm. Snooze. Alarm. Definitely did not want to get out of bed.

Yoga. Definitely need to get to practice. Go to morning practice Butler. You won’t have time this afternoon.

Coffee. Something about making an actual pot of coffee is satisfying. Should I read the Sutras or Marcus Aurelius this morning.

Phone. Let me see if I need to respond to anything before I go to practice. One of my favorite parts of my yoga practice is it is an hour and a half away from devices and screens

A boot! I run outside. There is a fucking boot on my Jeep. A boot on my Jeep. A boot on my Jeep in the same reserved parking space I’ve parked in since I moved in a year and a half ago.

I call. Of course it is a 3rd party messenging service at 5:45 am. Of course the “technician” doesn’t have the authority to pull the charge. Of course a manager can call me back “within 24 hours.” Of course I need to “wait by my vehicle” because the “technician” isn’t required to call me.

I was pissed and began immediately thinking of all the ways this event had already ruined my day. But as I stood in the cold in my pajamas and sweatshirt, I started to smile. All I could think about is how grateful I am for my life. I am blessed beyond measure. I love my life. I love my job. I love my friends. I love my communities. I love myself. I am loved. This was a slight inconvenience at the most.

When the “technician” arrived I wasn’t angry. I smiled and asked him to take a picture. He looked surprised. I told him today I had been sober for 320 days, and I grateful for my life. I knew this wasn’t his fault. We spent the he next 15 minutes sharing stories and talking about some struggles in his family.

Compared to all the blessings in my life and all the suffering in the world, the inconvenience of of paying a fine for a boot on my expensive Jeep in my reserved parking space outside my expensive apartment that caused me not to go to my fancy yoga class is insignificant.

Maybe the universe was simply charging me for perspective today.

I love y’all.

 

I’ve been sober 300 days.

As I was reading early this morning, I received a text from Flo.

“On your way?” She was holding me accountable to showing up to practice today.

Flo and I call each other sober buddies, but in truth she is my inspiration and role model.
Today I have been sober for 300 days. Today Flo has been sober for 20 months (608 days.) I have been fortunate to witness Flo’s transformation both physically and spiritually over the last 20 months. She showed me sobriety was achievable with consistent practice, focus and self-love. It is a blessing to have someone to model my behavior after, and a gift for her to care enough about me to hold me accountable.

Sutra 1.20 reads,

shraddha virya smriti samadhi prajna purvakah itaresham

Others [those not born a yogi] follow a five-fold systematic path of 1) faithful certainty in the path, 2) directing energy towards the practices, 3) repeated memory of the path and the process of stilling the mind, 4) training in deep concentration, and 5) the pursuit of real knowledge, by which the higher samadhi (asamprajnata samadhi) is attained.

The entire passage is powerful, but one word stood out, shraddha

Shraddha: Developing the faith that you are going in the right direction or the conscious faith in goal.

For once in my life I have faith I am on the right path. I see Flo, and know what is possible. Thank you.

“Let the god that is within you be the champion of the being you are” Marcus Aurelius, Meditations 3.5

Flo, I can definitely see the goddess in you. By focusing on finding your true self you make us all better.

Flo inspired me to be open and transparent about my sobriety. We both choose not to be anonymous about our recovery. My hope is that by sharing my journey I might help someone the way Flo has helped me.

Flo and I both credit the Ashtanga method of yoga with helping us get sober and maintain our sobriety. We support Taylor Hunt and the Trini Foundation and their efforts bring the life-changing practice of Ashtanga yoga to those struggling with drug and alcohol addiction. Please consider sharing this post and donating.

Namaste.