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

billion to build, making it

billion to build, making it the most expensive project in industry history. Additionally,
https://www.bomnar33.com 카지노사이트

Lot of 10 Sets 2007- 2016

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

I think this is among the

I think this is among the most significant info for me.

And i'm glad reading your article. But want to remark on few general things, The website style
is ideal, the articles is really nice : D. Good job, cheers

Every weekend i used to visit

Every weekend i used to visit this website, for
the reason that i wish for enjoyment, since this this site conations actually pleasant funny material too.

order cialis online

order cialis online https://cialisle.com/

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|

Hi! I could have sworn I've

Hi! I could have sworn I've been to this site before but after checking through
some of the post I realized it's new to me. Nonetheless,
I'm definitely happy I found it and I'll be book-marking and checking
back often!

Hello would you mind stating

Hello would you mind stating which blog platform you're working with?
I'm planning to start my own blog soon but I'm having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your layout seems different then most blogs and I'm looking for something unique.

P.S Apologies for being off-topic but I had to ask!

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 clearly know what youre talking about, why throw away your intelligence on just posting videos to your weblog when you
could be giving us something enlightening to read?

Hey there are using Wordpress

Hey there are using Wordpress for your blog platform?
I'm new to the blog world but I'm trying to get started and create my own. Do you need any coding expertise to make
your own blog? Any help would be greatly appreciated!

Thanks for sharing your

Thanks for sharing your thoughts about ig. Regards

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!|

Thanks for finally talking

Thanks for finally talking about >Válasz a hozzászólásra

We are a group of volunteers

We are a group of volunteers and starting a new scheme in our community.
Your website offered us with valuable info to work on. You have done a
formidable job and our entire community will be thankful to
you.

Incredible quest there. What

Incredible quest there. What occurred after? Good luck!

Actually no matter if someone

Actually no matter if someone doesn't be aware of after that its
up to other visitors that they will assist, so here it
occurs.

Incredible! This blog looks

Incredible! This blog looks just like my old one! It's on a entirely different
subject but it has pretty much the same page layout and design. Great choice
of colors!

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!|

Quality content is the main

Quality content is the main to be a focus for the users to pay a visit the web page, that's what this web page is providing.

That is very interesting,

That is very interesting, You're an overly professional blogger.
I've joined your feed and sit up for looking for extra of your magnificent
post. Also, I have shared your web site in my social networks

I am really enjoying the

I am really enjoying the theme/design of your web site. 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 Chrome.
Do you have any recommendations to help fix
this issue?

You ought to take part in a

You ought to take part in a contest for one of the highest quality
websites on the web. I am going to recommend this blog!

It's really very complicated

It's really very complicated in this active life to listen news on Television, thus I only use web for
that purpose, and get the most recent news.

Definitely believe that which

Definitely believe that which you said. Your favorite
justification appeared to be on the web the simplest thing to be aware of.
I say to you, I certainly get annoyed while people think about worries
that they plainly do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people can take a signal.
Will probably be back to get more. Thanks

Hey There. I found your blog

Hey There. I found your blog using msn. This is an extremely well written article.
I'll make sure to bookmark it and come back to read more
of your useful information. Thanks for the post. I'll definitely comeback.

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

Hi! Do you know if they make

Hi! Do you know if they make any plugins to assist
with Search Engine Optimization? I'm trying to get my blog
to rank for some targeted keywords but I'm not
seeing very good gains. If you know of any please share.
Appreciate it!

I was suggested this blog by

I was suggested this blog by my cousin. I am not sure whether this post is written by
him as nobody else know such detailed about my difficulty.
You are wonderful! Thanks!

Hey there, I think your blog

Hey there, I think your blog might be having browser compatibility issues.
When I look at your website in Chrome, it looks
fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that, superb blog!

Great blog here! Also your

Great blog here! Also your web site a lot up
very fast! What web host are you the use of?

Can I am getting your affiliate link to your host? I wish my web site loaded up as quickly as yours lol

There's certainly a great

There's certainly a great deal to learn about this
subject. I really like all the points you have made.

cialis

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

I do not know whether it's

I do not know whether it's just me or if everyone else
encountering problems with your site. It appears as if some of the written text on your content are
running off the screen. Can somebody else please provide feedback and let me know if this
is happening to them too? This might be a problem with my internet
browser because I've had this happen previously. Many thanks

Simply want to say your

Simply want to say your article is as astonishing. The clearness in your post is just nice and i could assume you're an expert on this subject.
Well with your permission allow me to grab your feed to keep updated with forthcoming post.
Thanks a million and please continue the rewarding work.

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

Hi, the whole thing is going

Hi, the whole thing is going sound here and ofcourse every one is
sharing facts, that's truly good, keep up writing.

Howdy! Do you know if they

Howdy! Do you know if they make any plugins to assist with Search Engine
Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good
gains. If you know of any please share. Thanks!

Right here is the perfect

Right here is the perfect website for everyone who hopes to understand this topic.
You know so much its almost tough to argue with you (not that I
actually would want to…HaHa). You certainly put a brand
new spin on a topic that's been discussed for decades.

Great stuff, just great!

Thanks a bunch for sharing

Thanks a bunch for sharing this with all of us you actually know what you're speaking approximately!

Bookmarked. Please also discuss with my website
=). We could have a hyperlink change agreement
among us

warm

warm [url=https://www.liverichandfree.com/#]generic cialis 2020[/url]
above cialis buy generic hero https://www.liverichandfree.com/

buy clomid

This post is worth everyone's

This post is worth everyone's attention. Where can I find out more?

cialis

cialis adcirca
[url=https://calis24.com/#]buy cialis online no prescription[/url] https://calis24.com/

I am curious to find out what

I am curious to find out what blog system you are working with?
I'm experiencing some small security issues with my latest blog and I would like to
find something more safe. Do you have any recommendations?

This is really fascinating,

This is really fascinating, You are a very
skilled blogger. I have joined your rss feed and stay up for in the hunt for extra of your great post.
Also, I've shared your site in my social networks

Hello! I'm at work surfing

Hello! I'm at work surfing around your blog from my new iphone
3gs! Just wanted to say I love reading your blog and look forward to all your posts!
Keep up the outstanding work!

It's a shame you don't have a

It's a shame you don't have a donate button! I'd definitely donate to this outstanding blog!
I guess for now i'll settle for book-marking and adding your RSS feed
to my Google account. I look forward to brand new updates and will talk about this website with my Facebook group.
Chat soon!

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

I really like your blog..

I really like your blog.. very nice colors & theme.
Did you make this website yourself or did you hire someone to do it for
you? Plz respond as I'm looking to create my own blog and would like to know where u got
this from. thank you

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.