Huawei Search Kit

Neha Jeswani
4 min readNov 20, 2020

--

Introduction

Search!! It’s a sought-after word through the entire software evolution and industry.

What is searching?

Searching is a process of locating a particular element present in a given set of elements. The element may be a record, a table, or a file or a keyword.

What is Search Engine?

A program that searches for and identifies items in a database that correspond to keywords or characters specified by the user, used especially for finding particular sites on the World Wide Web.

Archie” was the first search engine and it was introduced in 1990 by Alan Entage.

In today’s technical era, search engines has been drastically evolved and it is not limited to only big systems and laptops, their reach is now on your small mobile phone as well.

In fact, you can create your own search engine to have the upper hand on your business in this competitive era.

Huawei Search Kit offers API’s to build your own search platform in Android environment

Huawei Search Kit leverage developers to use the Petal Search capabilities by providing the device-side SDK and cloud side API’s to efficiently enable the search operation on the mobile app.

Note: Petal Search is a mobile search engine of Huawei powered by such cutting-edge technologies as big data, AI, and NLP.

In a typical scenario, any search engine works on the same principles shown in following image.

Huawei Search Kit uses the Petal Search engine capabilities in similar fashion by feeding the URL’s to engine’s scheduler which further do the parsing and indexing using Petal search and provide the search results which can be handled the mobile application.

Advantages

1. Speedy application development

2. Efficient search response

3. Cost effective

Note: Huawei Search Kit provides Client and Server side API’s to implement the search platform for your websites.

Responsibilities

To develop end to end solution and implement your own mobile search engine application, following would be your responsibilities:

1. Sites/Websites needs to be developed and maintained by the developers.

2. Receiving and handling the search queries from the end users and transporting them to Huawei for further search operation.

3. Developers are responsible to handle all the communication, modification or removal of the search queries raised by user regarding your website.

4. All the queries sent from your website to the Huawei search kit/engine shall comply all the technical guidelines provided by Huawei.

Development Overview

Prerequisite

1. Must have a Huawei Developer Account

2. Must have Android Studio 3.0 or later

3. Must have a Huawei phone with HMS Core 4.0.2.300 or later

4. EMUI 3.0 or later

Software Requirements

1. Java SDK 1.7 or later

2. Android 5.0 or later

Preparation

1. Create an app or project in the Huawei App Gallery Connect.

2. Provide the SHA Key and App Package name of the project in App Information Section and enable the ML Kit API.

3. Download the agconnect-services.json file.

4. Create an Android project.

Integration

  1. Add below to build.gradle (project)file, under buildscript/repositories and allprojects/repositories.

2. Add below to build.gradle (app) file, under dependencies to use the search kit SDK.

Tip: Minimum android version supported by Search kit is 24.

Configuring Network Permissions

To allow HTTP network requests on devices with target version 28 or later, configure the following information in the AndroidManifest.xml file:

android:usesCleartextTraffic=”true”>

Development Process

This article focuses on demonstrating the capabilities of Huawei Search Kit using device side SDK and API’s only.

We will understand the server/website configuration and Search Kit capabilities in next article.

Use Case: The application developed and explained is a very simple mobile search application to web search the products on a associated application.

This article explains client side search capabilities by implementing a mobile search application which only uses the web search API’s and return the search results from the website.

Client Side Development

Initializing Search Kit

You can call SearchKitInstance.init() in an Activity to initialize the SDK.

Search Activity

Search activity is responsible for:

1>Creating WebSearchRequest() for custom search

2> Setting request token for the calling the search results through website

setInstanceCredential() is used to set a global token, which is accessible to all methods. The token is used to verify a search request on the server. Search results of the request are returned only after the verification is successful.

3> Setting request token for web search

4> Start a web page search

webSearchRequest() is used as parameter which was constructed in Step 1 to the search method.

Complete Code

Tips & Tricks

The parameter in the setQ method of WebSearchRequest cannot be empty or exceed or exceed 1024 characters. (If the parameter passed exceeds 1024 characters, only the first 1024 characters will be used.) Otherwise, the search fails.

Results

Reference

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001055591730

Conclusion

This article focuses on web search for mobile application which query the website and demonstrate the client side API’s to initiate the search process, communicate with Huawei search API’s, customize the query and handle the results on the mobile application sent through the website.

--

--

Responses (1)