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

  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • 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

billiga fotbollströjor

This is really interesting,

This is really interesting, You are a very skilled blogger.
I have joined your feed and look forward to seeking more of your magnificent post.
Also, I have shared your website in my social networks!

l2dragonwind. mireene.

You're so cool! I don't

You're so cool! I don't suppose I have read something like that before.
So good to find someone with original thoughts on this subject.
Seriously.. thanks for starting this up. This site is something that is needed on the internet,
someone with some originality!

c-way. sdbreast. articles.

Link exchange is nothing else

Link exchange is nothing else however it is just placing the other person's weblog link on your page at appropriate place and other person will
also do same in support of you.

nemoadministrativerecord.

Wow! In the end I got a

Wow! In the end I got a webpage from where I be capable of in fact obtain useful facts concerning
my study and knowledge.

Contemplate investments that

Contemplate investments that supply quick annuities.

And that is an funding danger

And that is an funding danger value taking.

Thanks regarding providing

Thanks regarding providing many of these substantial written content.

I every time emailed this

I every time emailed this blog post page to all my friends,
for the reason that if like to read it then my
links will too.

qf0z3nti maglie calcio a poco

qf0z3nti maglie calcio a poco prezzo wgt0p6hsk9 yf5v1i0 fodboldtrøjer børn jrd3ek10z m6wx9qk8i fotbollströjor barn jsw3v4f0e5 pau2yf5cxo fotballdrakter mwkfu5pcqh

We absolutely love your blog

We absolutely love your blog and find the majority of
your post's to be exactly what I'm looking for. can you offer guest writers to write content available for you?
I wouldn't mind composing a post or elaborating on some of the subjects you write in relation to
here. Again, awesome blog!

Maintain the good job and

Maintain the good job and bringing in the crowd!

Hey would you mind stating

Hey would you mind stating which blog platform you're using?
I'm going to start my own blog in the near future but I'm having a
tough time deciding between BlogEngine/Wordpress/B2evolution and
Drupal. The reason I ask is because your design seems different then most blogs and I'm looking for
something completely unique. P.S Apologies for getting off-topic but I
had to ask!

You've got fantastic thing at

You've got fantastic thing at this point.

Take into account investments

Take into account investments that offer speedy annuities.

Thanks for your marvelous

Thanks for your marvelous posting! I certainly enjoyed reading it, you're a great
author. I will be sure to bookmark your blog and
will come back very soon. I want to encourage you
to continue your great posts, have a nice evening!

Great website! It looks

Great website! It looks extremely professional! Maintain the great work!

Howdy! Quick question that's

Howdy! Quick question that's entirely off topic.
Do you know how to make your site mobile friendly? My weblog looks weird when viewing from my apple iphone.
I'm trying to find a theme or plugin that might be able to fix this problem.
If you have any recommendations, please share.
Thanks!

Sustain the amazing job !!

Sustain the amazing job !! Lovin' it!

Great blog here! Also your

Great blog here! Also your site loads up very fast! What host are you using?
Can I get your affiliate link to your host? I wish
my web site loaded up as fast as yours lol

Good day, cool online site

Good day, cool online site you've gotten going here.

Pretty nice post. I simply

Pretty nice post. I simply stumbled upon your blog and wished to say that I
have truly enjoyed surfing around your weblog posts.
In any case I'll be subscribing in your rss feed and I hope you write again very soon!

brainteaser. telechat.

I do not even know how I

I do not even know how I ended up here, but I thought this post was
good. I do not know who you are but definitely you're going to
a famous blogger if you are not already ;) Cheers!

unisotong.

Undeniably believe that which

Undeniably believe that which you stated.

Your favorite justification seemed to be on the net the simplest thing
to be aware of. I say to you, I definitely get annoyed while people
think about worries that they plainly do not know about.
You managed to hit the nail upon the top and defined out the whole thing
without having side effect , people could take a signal. Will likely be back to get more.
Thanks

chilekawaii. guru.

ailaosta. orhideeaspa.

I think that everything said

I think that everything said made a bunch of sense. However, what about this?
what if you were to create a awesome headline? I mean,
I don't want to tell you how to run your blog, however suppose you
added a post title that grabbed a person's attention? I mean Válasz
a hozzászólásra is a little vanilla. You might peek at Yahoo's home page
and note how they create post titles to grab
viewers to click. You might add a related video or a pic or two to get people interested about everything've got to say.
Just my opinion, it would bring your posts a little livelier.

stayhere. myy.at.

First off I want to say

First off I want to say excellent blog! I had a quick question in which I'd like to
ask if you don't mind. I was curious to find out how you center yourself and clear your thoughts before writing.
I've had difficulty clearing my mind in getting my ideas out.

I truly do enjoy writing however it just seems like the first 10 to 15 minutes are
usually lost just trying to figure out how to begin. Any suggestions
or hints? Kudos!

clevio. vatal.

I could not refrain from

I could not refrain from commenting. Well written!

orientbeach. cresign.

You're a very helpful

You're a very helpful website; could not make it without ya!

When some one searches for

When some one searches for his essential thing,
therefore he/she wishes to be available that in detail, so that thing
is maintained over here.

Simply wanted to express I'm

Simply wanted to express I'm grateful I stumbled on your webpage.|

Traders do pay direct and

Traders do pay direct and oblique costs.

I am in fact pleased to read

I am in fact pleased to read this webpage posts which
includes plenty of helpful facts, thanks for providing these statistics.

Greetings, cool site you've

Greetings, cool site you've right now.

Fantastic goods from you,

Fantastic goods from you, man. I've take note your stuff previous to and you are just extremely magnificent.
I really like what you've obtained right here,
certainly like what you are saying and the best way
by which you say it. You're making it entertaining and you still care for to stay it wise.
I cant wait to learn far more from you. This is actually a great site.

How are you, cool web site

How are you, cool web site you have got going here.

hakodategagome. naimayy.

And this is an funding threat

And this is an funding threat value taking.

I'm really loving the

I'm really loving the theme/design of your website.
Do you ever run into any browser compatibility problems?
A handful of my blog audience have complained about
my website not operating correctly in Explorer
but looks great in Safari. Do you have any solutions to help fix
this issue?

Great looking web site. Think

Great looking web site. Think you did a great deal of your very own coding.

Great blog right here!

Great blog right here! Additionally your web site lots up fast!
What web host are you using? Can I get your affiliate hyperlink
in your host? I desire my web site loaded up as
quickly as yours lol

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.