Mini programs

更新时间:
复制 MD 格式

WeChat's built-in search works for basic lookups, but it cannot handle the query complexity that E-commerce and content apps demand. This page explains the limitations of native WeChat search, describes the scenarios where those limitations matter most, and shows how to connect a mini program to OpenSearch.

Background

WeChat provides the SearchBar plug-in as the frontend search component. The backend supports two search modes: mini-program search and cloud-based development.

Mini-program search

Mini-program search exposes three API operations:

OperationDescription
search.imageSearchSearches for commodity images on a mini-program website
search.siteSearchSearches a specific website
search.submitPagesSubmits a page's URL and parameters to WeChat for early indexing
These operations cannot search for commodities or text.

Cloud-based development

Cloud-based development lets you build mini programs and mini games in WeChat without managing servers. It provides full support for cloud-native services and WeChat services, reduces backend and O&M processes, and allows you to use cloud functions and cloud databases, store data, and call cloud operations. Searches run against cloud databases and support:

  • Fuzzy match using regular expressions

  • Basic aggregation operations

  • Geographical location-based searches

  • Multi-field fuzzy matches

Search performance and effect are limited. Analysis and query analysis are not supported.

Why native search falls short

For query intent-based scenarios — E-commerce and content apps in particular — the native search capabilities cannot meet business requirements, which leads to poor search results and lower conversion rates.

E-commerce search characteristics

E-commerce search has five properties that the native engine cannot handle well:

  • Low input efficiency. Users type short, ambiguous queries.

  • High commercial stakes. Search quality directly affects conversion rates.

  • Keyword stacking. A single query like "Pampers Boy Large-size Diaper Delivery-free" contains multiple weighted terms with varying priority.

  • Order-insensitive semantics. Rearranging keywords rarely changes what the user means.

  • Complex category prediction. A query like "Apple" could mean fruit or a phone brand, and the engine must predict the correct category.

Content industry search characteristics

Content apps face a different set of challenges:

  • Long-tail, colloquial queries. Users phrase searches conversationally and inconsistently — for example, "Science fictions suitable for boys to read."

  • Multi-channel aggregation. Results come from multiple content sources simultaneously.

  • Semantic understanding. The engine must grasp intent, not just keywords.

  • Domain-specific precision. Queries like "How to deal with the expectoration of a baby less than three" require results with high domain relevance.

OpenSearch solutions

OpenSearch addresses these gaps with the following capabilities:

Connect a mini program to OpenSearch

Connecting a mini program to OpenSearch follows the same pattern as connecting a web app, with WeChat-specific code conventions for the API call.

Step 1: Set up a data source

Purchase an ApsaraDB RDS or PolarDB instance in Alibaba Cloud, then connect it to your OpenSearch application. Alternatively, push data using the OpenSearch API or SDK.

Step 2: Configure your OpenSearch application

In the OpenSearch console, purchase an application and configure it for your mini program.

Step 3: Call the OpenSearch API from the mini program

Use JavaScript to call external API operations from the mini program. You can use Elasticsearch, Solr, or a third-party cloud service to connect to OpenSearch.

The following example shows the structure of a wx.request call to your backend service, which in turn queries OpenSearch:

wx.request({
  url: '',
  data: {
    SercherValue: that.data.inputValue,
    SercherTypeNum: that.data.SercherTypeNum,
    typeItem: that.data.typeItem
  },
  header: {},
  method: '',
  dataType: '',
  success: function(res) {},
  fail: function(res) {},
  complete: function(res) {}
})