Saját search api mező hozzáadása + 1 kis drupal diagnosztika

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.
Kategória: 
Gyorstippek

No ez megint amolyan nagy tömegeket érintő szösszenet lesz, de miután fél óra debugolás után jöttem rá, hogy miújság, gondoltam megspórolom magamnak (meg hátha azért másnak is..) egy következő fél órát.

A helyzet a kövi: Search Api által hajtott okos keresőt kell csinálni, amelynek az egyik sorrendezési módja: A legtöbbet kapott szavazat. A szavazáshoz a drupal.hu is látott Vote Up/Down modult használom, ami a votingapira épít.
Feladat: Etessük meg az entitásokra adott szavazatértékeket a search apival.

Igazából baromi egyszerű a dolog: Az Entity API a drupal gyári entitás paramétereit ki tudja egészíteni bizonyos adatokkal, jellemzőkkel (magyarul property), amit aztán különböző modulok okosan felhasználhatnak, mint például a rules, vagy a search api.

Tehát az első része, hogy adjunk hozzá egy ilyen jellemzőt:

[geshifilter-drupal6]/** * Implements hook_entity_property_info_alter(). */ function MODULOM_hook_entity_property_info_alter(&$info) { $info['node']['properties']['voting_results'] = array( 'type' => 'integer', 'label' => t('Votes for a node'), 'sanitized' => TRUE, 'getter callback' => 'MODULOM_get_search_api_votes', ); }[/geshifilter-drupal6]

A sokatmondó 'getter callback' jelenti azt a függvényt, amellyel az adott értéket elő kell túrni valahonnan. Esetünkben ez egy szimpla lekérdezés a votingapi_cache táblából:

[geshifilter-drupal6]function MODULOM_get_search_api_votes($item) { $results = db_query('SELECT value FROM {votingapi_cache} WHERE entity_id = :nid AND function = :function', array( ':nid' => $item->nid, ':function' => 'sum' )); $result = $results->fetchField(); return $result; }[/geshifilter-drupal6]

Ezután egy gyorstárürítés, és már látszik is a search api indexbeállító felületén az új mezőnk, csak bepipáljuk, majd újraépítjük az indexet.

Mondhatnánk, hogy készen vagyunk, de itt jön a bibi, ami miatt az a plusz fél óra becsúszott: Az entity apinak ugyan megmondjuk, hogy helló, itt egy property, itt egy getter callback, viszont az már teljes mértékben az entity apit használó modulra van bízva, hogy hogyan, mikor használja fel ezt az adatot.

Miután nálam baromira nem akart összejönni a szavazatok szerinti sorrendezés, elkezdtem nézegetni, hogy ugyan mikor hajlandó az én kici MODULOM_get_search_api_votes függvényem lefutni. Nos, akárhogyan, akármilyen oldalról rugdostam, csak nem akart megállni az xdebug.

Nosza, elkezdtem visszakövetni, hogy egyáltalán hogyan épül fel a search api lekérdezése. Ehhez a search api dokumentációjában kiszúrtam egy hookot, ami feltételezéseim szerint mindenképpen le kell fusson: ez pedig a hook_search_api_query_alter().

El is csíptem, szépen megállt az xdebug. Itt már látszott, hogy a SearchApiQuery->preExecute metódusa hívta meg az alterünket, ott is van benne: drupal_alter('search_api_query', $this); (nem mintha nem lett volna egyszerűbb rákeresni a 'search_api_query' stringre a modul fáljaiban, na mindegy..)

Ebből adódik, hogy kell lennie egy SearchApiQuery->Executenek is, ott is van benne:

[geshifilter-drupal6]// Execute query. $response = $this->index->server()->search($this);[/geshifilter-drupal6]

Itt gyakorlatilag szépen ellépegettem egészen a search metódusig, ahol maga a kereső query felépül. Soronként lépegetve a kóddzsumbujban kezdtek összeállni a változók, mígnem megláttam egy $valamilyen_valtozo['base_table']['search_api_db_default_node_index_voting_results'].
Hopppá! Hát itten kérem minden indexelt mezőnek saját táblája van!
Gyorsan belenéztem a táblába, és láttam, hogy ott vannak rossz értékek. Az már sanszos volt, hogy ezek a táblák index épüléskor frissülnek, úgyhogy újraindexeltem a keresést, és el is akadt az xdebug a MODULOM_get_search_api_votes() függvénynél egyből. Miután az egykarakteres typot már korábban kijavítottam, szépen feltöltődött az index - immár a jó értékekkel, és máris működött a szavazatok szerinti sorrendezés.

