Structured Information Search API

更新时间:
复制 MD 格式

Common parameters

Request parameters

Field

Type

Description

Default value

serviceId

long

The service ID.

101

uq

string

The search value entered by the user.

type

string

The search type.

Dynamic adaptation

queries

List<map<string, object>>

The search conditions.

[]

filters

List<map<string, object>>

The filter conditions.

[]

fields

array

The fields to retrieve (forward index).

[]

page

int

The page number for paging.

1

rows

int

The number of rows per page for paging.

10

customConfigInfo

map<string, object>

The custom intervention configuration.

{}

debug

boolean

The debugging information.

Description of the type field

A comma-separated list of fields to match against the search value.

Example: "index1,index2,index3"

Description of the queries and filter fields

Specifies the search conditions that are combined with the uq parameter. The queries conditions are used to calculate the final score. The filters conditions only filter the search results.

  • By default, subgroups are combined using the AND logical operator.

    • Fields within a subgroup support the _operator=AND/OR logical operator. The default is AND. The operator is case-insensitive.

    • Fields within a subgroup support nested sub-conditions using _conditions=[]. The logical relationship between sub-conditions inherits the _operator from the parent group by default. You can also customize this relationship using _conditions_operator=AND/OR. For more information about how to use sub-conditions, see the queries parameter.

  • Fields within a subgroup support single-value, multi-value, and range queries.

    • Single value: A number or a string.

    • Multi-value: An array of numbers or strings.

    • Relational properties: Supports the eq, neq, and like properties. You cannot configure more than one property for a field. The properties are case-insensitive.

    • Range properties: Supports the gt, gte, lt, and lte properties. The values must be numeric. The properties are case-insensitive.

Example

{
    "queries":[
        {
            "singleQuery": "stringValue",                   // Single-value query
            "multiQuery": ["stringValue1", "stringValue2"], // Multi-value query
            "logicQuery": {                                 // Logical query
                "like": "prefix"
            },
            "rangeQuery": {                                 // Range query
                "gte": intValue,
                "lte": intValue
            },
            "_conditions": [                                // Nested subquery conditions
                {
                    "singleQuery": intValue
                }
            ]
        },
        {
            "_operator": "OR", 				    // Multi-condition OR query (auto-generated by SDK)
            "singleQuery": "stringValue"
        }
    ]
}

Description of the customConfigInfo field

Specifies the custom intervention configuration. You do not need to configure this parameter if you define custom query conditions in the queries parameter. If you want to use the query syntax generated by the algorithm, you must pass the Query Strategy Perception (QSP)-related parameters.

Field

Type

Description

qsp

bool

Specifies whether to enable the QSP service.

qspSchema

List<map<string, object>>

The description of the index fields that the algorithm depends on to generate queries.

Description of the qspSchema field

The qspSchema field is a List<map<string, object>>. Each map describes the fields that the algorithm requires to build the query conditions.

Field

Type

Description

name

string

The name of the index field.

type

string

The type of the index field.

desc

string

A short description of the index field, up to 10 characters long.

The type field corresponds to the engine used for the structured information search. Only types that are supported by the engine are allowed.

Response parameters

Field

Type

Description

Default value

requestId

string

The request ID.

xxxx

status

int

The status of the request result.

0

message

string

The response message.

data.total

int

The total number of search results.

0

data.docs

array(map/dict/json)

The search results.

[]

debug

map<string, object>

The debugging information.

HTTP calls

Obtain an authentication token

You can obtain an authentication token by calling the PostMSConvSearchTokenGenerated operation in the POP software development kit (SDK). After you obtain the token, add the Bearer prefix and include the token in the Authorization header.

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>alinlp20200629</artifactId>
  <version>2.7.2</version>
