如何防止在搜索查询中返回某些值?

时间:2017-03-13 14:13:00

标签: algolia

如何阻止在搜索查询中返回某些值?

例如,我正在使用Algolia的地理查询功能,并希望阻止该位置被发送回客户端?

2 个答案:

答案 0 :(得分:1)

您可以指定 Unretrievable Attributes :此功能可让您选择与搜索结果一起 的记录信息。

例如JavaScript API Client

index.setSettings({
  unretrievableAttributes: ["_geoloc"]
})

答案 1 :(得分:1)

我有类似的问题。我联系了Algolia的支持,他们建议我删除在获得objectID后删除它所不想索引的任何属性:

function addOrUpdateIndexRecord(contact) {

    // Get Firebase object
    const record = contact.val();

    // Specify Algolia's objectID using the Firebase object key. ObjectID is obtained here
    record.objectID = contact.key;

    // Use this to delete the attributes you don't want indexed
    delete record.whateverNameOfTheFirstAttribute
    delete record.whateverNameOfTheSecondAttribute
    delete record.whateverNameOfTheThirdAttribute
    delete record.etcEtc

    // Add or update object
    index
      .saveObject(record)
      .then(() => {
        console.log('Firebase object indexed in Algolia', record.objectID);
      })
      .catch(error => {
        console.error('Error when indexing contact into Algolia', error);
        process.exit(1);
      });
    }
}