Tulajdonképpen baromi jók ezek az xdebugos diagnosztikák. Picit legalább sikerült megérteni a search api logikáját, legközelebb már gyorsabban eltalálom, hogy hová kell nyúlni, ha valami nem ok.

Hozzászólások

This is true for investment

This is true for investment advice as nicely.

\n \n fotballdrakter \n

\n \n fotballdrakter \n \n \n \n \n billige fotballdrakter \n \n \n \n \n Günstige fußballtrikots \n \n \n

Schwab Intelligent Portfolios

Schwab Intelligent Portfolios invests in Schwab ETFs.

These are actually wonderful

These are actually wonderful ideas in concerning blogging.
You have touched some pleasant things here. Any way keep up wrinting.

I'll right away snatch your

I'll right away snatch your rss as I can not in finding your email subscription link or e-newsletter service.
Do you have any? Please permit me recognise in order that I could subscribe.
Thanks.

Saved as a favorite, I really

Saved as a favorite, I really like your blog!

I'm impressed, I have to

I'm impressed, I have to admit. Seldom do I encounter a blog that's both educative and interesting, and without a doubt, you've hit the
nail on the head. The issue is something that not enough folks
are speaking intelligently about. I'm very happy I found this in my search
for something relating to this.

Thanks to your curiosity in

Thanks to your curiosity in Investment Recommendation.

Hi Dear, are you genuinely

Hi Dear, are you genuinely visiting this web site daily, if so then you will absolutely take fastidious experience.

Hi Dear, are you truly

Hi Dear, are you truly visiting this website regularly,
if so after that you will without doubt get fastidious experience.

I'm impressed, I must say.

I'm impressed, I must say. Rarely do I come across a blog that's both equally educative and engaging,
and without a doubt, you've hit the nail on the head. The issue is something too few men and women are speaking
intelligently about. I'm very happy that I found this in my search
for something relating to this.

Greetings! Very helpful

Greetings! Very helpful advice in this particular post!
It is the little changes that produce the biggest changes.
Thanks a lot for sharing!

And that is an investment

And that is an investment danger value taking.

At this time I am going to do

At this time I am going to do my breakfast, later than having my breakfast coming over again to read other news.

Hi there everybody, here

Hi there everybody, here every one is sharing these kinds of
experience, thus it's nice to read this web
site, and I used to pay a visit this blog all the time.

Wow that was unusual. I just

Wow that was unusual. I just wrote an extremely long comment but after
I clicked submit my comment didn't show up.
Grrrr... well I'm not writing all that over again. Regardless, just wanted to say wonderful blog!

Its like you read my mind!

Its like you read my mind! You seem to know so much about
this, like you wrote the book in it or something. I think that you
could do with some pics to drive the message home a little bit, but instead of that, this is great blog.
An excellent read. I'll definitely be back.

Definitely believe that which

Definitely believe that which you stated. Your favorite reason appeared to be on the web the
simplest thing to be aware of. I say to you, I certainly get irked while people consider
worries that they plainly don't know about. You managed to hit the
nail upon the top and also defined out the whole thing
without having side effect , people can take a signal.
Will probably be back to get more. Thanks

Hi there, this weekend is

Hi there, this weekend is fastidious designed for me, as this point in time i am reading this
fantastic educational article here at my home.

Every weekend i used to pay a

Every weekend i used to pay a visit this web site, for the reason that i want enjoyment,
since this this web site conations really nice funny material too.

Keep up the excellent work

Keep up the excellent work and producing in the crowd! sites:ggglese.com
maglie calcio http://marafon.edinarcoin.com/slider/philip-wendiocb/

Contemplate investments that

Contemplate investments that provide rapid annuities.

This paragraph presents clear

This paragraph presents clear idea in favor of the new people of blogging, that really how to do blogging.

Thank you for the auspicious

Thank you for the auspicious writeup. It in fact was a
amusement account it. Look advanced to more added agreeable from
you! By the way, how could we communicate?

This is a topic that's close

This is a topic that's close to my heart... Thank you! Exactly
where are your contact details though?

This is the right website for

This is the right website for anybody who really wants to find
out about this topic. You realize so much its almost hard to argue with you (not that I really will need to…HaHa).
You certainly put a new spin on a topic that has been discussed for many years.
Great stuff, just wonderful!

Contemplate investments that

Contemplate investments that offer speedy annuities.

Incredible points. Solid