</dependency>

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.6.0</version>
</dependency>
    public static void main(String[] args) throws Exception {
        Config config = new Config();
        config.setEndpoint("alinlp.cn-beijing.aliyuncs.com");
        config.setAccessKeyId("xxxx");
        config.setAccessKeySecret("xxxx");
        Client client = new Client(config);
        PostMSConvSearchTokenGeneratedResponse response = client.postMSConvSearchTokenGenerated();
        System.out.println(JacksonUtils.toJson(response));
    }
{
  "body" : {
    "code" : 200,
    "data" : "OQ25BJFGnMhUJ8NWpATLfcf2VW820vzGbXP5Us/qGdtwn338qSOLwkzyCnbmBD+t7AboAuvYzp5pujlKXfy90KSAnQVVVb/v15w7K+BkozM=",
    "httpStatusCode" : 200,
    "requestId" : "184B7122-B9EF-14BC-B974-7D013A601FE8",
    "success" : true
  },
  "headers" : {
    "access-control-allow-origin" : "*",
    "access-control-expose-headers" : "*",
    "connection" : "keep-alive",
    "content-length" : "217",
    "content-type" : "application/json;charset=utf-8",
    "date" : "Tue, 02 Jan 2024 07:32:08 GMT",
    "etag" : "2khQ+DZUrns9GU5hL39GwUQ7",
    "keep-alive" : "timeout=25",
    "x-acs-request-id" : "184B7122-B9EF-14BC-B974-7D013A601FE8",
    "x-acs-trace-id" : "ec5e93d7765a4df394f82da31c6a729e"
  },
  "statusCode" : 200
}

HTTP request

Request parameters

Field

Type

Description

Default value

headers

map/dict/json

The request header information.

{}

Authorization

string

The authentication information.

Bearer toY1FWrNAjvWkOmp24+UQFIi2PsYzbhNBq+yJmzumNmXw3sro3oOt9Kde5kzLcc4

Endpoint

https://nlp.aliyuncs.com

URL

https://nlp.aliyuncs.com/msearch/api/searchEnhance

 curl -i -X POST \
   -H "Content-Type:application/json" \
   -H "Authorization:Bearer OQ25BJFGnMhUJ8NWpATLfcf2VW820vzGbXP5Us/qGdtwn338qSOLwkzyCnbmBD+t7AboAuvYzp5pujlKXfy90KSAnQVVVb/v15w7K+BkozM=" \
   -d \
'{
    "uq": "ECS console: A web service page with interactive operations",
    "type": "title,content,keywords",
    "serviceId":23,
    "page": 1,
    "rows": 5
}' \
 'https://nlp.aliyuncs.com/msearch/api/searchEnhance'
{
    "requestId": null,
    "data": {
        "total": 3,
        "docs": [
            {
                "_rc_score": 19.05915,
                "keywords": "",
                "b_id": "25367",
                "gmt_modified_origin": "2022-09-26 18:26:12",
                "_q_score": 1.0,
                "id": 0,
                "_id": "0",
                "title": "What is Elastic Computing Service (ECS)",
                "_score": 19.05915,
                "content":"Elastic Computing Service (ECS) is a high-performance, stable, reliable, and scalable Infrastructure as a Service (IaaS) level cloud computing service provided by Alibaba Cloud." 
            },
            {
                "_rc_score": 10.70154,
                "keywords": "Developer Guide",
                "b_id": "42431",
                "gmt_modified_origin": "2023-01-06 11:07:33",
                "_q_score": 0.5614909374237571,
                "id": 37,
                "_id": "37",
                "title": "Configure an accelerated domain name",
                "_score": 10.70154,
                "content": "The ApsaraVideo Media Processing service supports distribution acceleration, which can accelerate resource access for services on specified websites. If you require acceleration, we recommend that you use the website that needs acceleration as the origin server and create an accelerated domain name for it."
            },
            {
                "_rc_score": 8.819408,
                "keywords": "User Guide",
                "b_id": "59977",
                "gmt_modified_origin": "2023-02-15 09:42:23",
                "_q_score": 0.4627387895053032,
                "id": 89,
                "_id": "89",
                "title": "Overview of burstable instances",
                "_score": 8.819408,
                "content": "Burstable instances are an economy instance type designed for entry-level computing scenarios with burstable performance requirements. This topic describes the features and scenarios of the burstable instance family, concepts such as baseline performance, CPU credits, and performance modes, and lists the specific instance types."
            }
        ]
    },
    "status": 0,
    "debug": null,
    "message": null
}

SDK calls

Java SDK

Maven dependencies

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>alinlp20200629</artifactId>
  <version>2.7.2</version>
</dependency>

<!--If a java.lang.NoSuchMethodError: com.aliyun.credentials.Client.getCredential()Lcom/aliyun/credentials/models/CredentialModel; exception occurs, add this dependency.-->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>credentials-java</artifactId>
    <version>0.3.0</version>
</dependency>

