In the methods SearchApiSolrService::getFieldNames and SearchApiSolrService::searchMultiple, the field search_api_id is mapped to a non-existent doc element, ss_search_api_id, which results in an invalid item id in result sets:

      // This array maps "local property name" => "solr doc property name".
      $ret = array(
        'search_api_id' => 'ss_search_api_id',
        'search_api_relevance' => 'score',
        'search_api_item_id' => 'item_id',
      );
    // Get field information
    $solr_fields = array(
      'search_api_id' => 'ss_search_api_id',
      'search_api_relevance' => 'score',
      'search_api_multi_index' => 'index_id',
    );

Changing these fields to map to id instead maps to the correct Solr doc element. Patch to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arpieb’s picture

... and here's the patch against 7.x-1.x, commit id 8d86923.

arpieb’s picture

Status: Active » Needs review
drunken monkey’s picture

Thanks for reporting!
We previously had a <copyField source="item_id" dest="ss_search_api_id" /> directive in schema.xml (now gone because of the common configs), that's where this comes from. Although I'm not actually sure what the advantage was, compared to just using the item_id field directly … It seems it's because item_id wasn't optimized for sorting – which of course makes no difference as long as the item IDs are numeric, which they usually are. And in this case, sorting on them using a string type leads to useless results anyways.
So, on the whole I'd say this functionality is pretty useless anyways, but for the sake of completeness we should of course still fix the code. Changing the field mapping to id isn't right, though – as said, it should refer to the item_id. So I guess we can just change this and drop search_api_item_id completely.

See the attached patch.

arpieb’s picture

It's my understanding that item_id is equivalent to nid in this module, which is only unique for a specific site. If multiple sites are being indexed on a single Solr index, then item_id does not uniquely identify a search result item - but id does.

A use case - I'm working on a module that allows you to curate lists of items from across multiple sites using search to populate an auto complete. Without the globally-unique id element being made available, there is no way that field is ever going to work. There could be other cases as well, that is the one I'm currently running into though.

Beyond that - it's a required, defined element being returned by Solr that really should be included in the available fields for a search result item.

drunken monkey’s picture

Well, not quite. The id is only unique as long as sites don't use the same index machine names. But of course, you'd have to follow that anyways for things to work.

I don't really understand your use case, but multi-site functionality is definitely something we should support better than currently. If it'd help you this much, I guess we can just introduce a new search_api_solr_id key (or something similar) to the results.

However, note that there's already $return['search_api_solr_response'] set on the return value of the search query for queries on the Solr server. From that, you could already get the Solr-specific IDs pretty easily, as well as any other fields you need.

drunken monkey’s picture

Status: Needs review » Fixed

Committed.
Please re-open with more information if you need anything else for your use case (see my previous comment) – or, better still, open a new issue to keep things in order.

Status: Fixed » Closed (fixed)

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