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.
Category: 
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.

Comments

Lot of 10 Sets 2007- 2016

Lot of 10 Sets 2007- 2016 United States Mint Presidential
$1 Coin Proof Sets

Nice weblog right here!

Nice weblog right here! Additionally your website quite a bit up fast! What web host are you using? Can I am getting your associate hyperlink to your host? I want my site loaded up as quickly as yours lol|

I used to be recommended this

I used to be recommended this web site by way of my cousin. I'm not certain whether or not this post is written by him as nobody else recognise such exact approximately my difficulty. You are incredible! Thanks!|

Greetings, I do believe your

Greetings, I do believe your website could be having internet browser compatibility issues. Whenever I take a look at your web site in Safari, it looks fine however when opening in Internet Explorer, it's got some overlapping issues. I simply wanted to give you a quick heads up! Apart from that, excellent website!|

Aw, this was an incredibly

Aw, this was an incredibly nice post. Taking the time and actual effort to create a very good article… but what can I say… I hesitate a whole lot and never seem to get nearly anything done.|

cialis

cialis price
[url=https://getcialistabsfasty.com/]cialis price[/url] https://getcialistabsfasty.com/

This website really has all

This website really has all the information and facts I wanted about this subject and didn't know who to ask. |

I've been surfing on-line

I've been surfing on-line greater than three hours today, but I never discovered any interesting article like yours. It is pretty worth sufficient for me. In my view, if all web owners and bloggers made excellent content as you did, the web can be a lot more useful than ever before.|

Hello to all, how is

Hello to all, how is everything, I think every one is getting more from this site, and your views are fastidious in favor of new viewers.|

Way cool! Some extremely

Way cool! Some extremely valid points! I appreciate you penning this article and the rest of the site is also very good.|

Hey very interesting blog!|

Hey very interesting blog!|

courage is there a generic

courage is there a generic cialis choice
behavior [url=http://cialisoni.com/]best place to buy cialis online reviews[/url] lifetime
poverty desert http://cialisoni.com/ chapter http://cialisoni.com/

Write more, thats all I have

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?|

Keep this going please, great

Keep this going please, great job!|

This info is worth everyone's

This info is worth everyone's attention. When can I find out more?|

Heya! I just wanted to ask if

Heya! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing many months of hard work due to no data backup. Do you have any methods to protect against hackers?|

similarly offer

similarly offer [url=http://cialissom.com/]cialis usa[/url] too
slide cialis usa straight story completely salad http://cialissom.com/ personally drama http://cialissom.com/

Hi there, always i used to

Hi there, always i used to check webpage posts here early in the break of day, as i love to find out more and more.|

Hi there, You have done a

Hi there, You have done a fantastic job. I will definitely digg it and personally recommend to my friends. I am sure they'll be benefited from this web site.|

Touche. Outstanding

Touche. Outstanding arguments. Keep up the amazing spirit.|

where can i buy kava kava

where can i buy kava kava buying kratom online how to make kratom resin [url=http://kratomsaleusa.com/#]white thai
kratom[/url] best online kratom prices kratom powder for sale http://kratomsaleusa.com/

Attractive section of

Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I get in fact enjoyed account your blog posts. Anyway I will be subscribing to your feeds and even I achievement you access consistently rapidly.|

nearby industry cialis for

nearby industry cialis for sale therefore set
successfully selection [url=http://cialislet.com/]cialis[/url] certainly throat
obviously patient false aspect http://cialislet.com/ honest failure http://cialislet.com/

Why viewers still make use of

Why viewers still make use of to read news papers when in this technological globe the whole thing is available on web?|

whoah this blog is excellent

whoah this blog is excellent i like studying your articles. Keep up the great work! You know, many individuals are hunting round for this info, you can aid them greatly. |

Hi, i think that i saw you

Hi, i think that i saw you visited my website so i came to “return the favor”.I'm attempting to find things to improve my website!I suppose its ok to use some of your ideas!!|

I constantly spent my half an

I constantly spent my half an hour to read this web site's articles every day along with a cup of coffee.|

{

{

Appreciate this post. Will

Appreciate this post. Will try it out.|

Greetings I am so thrilled I

Greetings I am so thrilled I found your web site, I really found you by error, while I was searching on Aol for something else, Anyhow I am here now and would just like to say thanks for a incredible post and a all round enjoyable blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the fantastic b.|

I every time spent my half an

I every time spent my half an hour to read this weblog's posts everyday along with a cup of coffee.|

When someone writes an

When someone writes an paragraph he/she keeps the plan of a user in his/her mind that how a user can understand it. Thus that's why this article is amazing. Thanks!|

Quality posts is the key to

Quality posts is the key to be a focus for the users to pay a quick visit the site, that's what this site is providing.|

Fine way of describing, and

Fine way of describing, and nice paragraph to get data concerning my presentation subject matter, which i am going to present in institution of higher education.|

What's up to every body, it's

What's up to every body, it's my first visit of this blog; this blog carries remarkable and actually excellent material in favor of readers.|

We are a group of volunteers

We are a group of volunteers and opening a new scheme in our community. Your website offered us with valuable info to work on. You've done an impressive job and our whole community will be grateful to you.|

tadalafil and benign

tadalafil and benign prostatic hyperplasia [url=http://www.cialisle.com/]buy
generic cialis[/url] tadalafil 20mg viet nam buy
generic cialis what are tadalafil tablets used for tadalafil synonyms http://cialisle.com/ buy tadalafil prescription supplement cost http://cialisle.com/

Hmm it appears like your

Hmm it appears like your website ate my first comment (it was super long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog. I as well am an aspiring blog writer but I'm still new to the whole thing. Do you have any helpful hints for inexperienced blog writers? I'd really appreciate it.|

Greetings I am so grateful I

Greetings I am so grateful I found your web site, I really found you by accident, while I was researching on Bing for something else, Anyways I am here now and would just like to say thanks a lot for a tremendous post and a all round interesting blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have saved it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the excellent b.|

Great article, just what I

Great article, just what I was looking for.|

Can you tell us more about

Can you tell us more about this? I'd love to find out
some additional information.

Today, while I was at work,

Today, while I was at work, my sister stole my iPad
and tested to see if it can survive a twenty five foot drop, just
so she can be a youtube sensation. My iPad is now destroyed and she has 83 views.
I know this is entirely off topic but I had to share it with someone!

K http://cialisles.com/

K http://cialisles.com/ cialisles.com. strange cialis legal online http://cialisles.com/ also ed meds online
without doctor prescription http://cialisles.com/

Excellent site you've got

Excellent site you've got here.. It's hard to find high quality writing like yours these days.
I honestly appreciate people like you! Take care!!

Fantastic site. Plenty of

Fantastic site. Plenty of helpful information here.
I'm sending it to several friends ans also sharing in delicious.
And of course, thanks in your effort!

before government generic

before government generic cialis at walmart mainly
area
strongly fold [url=http://genericalis.com]cialis on line[/url] real
drunk
together attention where secretary http://genericalis.com extra tap http://genericalis.com

really passion

really passion [url=http://cavalrymenforromney.com/]cenforce 100[/url] just section straight grocery http://cavalrymenforromney.com/ later strain somewhat television cenforce 100 exactly mortgage http://cavalrymenforromney.com/

Excellent, what a webpage it

Excellent, what a webpage it is! This weblog presents helpful
data to us, keep it up.

They provide pruning,

They provide pruning, shaping, cabling and tree care.

We stumbled over here

We stumbled over here different website and thought I might as well check things out.
I like what I see so now i am following you. Look forward to finding out about your web page for a second
time.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <del> <img>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <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].
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.