Java sample code

public static void main(String[] args) throws Exception {
        Config config = new Config();
        config.setEndpoint("alinlp.cn-beijing.aliyuncs.com");
        config.setAccessKeyId("xxxx");
        config.setAccessKeySecret("xxxx");
        Client client = new Client(config);
        PostMSSearchEnhanceRequest postMSSearchEnhanceRequest = new PostMSSearchEnhanceRequest();
        postMSSearchEnhanceRequest.setServiceId(1555L);
        postMSSearchEnhanceRequest.setUq("Alibaba Cloud");
        postMSSearchEnhanceRequest.setPage(1);
        postMSSearchEnhanceRequest.setRows(5);
        postMSSearchEnhanceRequest.setType("name,title,content");
        postMSSearchEnhanceRequest.setFields(Lists.newArrayList("name","title", "content"));
        // The runtime parameter timeout settings are effective only for requests that use this runtime parameter instance.
        RuntimeOptions runtimeOptions = new RuntimeOptions();
        runtimeOptions.connectTimeout = 5000;
        runtimeOptions.readTimeout = 10000;
        PostMSSearchEnhanceResponse response = client.postMSSearchEnhanceWithOptions(postMSSearchEnhanceRequest, runtimeOptions);
        System.out.println(JacksonUtils.toJson(response));
    }

Sample response:
{
  "body" : {
    "code" : 200,
    "data" : {
      "data" : {
        "docs" : [
          {
            "_id" : "3459649677041723584_2",
            "_q_score" : 1,
            "_rc_score" : 11.952197,
            "_score" : 11.952197,
            "content" : " • This document is for reference only for your use of Alibaba Cloud products and services. Alibaba Cloud provides this document on an \"as is\", \"with all faults\", and \"as available\" basis. Alibaba Cloud makes every effort to provide relevant introductions and operational guidance based on existing technology. However, Alibaba Cloud expressly disclaims all warranties, express or implied, regarding the accuracy, completeness, applicability, and reliability of the content of this document. Alibaba Cloud is not liable for any legal responsibility for any errors or economic losses incurred by any entity, company, or individual from downloading, using, or relying on this document. Under no circumstances will Alibaba Cloud be liable for any indirect, consequential, exemplary, incidental, special, or punitive damages, including loss of profits suffered by users from using or relying on this document (even if Alibaba Cloud has been advised of the possibility of such losses). • All content on the Alibaba Cloud website, including but not limited to works, products, images, archives, information, materials, website architecture, website screen arrangement, and web page design, is legally owned by Alibaba Cloud and/or its affiliates, including but not limited to trademark rights, patent rights, copyrights, and trade secrets. Without the written consent of Alibaba Cloud and/or its affiliates, no one may use, modify, copy, publicly disseminate, alter, distribute, issue, or publicly publish the Alibaba Cloud website, product programs, or content.",
            "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
            "title" : ""
          },
          {
            "_id" : "3459649677041723584_3",
            "_q_score" : 0.98918508454972753,
            "_rc_score" : 11.822934999999999,
            "_score" : 11.822934999999999,
            "content" : "Without the written consent of Alibaba Cloud and/or its affiliates, no one may use, modify, copy, publicly disseminate, alter, distribute, issue, or publicly publish the Alibaba Cloud website, product programs, or content. In addition, without the prior written consent of Alibaba Cloud, no one may use, publish, or copy the name of Alibaba Cloud for any marketing, advertising, promotional, or other purposes (including but not limited to using 'Alibaba Cloud', 'Aliyun', 'HiChina', etc., brands of Alibaba Cloud and/or its affiliates, alone or in combination, along with their subsidiary logos and patterns, or any similar company names, trade names, trademarks, product or service names, domain names, graphic marks, logos, identifiers, or through specific descriptions that enable third parties to identify Alibaba Cloud and/or its affiliates). • If you find any errors in this document, please contact Alibaba Cloud.",
            "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
            "title" : ""
          },
          {
            "_id" : "3459649677041723584_4",
            "_q_score" : 0.96916625453880978,
            "_rc_score" : 11.583665999999999,
            "_score" : 11.583665999999999,
            "content" : " Alibaba Cloud OCR Alibaba Cloud OCR/Table of Contents Document Version: 20230509 3 Table of Contents Legal Disclaimer.................................................................................................................................................................................... 2 Table of Contents 3 Foreword 4 Overview................................................................................................................................................................................................................4",
            "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
            "title" : ""
          },
          {
            "_id" : "3459649677041723584_73",
            "_q_score" : 0.96650933715366305,
            "_rc_score" : 11.551909999999999,
            "_score" : 11.551909999999999,
            "content" : "Supports mixed detection and recognition of cards, certificates, and bills within the same file or image. It enables automatic classification, accurate recognition of key information, and structured extraction in scenarios such as mixed financial bills and personal documents. This greatly enhances the technical efficiency of OCR capabilities in financial automation, office automation, and various industry applications. Alibaba Cloud OCR Alibaba Cloud OCR/Product Features Document Version: 20230509 30 Alibaba Cloud OCR Alibaba Cloud OCR/Product Specifications Document Version: 20230509 31 3. Product Specifications",
            "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
            "title" : "Waybill Recognition ii. Mixed Bill Recognition"
          },
          {
            "_id" : "3459649677041723584_42",
            "_q_score" : 0.93509536363900292,
            "_rc_score" : 11.176444,
            "_score" : 11.176444,
            "content" : "Accurately recognizes key information in a bank account opening permit, such as the account number, approval number, company name, legal representative's name, and opening bank. Alibaba Cloud OCR Alibaba Cloud OCR/Product Features Document Version: 20230509 15",
            "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
            "title" : "Bank Account Opening Permit Recognition"
          }
        ],
        "total" : 108
      },
      "requestId" : "F861AC34-7F30-15A6-AE92-FD788525036F",
      "status" : 0
    },
    "httpStatusCode" : 200,
    "requestId" : "F861AC34-7F30-15A6-AE92-FD788525036F",
    "success" : true
  },
  "headers" : {
    "access-control-allow-origin" : "*",
    "access-control-expose-headers" : "*",
    "connection" : "keep-alive",
    "content-type" : "application/json;charset=utf-8",
    "date" : "Tue, 02 Jan 2024 07:18:54 GMT",
    "keep-alive" : "timeout=25",
    "transfer-encoding" : "chunked",
    "vary" : "Accept-Encoding",
    "x-acs-request-id" : "F861AC34-7F30-15A6-AE92-FD788525036F",
    "x-acs-trace-id" : "e6e485a286ccb89ce0008022f62682c9"
  },
  "statusCode" : 200
}

