function solr_machinetags_query_for_path_hierarchy($mt, $field, $more = array())
{
    list($ns, $pred, $value) = solr_machinetags_explode($mt);
    $k = array();
    if ($ns != '*') {
        $k[] = solr_machinetags_add_lazy8s($ns);
    }
    if ($pred != '*') {
        $k[] = solr_machinetags_add_lazy8s($pred);
    }
    $k = count($k) ? implode("/", $k) : '';
    $v = $v == '*' ? solr_machinetags_add_lazy8s($value) : '';
    $query = array();
    if ($k) {
        $query[] = "{$field}:{$k}/*";
    }
    $values = $value ? explode(" ", $value) : array();
    $count = count($values);
    for ($i = 0; $i < $count; $i++) {
        $v = solr_machinetags_add_lazy8s($values[$i]);
        if ($count == 1) {
            $q = "{$field}:*/{$v}";
        } else {
            if ($i == 0) {
                $q = "{$field}:{$k}/{$v}*";
            } else {
                if ($i == $count - 1) {
                    $q = "{$field}:{$k}/*{$v}";
                } else {
                    $q = "{$field}:{$k}/*{$v}*";
                }
            }
        }
        $query[] = $q;
    }
    $q = implode(" AND ", $query);
    return $q;
}
function flickr_photos_search_index_photo(&$photo, $meta = array())
{
    if (!$GLOBALS['cfg']['enable_feature_solr']) {
        return not_okay('search indexing is disabled');
    }
    if (!$meta) {
        $meta = flickr_photos_metadata_load($photo);
    }
    # really exit or just ignore all the $meta stuff below?
    if (!$meta['ok']) {
        return not_okay('failed to load photo metadata');
    }
    $meta = $meta['data']['photo'];
    $doc = array('id' => $photo['id'], 'user_id' => $photo['user_id'], 'title' => $photo['title'], 'perms' => $photo['perms'], 'datetaken' => solr_dates_prep_mysql_datetime($photo['datetaken']), 'dateupload' => solr_dates_prep_mysql_datetime($photo['dateupload']));
    $tags = array();
    $machinetags = array();
    if (isset($meta['tags']['tag'])) {
        foreach ($meta['tags']['tag'] as $tag) {
            $tags[] = $tag['raw'];
            if ($tag['machinetag']) {
                $machinetags = array_merge($machinetags, solr_machinetags_explode($tag['raw']));
            }
        }
    }
    if (count($tags)) {
        $doc['tags'] = $tags;
    }
    if (count($machinetags)) {
        $doc['machinetags'] = $machinetags;
    }
    if ($photo['hasgeo']) {
        $doc['location'] = "{$photo['latitude']},{$photo['longitude']}";
        $doc['accuracy'] = $photo['accuracy'];
        $doc['geoperms'] = $photo['geoperms'];
        $doc['geocontext'] = $photo['geocontext'];
        foreach (array('neighbourhood', 'locality', 'county', 'region', 'country', 'continent') as $place) {
            if (isset($meta['location'][$place])) {
                $doc[$place] = $meta['location'][$place]['woeid'];
            }
        }
        if ($place = flickr_places_get_by_woeid($photo['woeid'])) {
            $doc['timezone'] = $place['timezone'];
            $doc['place'] = $place['place_url'];
        }
    }
    # pull in some EXIF data (if present)
    $rsp = flickr_photos_exif_read($photo);
    if ($rsp['ok']) {
        $exif = $rsp['rows'];
        if (isset($exif['Make'])) {
            if ($make = exif_tools_scrub_string($exif['Make'])) {
                $doc['camera_make'] = ucwords($make);
            }
        }
        if (isset($exif['Model'])) {
            if ($model = exif_tools_scrub_string($exif['Model'])) {
                $doc['camera_model'] = $model;
            }
        }
        # EXIF: what else?
        if (isset($exif['FocalLength'])) {
            $doc['focal_length'] = exif_tools_rational2float($exif['FocalLength']);
        }
        if (isset($exif['ApetureValue'])) {
            $doc['apeture'] = exif_tools_rational2float($exif['ApetureValue']);
        }
        if (isset($exif['ShutterSpeedValue'])) {
            $doc['shutter_speed'] = exif_tools_rational2float($exif['ShutterSpeedValue']);
        }
        if (isset($exif['ISOSpeedRatings'])) {
            $doc['iso_speed'] = intval($exif['ISOSpeedRatings']);
        }
        # http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/GPS.html
        if (isset($exif['GPSAltitude'])) {
            $altitude = exif_tools_explode_gps_altitude($exif['GPSAltitude'], $exif['GPSAltitudeRef']);
            $doc['altitude'] = $altitude;
        }
        if (isset($exif['GPSImgDirection'])) {
            $direction = exif_tools_explode_gps_img_direction($exif['GPSImgDirection'], $exif['GPSImgDirectionRef']);
            $doc['direction'] = $direction;
        }
    }
    # go!
    $docs = array($doc);
    $rsp = solr_add($docs);
    return $rsp;
}