Comments

maciej.zgadzaj’s picture

Status: Active » Needs review
StatusFileSize
new2.05 KB

Promised patch attached:

  • fixes 2 bugs found in the code (thanks prics for that)
  • makes items being indexed in the correct language (as defined in search_api_language property)
drunken monkey’s picture

StatusFileSize
new2.05 KB

Thanks for the patch! Looks good on the whole, just one thing:

+++ b/datasource.inc
@@ -161,7 +160,7 @@ class SearchApiEtDatasourceController extends SearchApiEntityDataSourceControlle
+      foreach (search_api_et_item_languages($entity, $entity->entityType, $index) as $lang) {

Why should this work? Entities don't have that property, at least not in general.

Revised patch attached.

maciej.zgadzaj’s picture

Status: Needs review » Reviewed & tested by the community

Yes, $this of course, my bad, haven't spotted this. Thanks!

RTBC?

maciej.zgadzaj’s picture

One more thing - in getMetadataWrapper() we need to check whether $item is an object/has language defined, otherwise it gets red when for example configuring an index. Improved patch attached.

d3claes’s picture

With all the patches in the issue queue applied, I can successfully create an index based on node (multilingual), set fields, workflow and finally build the index.

Building the view generates an ajax-error on adding a field or filter:
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 744 in sites\all\modules\entity\includes\entity.wrapper.inc).

maciej.zgadzaj’s picture

d3claes, thanks for your feedback. So far I have been focusing on making indexing work properly, and making sure that basic code search returns expected result (you can check my fork of this sandbox, Search API Entity Translation v2b, which is getting all the patches (and a bit more) committed first) for an example of such a search.

True I haven't looked yet into how this works with more advanced querying systems (like mentioned Views), but it is on my to-do list too, right after I finish with the admin UI for the index settings, which I am working at right now (time permitting).

maciej.zgadzaj’s picture

d3claes, that EntityMetadataWrapperException should be fixed now with the recent commit in my sandbox linked to in my previous comment.

d3claes’s picture

Hi,
Thank you for committing the patches into one package... that is very convenient.
I tried your sandbox version and I've managed to create a simple page succesfully with search_api_page.
But when I build a search page again via views, I'm still receiving the same error message on adding a field or a filter:
- with display format 'rendered entity' (display search result), and
- with display format 'fields'
Are there certain conditions (minimum versions) for modules like entity or views?
Sincerely,
d3claes

maciej.zgadzaj’s picture

Yes, sorry, my fault here, I have committed the fix yesterday, but haven't pushed it to d.o., that's why you were still getting an error. Only pushed it today about half an hour ago, so you might want to pull again, should fix an issue for you.

d3claes’s picture

Hi,
Yes, we are one step further.
This is the sql error message I'm receiving when adding a field to the view:
PDOException: SQLSTATE[22018]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Conversion failed when converting the nvarchar value 'fr_1339' to data type int.: SELECT revision.[vid] AS [vid], base.[uid] AS [uid], revision.[title] AS [title], revision.[log] AS [log], revision.[status] AS [status], revision.[comment] AS [comment], revision.[promote] AS [promote], revision.[sticky] AS [sticky], base.[nid] AS [nid], base.[type] AS [type], base.[language] AS [language], base.[created] AS [created], base.[changed] AS [changed], base.[tnid] AS [tnid], base.[translate] AS [translate], revision.[timestamp] AS [revision_timestamp], revision.[uid] AS [revision_uid] FROM {node} base INNER JOIN {node_revision} revision ON revision.vid = base.vid WHERE ( ([base].[nid] IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9)) ); Array ( [:db_condition_placeholder_0] => fr_1001 [:db_condition_placeholder_1] => fr_1010 [:db_condition_placeholder_2] => fr_1011 [:db_condition_placeholder_3] => fr_1014 [:db_condition_placeholder_4] => fr_1053 [:db_condition_placeholder_5] => fr_1271 [:db_condition_placeholder_6] => fr_1317 [:db_condition_placeholder_7] => fr_1332 [:db_condition_placeholder_8] => fr_1335 [:db_condition_placeholder_9] => fr_1339 ) in DrupalDefaultEntityController->load() (regel 203 van C:\doc-drupal\includes\entity.inc).
The language is still part of the passed id's.

maciej.zgadzaj’s picture