Python SDK

pip source

PyPI

pip install alibabacloud_alinlp20200629==2.8.2

Python sample code

import json

from alibabacloud_alinlp20200629 import client
from alibabacloud_tea_openapi import models as api_models
from alibabacloud_tea_util.models import RuntimeOptions
from alibabacloud_alinlp20200629 import models
import os


def searchEnhance():
    config = api_models.Config(access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                               access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
                               region_id="cn-beijing")
    nlp_client = client.Client(config)
    request = models.PostMSSearchEnhanceRequest()
    request.service_id = 1555
    request.uq = 'Alibaba Cloud'
    request.page = 1
    request.rows = 5
    request.type = "name,title,content"
    runtime_options = RuntimeOptions(connect_timeout=5000, read_timeout=10000)
    response = nlp_client.post_mssearch_enhance_with_options(request, runtime_options)
    # For Python 2: print(response)
    print(json.dumps(response.body.data, ensure_ascii=False))
{
  "data" : {
    "docs" : [
      {
        "_id" : "3459649677041723584_2",
        "_q_score" : 1,
        "_rc_score" : 11.952197,
        "_score" : 11.952197,
        "chunkId" : "3459649677041723584_2",
        "content" : " • This document is for reference only for your use of Alibaba Cloud products and services. Alibaba Cloud provides this document on an \"as is\", \"with all faults\", and \"as available\" basis. Alibaba Cloud makes every effort to provide relevant introductions and operational guidance based on existing technology. However, Alibaba Cloud expressly disclaims all warranties, express or implied, regarding the accuracy, completeness, applicability, and reliability of the content of this document. Alibaba Cloud is not liable for any legal responsibility for any errors or economic losses incurred by any entity, company, or individual from downloading, using, or relying on this document. Under no circumstances will Alibaba Cloud be liable for any indirect, consequential, exemplary, incidental, special, or punitive damages, including loss of profits suffered by users from using or relying on this document (even if Alibaba Cloud has been advised of the possibility of such losses). • All content on the Alibaba Cloud website, including but not limited to works, products, images, archives, information, materials, website architecture, website screen arrangement, and web page design, is legally owned by Alibaba Cloud and/or its affiliates, including but not limited to trademark rights, patent rights, copyrights, and trade secrets. Without the written consent of Alibaba Cloud and/or its affiliates, no one may use, modify, copy, publicly disseminate, alter, distribute, issue, or publicly publish the Alibaba Cloud website, product programs, or content.",
        "docId" : "3459649677041723584",
        "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
        "title" : "",
        "url" : "oss://ossFile1/OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf"
      },
      {
        "_id" : "3459649677041723584_3",
        "_q_score" : 0.98918508454972753,
        "_rc_score" : 11.822934999999999,
        "_score" : 11.822934999999999,
        "chunkId" : "3459649677041723584_3",
        "content" : "Without the written consent of Alibaba Cloud and/or its affiliates, no one may use, modify, copy, publicly disseminate, alter, distribute, issue, or publicly publish the Alibaba Cloud website, product programs, or content. In addition, without the prior written consent of Alibaba Cloud, no one may use, publish, or copy the name of Alibaba Cloud for any marketing, advertising, promotional, or other purposes (including but not limited to using 'Alibaba Cloud', 'Aliyun', 'HiChina', etc., brands of Alibaba Cloud and/or its affiliates, alone or in combination, along with their subsidiary logos and patterns, or any similar company names, trade names, trademarks, product or service names, domain names, graphic marks, logos, identifiers, or through specific descriptions that enable third parties to identify Alibaba Cloud and/or its affiliates). • If you find any errors in this document, please contact Alibaba Cloud.",
        "docId" : "3459649677041723584",
        "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
        "title" : "",
        "url" : "oss://ossFile1/OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf"
      },
      {
        "_id" : "3459649677041723584_4",
        "_q_score" : 0.96916625453880978,
        "_rc_score" : 11.583665999999999,
        "_score" : 11.583665999999999,
        "chunkId" : "3459649677041723584_4",
        "content" : " Alibaba Cloud OCR Alibaba Cloud OCR/Table of Contents Document Version: 20230509 3 Table of Contents Legal Disclaimer.................................................................................................................................................................................... 2 Table of Contents 3 Foreword 4 Overview................................................................................................................................................................................................................4",
        "docId" : "3459649677041723584",
        "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
        "title" : "",
        "url" : "oss://ossFile1/OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf"
      },
      {
        "_id" : "3459649677041723584_73",
        "_q_score" : 0.96650933715366305,
        "_rc_score" : 11.551909999999999,
        "_score" : 11.551909999999999,
        "chunkId" : "3459649677041723584_73",
        "content" : "Supports mixed detection and recognition of cards, certificates, and bills within the same file or image. It enables automatic classification, accurate recognition of key information, and structured extraction in scenarios such as mixed financial bills and personal documents. This greatly enhances the technical efficiency of OCR capabilities in financial automation, office automation, and various industry applications. Alibaba Cloud OCR Alibaba Cloud OCR/Product Features Document Version: 20230509 30 Alibaba Cloud OCR Alibaba Cloud OCR/Product Specifications Document Version: 20230509 31 3. Product Specifications",
        "docId" : "3459649677041723584",
        "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
        "title" : "Waybill Recognition ii. Mixed Bill Recognition",
        "url" : "oss://ossFile1/OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf"
      },
      {
        "_id" : "3459649677041723584_42",
        "_q_score" : 0.93509536363900292,
        "_rc_score" : 11.176444,
        "_score" : 11.176444,
        "chunkId" : "3459649677041723584_42",
        "content" : "Accurately recognizes key information in a bank account opening permit, such as the account number, approval number, company name, legal representative's name, and opening bank. Alibaba Cloud OCR Alibaba Cloud OCR/Product Features Document Version: 20230509 15",
        "docId" : "3459649677041723584",
        "name" : "OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf",
        "title" : "Bank Account Opening Permit Recognition",
        "url" : "oss://ossFile1/OCR Basic Capabilities Product Whitepaper V1.91, for external use.pdf"
      }
    ],
    "total" : 108
  },
  "requestId" : "891CB7AB-5773-132F-B03D-589A3D2A6C7E",
  "status" : 0
}