Article From:

JavaOpen source fresh business platform – search module design and Architecture (source code can be downloaded)

Explanation: the search module is aimed at a buyer’s user, looking for a kind of query which is very laborious when looking for dishes. It is also a fast search commodity at the moment.

           For the APP buyers of mobile terminals, the speed of requests is within 3 seconds. It supports fuzzy queries, because the actual search frequency is less than 18%-25%.

          At the same time, the business is not very large, so the Java full text search technology is not adopted. (Lucene, etc.) What is used here is the basic fuzzy query.


1. The search dimension is thinking.

             1.1  The content of the buyer is likely to be aimed at the properties of the dishes, so the contents include the name of the commodity, the name of the commodity, the label of the goods, the description of the goods, the name of the specification, the processing method and so on.

             1.2  We know that fuzzy search results in invalidation of the index and the performance of the entire query is also affected.

             1.3 The business form shows that some hot words and contents can be used for JVM caching to improve the purchase rate of the entire single item. For example, potatoes now analyze a lot of people, if we can talk with a businessman, one day.

You need 10W kg of potatoes to supply, so the default display of this keyword will appear on the whole page. This is the flexible configuration of the back end.


2. For the keyword that the buyer searches, we need the database to record, so we can figure out what the buyer will need from the system level, and can carry on the targeted marketing.


The design of the related database table is as follows:

CREATE TABLE `buyer_search` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatic increase of ID',
  `buyer_id` bigint(20) DEFAULT NULL COMMENT 'Buyer ID',
  `words` bigint(20) DEFAULT NULL COMMENT 'Seller ID',
  `create_time` datetime DEFAULT NULL COMMENT 'Create time ',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='The buyer's search record table ';

Explanation: the purpose is very clear, that is, to record buyers’ search keywords for analysis and research. In order to better experience the user.


The related business code is as follows:

     * APPFull text search new*@param request
     * @param response
     * @param keyword
     * @return
    @RequestMapping(value = "/search/new", method = { RequestMethod.GET, RequestMethod.POST })
    public JsonResult newSearchGoods(HttpServletRequest request, HttpServletResponse response,Long userId,Long regionId,String keyword){
  " content: "+ keyword);
            //Search results are displayed by the merchant//List<SellerVo> list = sellerService.searchSeller(regionId,keyword);
            //Search results are displayed according to goods
            List<NewSearchVo> list = goodsService.newSearchGoods(userId,regionId,keyword);
            return new JsonResult(JsonResultCode.SUCCESS, "Query information success ", list);
        }catch(Exception ex){
            logger.error("[SearchController][newSearchGoods] exception :",ex);
            return new JsonResult(JsonResultCode.FAILURE, "System error, please retry "," ");


VOThe objects are as follows:

 * Search and display classes (APP global search)*/
public class NewSearchVo implements Serializable{

    private static final long serialVersionUID = 1L;
     * ID from users*/
    private Long sellerId;

     * Shop name*/
    private String sellerName;
     * Shop alias, can be understood for short*/
    private String sellerAlias;
     * Shop logo*/
    private String sellerLogo;
     * Store rating, the default is 0*/
    private int sellerRank;
     * Store score*/
    private Double sellerGrade;
     * Post search list of goods*/
    private List<GoodsVo> searchItemList;

    public Long getSellerId() {
        return sellerId;

    public void setSellerId(Long sellerId) {
        this.sellerId = sellerId;

    public String getSellerName() {
        return sellerName;

    public void setSellerName(String sellerName) {
        this.sellerName = sellerName;

    public String getSellerAlias() {
        return sellerAlias;

    public void setSellerAlias(String sellerAlias) {
        this.sellerAlias = sellerAlias;

    public String getSellerLogo() {
        return sellerLogo;

    public void setSellerLogo(String sellerLogo) {
        this.sellerLogo = sellerLogo;

    public int getSellerRank() {
        return sellerRank;

    public void setSellerRank(int sellerRank) {
        this.sellerRank = sellerRank;

    public Double getSellerGrade() {
        return sellerGrade;

    public void setSellerGrade(Double sellerGrade) {
        this.sellerGrade = sellerGrade;

    public List<GoodsVo> getSearchItemList() {
        return searchItemList;

    public void setSearchItemList(List<GoodsVo> searchItemList) {
        this.searchItemList = searchItemList;


3, Data query performance temporarily meet the basic requirements, also posted to everyone together for reference, the purpose is to study and think together.


    <!-- Global search for new -->< select id= "newSearchGoods" resultMap= "newSearchResult" >< incluDe refid= "newSearchSelect" />< include refid= "newSearchFrom" />< includeRefid= "searchWhere" /><if test=" keyword != null">
            and (g.goods_name like concat('%',#{keyword},'%')
            or g.goods_as like concat('%',#{keyword},'%')
            or g.goods_label like concat('%',#{keyword},'%')
            or g.goods_brand like concat('%',#{keyword},'%')
            or g.goods_desc like concat('%',#{keyword},'%') 
            or gf.format_name like concat('%',#{keyword},'%') 
            or pm.method_name like concat('%',#{keyword},'%') 
            or s.seller_name like concat('%',#{keyword},'%') 
            or exists(select 1 from category where category_id = g.category_id and category_name like concat('%',#{keyword},'%') )
        <include refid="searchOrderBy" />


Summary, because the search business involved is relatively small, the function is relatively simple, the gold content is not very high, so learn from each other.


For the extension scheme, if the business is found very large, we can use Chinese word segmentation records, data mining, a separation of cold hot data, and so on.


The related business operation screenshots are as follows:



JavaOpen source fresh business platform – search module design and Architecture (source code can be downloaded), if you need to download, you can download it under my GitHub. 

Leave a Reply

Your email address will not be published. Required fields are marked *