Incredible points. Solid arguments. Keep up the good effort.

Fantastic beat ! I wish to

Fantastic beat ! I wish to apprentice while you amend your web site, how can i subscribe
for a weblog site? The account helped me a acceptable deal.

I have been tiny bit acquainted of this your broadcast offered bright transparent concept

What's up it's me, I am also

What's up it's me, I am also visiting this web page regularly, this web page is truly pleasant and the
visitors are in fact sharing pleasant thoughts.

All types of investments come

All types of investments come with sure dangers.

Do you mind if I quote a few

Do you mind if I quote a few of your articles as long as I provide credit and
sources back to your weblog? My website is in the very same area of interest as yours and my users would genuinely benefit from some of the
information you present here. Please let me know if
this okay with you. Thanks a lot!

Financial advisors enterprise

Financial advisors enterprise is people enterprise.

Hi there, I enjoy reading

Hi there, I enjoy reading through your article.
I wanted to write a little comment to support you.

Consider investments that

Consider investments that supply fast annuities.

You actually make it seem so

You actually make it seem so easy with your presentation but I find
this matter to be really something that I think I would never understand.
It seems too complex and very broad for me. I am looking forward for your next post,
I'll try to get the hang of it!

You really make it seem so

You really make it seem so easy with your presentation but I find this matter to be really something that I think I would never
understand. It seems too complex and very broad for me.
I'm looking forward for your next post, I'll try to get the hang of it!

hey there and thank you for

hey there and thank you for your info – I've
certainly picked up something new from right here. I did however
expertise a few technical issues using this web site, since I experienced to reload the site lots of times previous to I could get it to load properly.
I had been wondering if your web host is OK? Not that I am complaining,
but sluggish loading instances times will often affect your placement in google and could damage your high-quality score if ads and marketing with Adwords.
Anyway I am adding this RSS to my email and could look
out for much more of your respective fascinating content.
Make sure you update this again soon.

Your style is unique in

Your style is unique in comparison to other people I've read stuff from.

I appreciate you for posting when you have the opportunity, Guess I'll just book mark this page.

There's definately a lot to

There's definately a lot to find out about this topic.
I really like all of the points you have made.

When I initially commented I

When I initially commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I
get several emails with the same comment. Is there any way you can remove me from that service?
Bless you!

Nice post. I was checking

Nice post. I was checking constantly this blog and I'm
impressed! Very useful information specifically the closing phase :) I maintain such information much.
I was seeking this particular info for a very long
time. Thanks and best of luck.

What's up mates, how is

What's up mates, how is everything, and what you
desire to say on the topic of this paragraph, in my view its
really awesome in support of me.

Hi there I am so happy I

Hi there I am so happy I found your weblog, I really found you by
accident, while I was searching on Bing for something else, Nonetheless I am
here now and would just like to say many thanks for a incredible post and a
all round entertaining blog (I also love the theme/design), I
don’t have time to read it all at the moment but
I have book-marked it and also added your RSS feeds, so when I have time
I will be back to read a lot more, Please do keep up the awesome b.

Thanks for your interest in

Thanks for your interest in Investment Advice.

It's really a nice and

It's really a nice and helpful piece of info.
I'm glad that you shared this useful info with us.
Please stay us up to date like this. Thanks for sharing.

If you are going for finest

If you are going for finest contents like me, only pay
a visit this web page every day because it provides feature contents, thanks

Now it's time to choose your

Now it's time to choose your particular investments.

Wonderful blog! I found it

Wonderful blog! I found it while surfing around on Yahoo News.

Do you have any tips on how to get listed in Yahoo News?
I've been trying for a while but I never seem to get there!
Thanks

Everyone loves it when folks

Everyone loves it when folks come together and share thoughts.

Great blog, stick with it!

Hozzászólás

A mező tartalma nem nyilvános.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.
  • Engedélyezett HTML elemek: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <del> <img>
  • A webcímek és email címek automatikusan linkekké alakulnak.
  • A sorokat és bekezdéseket a rendszer automatikusan felismeri.
  • Engedélyezett HTML elemek: <a> <blockquote> <br> <cite> <code> <dd> <del> <div> <dl> <dt> <em> <li> <ol> <p> <span> <strong> <ul>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <sql>. The supported tag styles are: <foo>, [foo].
  • Minden email cím át lesz alakítva ember által olvasható módon, vagy (ha a JavaScript engedélyezett) ki lesz cserélve kattintható, de biztonságos hivatkozásra.