No such error in my sandbox, and with the last commit you shouldn't be getting the language code in obtained ids.

Have you cleared your caches? And then cleared them again? ;) And then disabled and reenabled the index to requeue and reindex all items?

d3claes’s picture

It is difficult to follow the functions one after each other because many classes are being extended, etc.
In #10, the call to entity->load that is raising the error message is in line 470 of sites/all/modules/search_api/contrib/search_api_views/includes/query.inc. The parameter $results passed to this function get_result_wrappers($results, $relationship = NULL, $field = NULL) has the language part in the id's.
It is not the fct. getMetadataWrapper() in datasource_entity.inc from your sandbox that generated the fault.
When I extract the id-parts similar at line 470, the view get build correctly.

maciej.zgadzaj’s picture

Could you verify that SearchApiEtDatasourceController::getMetadataWrapper() is being called at all? And if so, what is the value of $item right before $wrapper = entity_metadata_wrapper($this->entityType, $item, $info);?

And just to make sure, would you mind deleting and recreating your multilingual index from scratch?

d3claes’s picture

StatusFileSize
new12.71 KB
new15.19 KB

I've used the patch in https://drupal.org/node/1937832 to create a 'stacktrace' and 'backtrace', if this is of any help:
stacktrace:
stacktrace

backtrace:
backtrace

Although it's not mentioned as such in the above lists, the fct. getMetadataWrapper() in datasource_entity.inc gets called twice per node (print_r($item)):
- first time with $item = language_nid (which get cleaned up by explode() above it)
- second time with $item = entity-object
First all the nids get passed, then the objects

Caches were emptied, and index and view were fresh build.

maciej.zgadzaj’s picture

Ok, I see where the issue is. Essentially it's because SearchApiViewsQuery::get_result_wrappers() calls entity_load() with an array of entity IDs still including language code in them (so they are strings instead of integers), and then your MSSQL returns an error (which is not the case for MySQL, which I'm running here).

The good thing is that $wrappers are still properly populated (at least in my case, could you confirm it's the case for you too?), so the whole thing essentially works (apart from that exception obviously), the bad though that I have followed the whole workflow how the results are passed from server service to the view and still have no good idea how to fix it nicely.

Tried new processor to update id of each item in $response['results'] array, but unfortunately Search API Views is using array keys instead of this value when populating $view->result in SearchApiViewsQuery::addResults(), which can't be changed to just entity ID only (as then the results could be overwriting each other).

The best rough idea so far is to just extend SearchApiViewsQuery and override addResults() to make it ET-specific, but I don't really like too much...

maciej.zgadzaj’s picture

Just pushed new commit, I believe this should fix your issue.

d3claes’s picture

I can confirm that with this latest patch no errors/notices are raised during the building of the index, the creation of the view and the use of the view.
Thank you very much!

I will do some additional testing on building and using the view (available fields and exposed filters)... but that's beyond this issue.

maciej.zgadzaj’s picture

Happy to hear that!

If you spot anything else, just open a new issue directly in my sandbox.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

I've committed the patch in #4. Thanks again!

Regarding the other fixes in your sandbox: have you posted patches for those in my issue queue, too? I do think we should keep things in one location, if possible. I'd be happy to give you committ access to this sandbox, too, however, if you want. Or, if your sandbox is already more or less finished, we can just ask Daniel whether he wants to commit that, and if I have things to add I can then just create issues for the main project.

maciej.zgadzaj’s picture

You've probably already seen that I stopped posting patches at one point, committing all new changes to my sandbox only instead as I went along (as it was just much easier for me to work this way instead of constantly fiddling with patches, also making life easier for others wanting to try this all out).

It seems to be working fine right now, at least I haven't spotted any serious issues with it yet (there is one support request which I need to investigate, but as far as I remember I had a very quick look into it right before leaving for holidays and everything worked fine for me).

One thing that still would need to be changed is that unfortunate deleting indexes in hook_disable() implementation, but for this Search API would need to be improved first to not try to load classes for disabled indexes. (I was working with the most recent dev version and the issue was still there.)

If you and Daniel are ok with it, I'd suggest we just commit all the changes from my sandbox after they are reviewed (would be great if you could have a look at the new code too when you have a second and perhaps play with it a bit and try to break it), and then we'll just get rid of all those many sandboxes.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.