azure - 如何通过 Java 以编程方式在 Azure 搜索中设置认知搜索功能(使用 OCR)?
问题描述
我想在我的应用程序中提供全文搜索功能,因此我正在尝试使用认知搜索功能配置 Azure 搜索,以便我可以索引存储在 Azure Blob 存储中的图像和非图像文档。但是,在使用 Azure 搜索的 REST API 通过 Java 代码配置 Azure 搜索时,我无法在 Azure 搜索中利用 OCR 功能,并且图像文档没有被索引。通过 Java 代码(使用 Azure 搜索 REST API)配置 Azure 搜索时,我遗漏了一些配置详细信息。
案例 1:从 Azure 门户,我能够
- 使用认知功能(包括 OCR 技能集)、索引、索引器和 Azure Blob 存储来配置 Azure 搜索。
- 索引图像和非图像文档,例如 pdf、png、jpg、xls 等。
- 搜索索引文档
案例 2:使用 Azure REST API 从 Java 代码中,我能够
- 使用认知功能、索引、索引器和 Azure Blob 存储配置 Azure 搜索。
- 索引非图像文档,例如 pdf、xls 等。
- 搜索索引文档但是,在使用 Azure 搜索的 REST API 通过 Java 代码配置 Azure 搜索时(在案例 2 中),我无法在 Azure 搜索中利用 OCR 功能,并且图像文档没有被索引。通过 Java 代码(使用 Azure 搜索 REST API)配置 Azure 搜索时,我遗漏了一些配置详细信息。
我正在使用 Java 代码 1 中的以下示例 Azure Search Rest API。https://%s.search.windows.net/datasources?api-version=%s 2.https ://%s.search.windows.net/技能集/cog-search-demo-ss?api-version=%s 3. https://%s.search.windows.net/indexes/%s?api-version=%s 4. https://%s .search.windows.net/indexers?api-version=%s
配置jsons:1.datasource.json
{
"name" : "csstoragetest",
"type" : "azureblob",
"credentials" : { "connectionString" : "connectionString" },
"container" : { "name" : "csblob" }
}
- 技能组.json
{
"description": "Extract text from images and merge with content text to produce merged_text",
"skills":
[
{
"description": "Extract text (plain and structured) from image.",
"@odata.type": "#Microsoft.Skills.Vision.OcrSkill",
"context": "/document/normalized_images/*",
"defaultLanguageCode": "null",
"detectOrientation": true,
"inputs": [
{
"name": "image",
"source": "/document/normalized_images/*"
}
],
"outputs": [
{
"name": "text",
"targetName": "myText"
},
{
"name": "layoutText",
"targetName": "myLayoutText"
}
]
},
{
"@odata.type": "#Microsoft.Skills.Text.MergeSkill",
"description": "Create merged_text, which includes all the textual representation of each image inserted at the right location in the content field.",
"context": "/document",
"insertPreTag": " ",
"insertPostTag": " ",
"inputs": [
{
"name":"text", "source": "/document/content"
},
{
"name": "itemsToInsert", "source": "/document/normalized_images/*/text"
},
{
"name":"offsets", "source": "/document/normalized_images/*/contentOffset"
}
],
"outputs": [
{
"name": "mergedText", "targetName" : "merged_text"
}
]
}
]
}
- 索引.json
{
"name": "azureblob-indexing",
"fields": [
{ "name": "id", "type": "Edm.String", "key": true, "searchable": false },
{ "name": "content", "type": "Edm.String", "searchable": true, "filterable": false, "sortable": false, "facetable": false }
]
}
- indexer.json
{
"name" : "azureblob-indexing1",
"dataSourceName" : "csstoragetest",
"targetIndexName" : "azureblob-indexing",
"schedule" : { "interval" : "PT2H" },
"skillsetName" : "cog-search-demo-ss",
"parameters":
{
"maxFailedItems":-1,
"maxFailedItemsPerBatch":-1,
"configuration":
{
"dataToExtract": "contentAndMetadata",
"imageAction":"generateNormalizedImages",
"parsingMode": "default",
"firstLineContainsHeaders": false,
"delimitedTextDelimiter": ","
}
}
}
通过 java 代码配置 Azure 搜索后,图像文档应该在 azure 搜索中建立索引,并且我应该能够根据其中包含的文本搜索它们。
解决方案
尝试将默认语言代码设置为 null ,而无需在Skillset.json中使用引号:
"defaultLanguageCode": null
推荐阅读
- python - 除了 numpy 数组,Python 从 long 转换
- excel - VBA Excel:从特定单元格中搜索某行的某个变量值然后将值复制并粘贴到该列的宏
- database - 在数组中查找 ObjectId
- angular - 如何使用 Angular 2+ 中的指令获取图像 src 值?
- cordova - Cordova/JQuery 移动应用程序在构建后无法正确显示页面
- oracle - 通过 dblink (Oracle <> Postgres) 查询 JSONB
- javascript - url上的回调函数?
- r - KNN 可视化 - 如何围绕使用 R 连接到 N 个最近点的数据点绘制一个圆圈
- reactjs - Reactjs 随机颜色选择器 - 哇一定有更简单的方法吗?
- sql - oracle sql - 如何从某些范围内获取具有最大值的记录