parse-platform - 将 Parse 类导入到 algolia

标签 parse-platform algolia

我正在尝试将我的类(2500 条记录)从 Parse.com 导入到 Algolia 索引中。默认情况下有 100 条记录的限制,这显然对我不起作用。即使我使用 query.limit = 1000;
下面的代码如何用于导入我的整个类(class)?

Parse.Cloud.define("createIndex", function(request, response) {

var algoliasearch = require('cloud/algoliasearch.parse.js');
var client = algoliasearch('9PsdfsdWVU7', '3b24e897bfb4esdfsdfsdf209e25c28');
var index = client.initIndex('exercises');

console.log("running");

var objectsToIndex = [];

//Create a new query for Contacts
var query = new Parse.Query('Exercises');

query.limit = 1000;
// Find all items
query.find({
    success: function(exercises) {
        // prepare objects to index from contacts
        objectsToIndex = exercises.map(function(exercise) {
            // convert to regular key/value JavaScript object
            exercise = exercise.toJSON();

            // Specify Algolia's objectID with the Parse.Object unique ID
            exercise.objectID = exercise.objectId;

            return exercise;
        });

        // Add or update new objects
        index.saveObjects(objectsToIndex, function(err, content) {
            if (err) {
                throw err;
            }

            console.log('Parse<>Algolia import done');
        });
        response.success("worked");
    },
    error: function(err) {
        response.error("failed");
        throw err;
    }
});

});

最佳答案

Parse.com 有一个查找限制,当您想“获取所有对象”时,还有所有其他限制,您可以在此处找到更多信息:https://parse.com/docs/js/guide#performance-limits-and-other-considerations

对于您当前的问题,您可以这样做:

Parse.Cloud.define("createIndex", function(request, response) {
    var algoliasearch = require('cloud/algoliasearch.parse.js');
    var client = algoliasearch('9PsdfsdWVU7', '3b24e897bfb4esdfsdfsdf209e25c28');
    var index = client.initIndex('exercises');

    console.log("running");

    //Create a new query for Contacts
    var Exercises = Parse.Object.extend('Exercises');
    var query = new Parse.Query(Exercises);
    var skip = -1000;
    var limit = 1000;

    saveItems();

    function saveItems() {
        skip += limit;
        query.skip(skip + limit);
        query.limit(limit);
        query.find({success: sucess, error: error});
    }

    function sucess(exercices) {
        if (exercices.length === 0) {
            response.success("finished");
            return;
        }


        exercises = exercises.map(function(exercise) {
            // convert to regular key/value JavaScript object
            exercise = exercise.toJSON();

            // Specify Algolia's objectID with the Parse.Object unique ID
            exercise.objectID = exercise.objectId;

            return exercise;
        });

        index.saveObjects(exercises, function(err) {
            if (err) {
                throw err;
            }

            console.log('Parse<>Algolia import done');
            response.success("worked");
            saveItems();
        });

    }

    function error() {
        response.error("failed");
        throw err;
    }
});

关于parse-platform - 将 Parse 类导入到 algolia,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33660918/

相关文章:

ios - 如何将 UIImages 添加到我的 PFFile 数组中,以便在查询 PFFIle 图像失败时,可以通过附加 UIImage 来替换它?

Algolia 实时 Webhooks

search - 仅当包含突出显示的匹配项时才在搜索结果模板中显示属性

javascript - Algolia:使用 AND 子句在每个字段中搜索多个值

ios - 解析本地数据存储性能

android - 使用android在Parse中插入多个数据

ios - 在哪里可以找到 Parse 保存的数据?

java - Parse.com 使用 java 创建 objectId

algolia - 我可以使用数字过滤器进行 OR 地理搜索吗?

android - 如何在带有 Firebase 内容的 Android 中使用 Algolia