【问题标题】:Zend Gdata Calendar: setQuery with exact phrase match?Zend Gdata 日历:setQuery 与完全匹配的短语?
【发布时间】:2024-01-21 01:17:01
【问题描述】:

我无法使用 Zend_Gdata_Calendar 返回具有完全匹配词组的 Google 日历事件子集。

setQuery() 部分中的 reference guide for Zend_Gdata_Books 表明 Zend 应该可以做到这一点:

请注意,参数值中的任何空格、引号或其他标点符号都必须进行 URL 转义(使用加号 (+) 表示空格)。要搜索确切的短语,请将短语括在引号中。例如,要搜索匹配短语“间谍飞机”的书籍,请将q 参数设置为%22spy+plane%22

据我所知,Zend_Gdata_BooksZend_Gdata_Calendar 扩展了相同的 setQuery() 函数,所以我认为它们在 Zend 端是等价的。

对于 Google,Calendar query parameters reference 表示日历 API 支持标准数据 API 查询参数,这反过来又表示全文查询字符串 q 支持不区分大小写的精确短语搜索,正如 Zend_Gdata_Books 所表明的那样.

这些方法我都试过了:

$gCal = new Zend_Gdata_Calendar();
$query = $gCal->newEventQuery();

$query->setQuery("%22event+text%22"); //no results
$query->setQuery("%22event%20text%22"); //no results
$query->setQuery("\"event text\""); //too many results
$query->setQuery('"event text"'); //too many results
$query->setQuery("event text"); //too many results

我意识到前两个不起作用,因为字符串被双重 URL 编码。在后一种情况下,我得到了我想要的事件,但也得到了我不想要的事件,包括“事件”或“文本”。

会不会是 Google 为 Calendar API 实现了不同的全文查询?我可能会做哪些愚蠢的事情来打破它?

【问题讨论】:

    标签: php zend-framework google-calendar-api google-data-api zend-gdata


    【解决方案1】:

    看来你想试试$query->setQuery('"event text"');
    产生Query string(19) "?q=%22event+text%22"
    的查询字符串 $query->setQuery("event text");
    产生Query string(13) "?q=event+text"的查询字符串

    我用过:

    $gCal = new Zend_Gdata_Calendar();
            $query = $gCal->newEventQuery();
            $query->setQuery("event text");
            Zend_Debug::dump($query->getQueryString(), 'Query');
    

    进行测试。

    【讨论】:

    • 非常感谢 - 我没有意识到我可以检查查询字符串(我是 Zend 的新手)。看起来'"event text"'"/"event text/"" 都在生成我想要的查询字符串,但是在这两种情况下我仍然收到太多事件(包括eventtext 本身的事件)——几乎就像谷歌在搜索之前丢弃引号。