Friday 10 May 2013

Solr and the stars


Funny fact on Friday that everybody notice it. You meat with strangers and the first thing they say: "it's a Friday". I think it just meant to bring people together.


I had a nice afternoon at a huge park talking about life - a lot. My only problem with parks is the park coffee. It's water and mud. There is not much to do without competition.

This day I did Solr configuration mostly, and - what a surprise - found an interesting behavior again. So this time it's about the keyword filter. I've got immediately scared by the work: keyword. Keyword means a lot of things and never really specific enough to prevent total confusion. I thought my life is over and I have to manually concatenate a keyword index field. However a valid way to do, there is an easier one - using display types. It really sounds dead-obvious, it takes time only on a Friday.

So the better way is to define the 'search_index' content type display and set the fields in a way that it contains everything - especially the rendered node displays about the referenced entities. Quickly reindexed the content and I've got the perfect 'content' value in the index. Remember, that's the Field Drupal is putting the node view output string. A tested with some keywords and somehow it worked 90% of the cases. The 10% was a total empty result, however the filter string is obviously in the index at the right place. A little code check and I've found that the query that views is using is going through the apachesolr_view module, which adds a tiny * (asterisk) to the end of the word. So in Solr it looks like:

For the word Europe it presents: (content:(Europe*))

The syntax is plain Solr format where the asterisk represents anything. (I guess so). So you can check it out also without any abstraction on it. If you go to

127.0.0.1:8983/solr/select?indent=on&version=2.2&q.alt=*:*&fq=&start=0&rows=10&fl=*%2Cscore&wt=&explainOther=&hl.fl=

You'll see the last 10 items. Then you can try it with the keyword a filter:

127.0.0.1:8983/solr/select?indent=on&version=2.2&q.alt=content:(Europe*)&fq=&start=0&rows=10&fl=*%2Cscore&wt=&explainOther=&hl.fl=

Of course replace my keyword to something more meaningful for you. But it might not show any result. I was playing with it for a while and found something interesting. If I wrap the keyword in double quotes it shows the result, but doesn't show the highlight attributes properly. It's messed up. But the best is simply not to use asterisk at all. I mean Lord, it's already Friday, couldn't you just hide it for a day? What funny is that I don't really know why it fails sometimes and sometimes it doesn't.

---

Peter

No comments:

Post a Comment

Note: only a member of this blog may post a comment.