【问题标题】:Search in spreadsheets not working for new files created在电子表格中搜索不适用于创建的新文件
【发布时间】:2012-04-26 13:54:28
【问题描述】:

我使用文档列表 api 在 google docs 上创建了我的电子表格模板的副本,我意识到:

1. title queries works fine
2. content queries are not working(*) or partially working(**)
(*)for majority of spreadsheets: I searched every word from the content of a spreadsheet and I get no results
(**) for a few spreadsheets I find results for some words that are copied from template; the particular words queries are not working
3. If I update the spreadsheet after a few minutes all queries work fine.
(I make this searches from UI)

这是创建此文件的步骤:

1. Copy spreadsheet template to root

private String sendPostCopyRequest(String authorizationToken, String resourceID, String title, int noRetries) throws IOException{ 
    /*
    resourceId = resource id for the template that i want to copy
    title = the title of the new file created
    */      
    String urlStr = "https://docs.google.com/feeds/default/private/full";
    URL url = new URL(urlStr); 
    HttpURLConnection copyHttpUrlConn = (HttpURLConnection) url.openConnection(); 
    copyHttpUrlConn.setDoOutput(true); 
    copyHttpUrlConn.setRequestMethod("POST"); 

    String outputString = "<?xml version='1.0' encoding='UTF-8'?>" +
            "<entry xmlns=\"http://www.w3.org/2005/Atom\"> " +
            "<id>https://docs.google.com/feeds/default/private/full/" + resourceID +"</id>" +
            " <title>" + title + "</title></entry>";

    copyHttpUrlConn.setRequestProperty("GData-Version", "3.0");
    copyHttpUrlConn.setRequestProperty("Content-Type","application/atom+xml");

    copyHttpUrlConn.setRequestProperty("Content-Length", outputString.length() + "");
    copyHttpUrlConn.setRequestProperty("Authorization", "GoogleLogin auth=" + authorizationToken);

    OutputStream outputStream = copyHttpUrlConn.getOutputStream(); 

    outputStream.write(outputString.getBytes()); 
    copyHttpUrlConn.getResponseCode(); 

    return readIdFromResponse(copyHttpUrlConn.getInputStream()); 
}

2. I update some cells using this method:

public boolean setCellValue(SpreadsheetService spreadSheetService, SpreadsheetEntry entry, int worksheetNumber, String position, String value) throws IOException, ServiceException {

    List<WorksheetEntry> worksheets = entry.getWorksheets();
    WorksheetEntry worksheet = worksheets.get(worksheetNumber);
    URL cellFeedUrl = worksheet.getCellFeedUrl();
    CellQuery query = new CellQuery(cellFeedUrl);
    query.setReturnEmpty(true);
    query.setRange(position);
    CellFeed cellFeed = spreadSheetService.query(query, CellFeed.class);
    CellEntry cell = cellFeed.getEntries().get(0);

    cell.changeInputValueLocal(value);
    cell.update();
    return true;

}

3. I move the created file to a new folder (collection)

    public DocumentListEntry moveSpreadSheet(DocsService docsService, String entryId, String destinationFolderDocId) throws MalformedURLException, IOException, ServiceException {

    DocumentListEntry newEntry = null;
    newEntry = new com.google.gdata.data.docs.SpreadsheetEntry();
    newEntry.setId(entryId);
    String destFolderUri = "https://docs.google.com/feeds/default/private/full/folder%3A"+ destinationFolderDocId + "/contents";

    return docsService.insert(new URL(destFolderUri), newEntry);

}

(the same results with gdata java sdk api 1.4.5, 1.4.6, 1.4.7)

这发生在 2011 年 12 月 23 日(近似值)。对于在此日期之前使用相同代码创建的所有电子表格,所有查询都可以正常工作。

我可以根据要求提供任何其他信息。

更新:

  1. 这个问题似乎也出现在上传带有转换的电子表格时。
  2. 如果我在创建/上传一段时间后(约 2 小时)更新文件,查询会在结果中返回它们。

【问题讨论】:

  • 我和其他几个人报告说电子表格中的 GoogleDocs 搜索已损坏(Google 支持论坛,现在找不到链接)。一位 Google 员工确认旧文档没有被编入索引(AFAIK 由于某个时间点的错误),我们必须打开并编辑它们才能重新编入索引。但是,今天我发现电子表格中的搜索不适用于 8 天前创建的电子表格,所以我猜这个错误又出现了。我建议您搜索 Google 论坛,看看是否可以找到当前状态。
  • 我知道那个帖子,因为我也在那里报告过(这是链接 - link),但它是关于从 UI 创建的文件。我将在那里重新发布以通知他们(似乎对于从 UI 上传的新文件是同样的问题,但在单元格更新后工作正常)

标签: java google-app-engine google-docs google-docs-api google-spreadsheet-api


【解决方案1】:

您的问题可能与 Google 对电子表格内容的索引速度较慢有关。

https://groups.google.com/a/googleproductforums.com/d/msg/docs/vEhI_HkKX3I/MGKqkryrx90J

“目前,将您写入电子表格的内容编入索引可能需要大约 10 分钟。因此,如果您输入内容,然后立即搜索,它可能尚未显示在您的列表中记录结果。再等几分钟(我们正在努力加快速度)"

【讨论】:

  • 我的问题不是关于缓慢的 Google 索引...我说的是几个月前创建的文件(不是 10 分钟)
  • 建议的解决方法:编写一些代码来遍历所有电子表格,触摸一个单元格,然后保存。然后请与社区分享:-)
  • 我猜这行不通。我所有的电子表格都是使用以下步骤获得的:从模板复制,从中更新随机单元格。这意味着我已经按照你说的做了。我会努力做到这一点,如果我在创建后较长时间后更新它们,也许会起作用。我会带着结果回来
  • 它似乎可以工作,但仅适用于“旧文件”(大约 2 小时前 - 我没有进行太多测试)。我相信因为我的文档是通过更新单元格创建的,所以这不起作用。我将创建一个 cron 来更新在过去 X 小时内创建的电子表格,直到这个问题得到解决。感谢您的解决方法。
  • 欢迎您。不过,您不必这样做。这是 Google 急需修复的错误,但由于某种原因,它没有得到应有的重视。
猜你喜欢
  • 1970-01-01
  • 2018-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多