Google Cloud数据存储区 - 按类型查询和按GQL查询的不同结果

问题描述 投票:0回答:1

我有2种类型的查询,按Kind和GQL

$query = $datastore
         ->query()
         ->kind('files')
         ->filter('tags','=','texture')
         ->filter('tags','=','newspaper')
         ->start($pageCursor);

这比GQL查询提供了更多结果:

$query = $datastore
         ->gqlQuery
         ("SELECT * 
           FROM files
           where tags='texture' and tags='newspaper'",
           ['allowLiterals' => true]
         );

为什么他们的结果不一样?

我的查询结果:https://drive.google.com/open?id=1r-Tonqs1ld4bKo0woIcR_UrMUTc1em0D

如果我使用GQL查询,则只找到4个结果

更新您可以按照此主题:https://github.com/googleapis/google-cloud-php/issues/1696

google-cloud-datastore gql
1个回答
0
投票

如果没有看到您的代码,很难找到您的错误,请在下一个问题中提供更多详细信息。

我已经使用了您的示例,所有工作都按预期进行。该脚本的输出是:

Query by kind retrieves 19 results Query by GQL retrieves 19 results

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\Datastore\DatastoreClient;
# Your Google Cloud Platform project ID
$projectId = 'YOUR-PROJECT-ID';

$datastore = new DatastoreClient([
    'projectId' => $projectId
]);

$titles = ['man sitting near door', 'way reading paper', 'scattered magazines', 'grayscale ', 'photography of kanji text', 'texture: vintage newspaper', 'wall floor recycle light simple', 'old newspaper texture', 'Mockup Old Paper Color  ', 'Mockup Journal.', 'Old Newspaper Texture', 'Triangle Geometric Graphic Pattern Template', 'paperboard carton surface beige plain', 'paperboard simple fiber dusty texture', 'Designer Workspace', 'craft texture brown journal note', 'Brown texture', 'Newspaper collage texture', 'Texture Newspaper'];

$tags = ['newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, age, chinese, china, chinese newspaper', 
    'world, war, newspaper, texture, history, grunge, pattern, american, war, battle', 'basket, yellow building, shop, colour, wallpaper, texture, misc, wallpaper, urban, bicycle, morning, sidewalk, asian, newspaper, yellow, street, bike, man, tree, china, bycicle', 
    'man, boy, male, card, paper, decoration, woman, child, smile, torn, wall, paper, poster, texture, old, affiche wall advert wallpaper portugal wall poster erosion used print urban, newspaper', 
    'white, cloud, house, bw, black and white, pattern, light, street, silhouette, texture, calligraphy, composition, japanese, japan, newspaper, character, wall, wall paper, wall art, poster, black and white, png images', 
    'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, vintage newspaper', 
    'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean', 
    'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, age, old paper', 
    'newspaper, cut, paper, kraft, cardboard, mockup, old, slip, ad, advertisement, advertising, ancient, announcement, antique, backdrop, background, banner, blank, border, card, christmas, communication, design, dirty, edge, empty, grunge, illustration, information, label, letter, message, note, page, parchment, pattern, poster, red, ripped, shadow, sticker, tag, template, texture, torn, vector, vintage, wallpaper, web, white', 
    'leather, magazine, mockup, book, black, spread, page, double, brochure, blank, reading, journal, template, a4, holding, hand, newspaper, front, leaflet, person, back, binding, softcover, big, pamphlet, album, business, clear, dark, design, desk, display, document, glossy, grey, hard, hardcover, layout, ledger, mag, mock up, news, opened, paper, paperback, print, sheet, showing, soft, text, texture', 
    'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, age',
    'pattern, people, texture, template, geometric, paint, home, triangle, geometric pattern, graphic, kid, child, square, bag, person, paper texture, window, creative, newspaper, plants',
    'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
    'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
    'designer, table, workspace, computer, flat, object, workstation, desktop, design, work, office, home, desk, display, lamp, concept, cup, decor, modern, illustration, monitor, interior, inside, house, education, job, book, coffee, business, light, style, background, graphic, workplace, icons, symbol, elements, equipment, emblem, lifestyle, place, decorative, collection, room, set, organization, stylish, freelance, notepad, creative, jobs, creativity, mug, email, view, bulb, tablet, notebook, top, wood, number, texture, newspaper, think, paper, talk, bubble, mock-up, speech, item, media, template, idea, management, mock, project, mail, infographic, connect, wooden, chat, icon, content, pc, space, minimalism, vector, technology, web, screen, website, white, corporate, decorated, mouse, internet, process, clock',
    'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
    'pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, vintage pattern, recycle, natural, document, clean, floor',
    'newspaper, texture, collage, news, old, background, text, book',
    'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall'];

$i = 0;
foreach ($titles as $title){
    $entity = $datastore->entity('Examples');
    $entity['title'] = $title;
    $entity['tags'] = explode(", ", $tags[$i]);
    $datastore->insert($entity);
    $i = $i + 1; 
}

sleep(1);

$query = $datastore
         ->query()
         ->kind('Examples')
         ->filter('tags','=','texture')
     ->filter('tags','=','newspaper');

$results = $datastore->runQuery($query);

$count = 0;
foreach ($results as $res) {
    $count++;
}
echo 'Query by kind retrieves ', $count, ' results', PHP_EOL ;


$query = $datastore
         ->gqlQuery
         ("SELECT * 
           FROM Examples
           where tags='texture' and tags='newspaper'",
           ['allowLiterals' => true]
         );

$results = $datastore->runQuery($query);

$count = 0;
foreach ($results as $res) {
    $count++;
}
echo 'Query by GQL retrieves ' ,$count, ' results', PHP_EOL;
© www.soinside.com 2019 - 2024. All rights reserved.