Apache_Solr_Document should support toArray() or similar functionality.

26 views
Skip to first unread message

ant92083

unread,
Jan 10, 2012, 10:02:00 AM1/10/12
to PHP Solr Client
I have noticed that the library supports retrieving the values of the
fields or the keys of the fields but not both together. I find myself
extending Apache_Solr_Document for such a trivial task. Could we not
add something to Apache_Solr_Document such as:

public function toArray() {
return $this->_fields;
}

I thought about this long and hard and it makes sense because if you
work in a sort of framework such as Zend having a the key/value pairs
is vital to doing some pretty mundane tasks when working with the
table/gateway access patterns. Thoughts suggestions?

Donovan Jimenez

unread,
Jan 10, 2012, 1:17:40 PM1/10/12
to php-sol...@googlegroups.com
Apace_Solr_Document is iterable just like an associative array, which i imagine is what you're looking to do.

<code>
// this works, and is the typical use case
foreach ($document as $key => $value) {...}
</code>

The key and field methods are just analogies to array_keys and array_values since they're not covered by the IteratorAggregate interface. You could also work directly with the iterator if you so desire.

- Donovan
> --
> You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
> To post to this group, send email to php-sol...@googlegroups.com.
> To unsubscribe from this group, send email to php-solr-clie...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/php-solr-client?hl=en.
>
>

Anthony Wlodarski

unread,
Jan 10, 2012, 1:24:12 PM1/10/12
to php-sol...@googlegroups.com
This is correct. I forgot that it was an interface that was implemented.  This suits my needs perfectly.
Reply all
Reply to author
Forward
0 new messages