The current Solr_Base_Query object exposes functionality to add a subquery, and to remove a subquery. Unfortunately, it does not provide the ability to retrieve the subqueries that are currently part of a query object. In order to properly remove a subquery from the object, you must know the query id of the sub query you'd like to remove. The subqueries attribute is protected and thus not accessible from any other modules. With the query id being dynamically assigned, it seems important to be able to retrieve the array of sub queries in order to get the correct query id.

This patch exposes two new functions: get_subqueries($query_id = NULL) and get_fields($name = NULL). Both the Drupal_Solr_Query_Interface and Solr_Base_Query class have been updated.

CommentFileSizeAuthor
apachesolr_expose_subqueries.patch1.77 KBsocki

Comments

pwolanin’s picture

Status: Needs review » Needs work

code style does not conform.

What's the utility of the $query_id param?

We already have a method that returns all fields:

  public function get_filters($name = NULL) {
    if (empty($name)) {
      return $this->fields;
    }
    reset($this->fields);
    $matches = array();
    foreach ($this->fields as $filter) {
      if ($filter['#name'] == $name) {
        $matches[] = $filter;
      }
    }
    return $matches;
  }
socki’s picture

The query_id was meant just to be consistent with the other get functions which allow you to get (or check for) a specific subquery rather then retrieve an array of them all. I suppose that this parameter would be left out more often then not.

I made a mistake there with the get_filters method, it was actually more to expose the 'filterstring' attribute, and not fields.

I've noticed (and come across a case) where the 'keys' attribute could also use a function. On general search it should be possible to determine the keyword from the url string.

I will generate a new patch with these updates.

pwolanin’s picture

while this is annoyingly unusable as-is, do you have an actual use case to remove a subquery?

jpmckinney’s picture

Status: Needs work » Closed (duplicate)

Marking duplicate of #926564: Add get_subqueries() which is more minimal.