如何提高FTS的性能?

时间:2018-07-24 15:02:47

标签: node.js full-text-search couchbase bleve

我需要提高我的搜索性能的建议。现在写,我正在使用node.js和couchbase开发后端服务。我的索引定义如下:

{"name": "product_search",
 "type": "fulltext-index",
  "params": {
 "doc_config": {
   "docid_prefix_delim": "",
   "docid_regexp": "",
   "mode": "type_field",
   "type_field": "_type"
  },
  "mapping": {
   "default_analyzer": "standard",
   "default_datetime_parser": "dateTimeOptional",
   "default_field": "_all",
   "default_mapping": {
    "default_analyzer": "",
    "dynamic": true,
    "enabled": false 
},
   "default_type": "_default",
   "docvalues_dynamic": true,
   "index_dynamic": true,
   "store_dynamic": false,
   "type_field": "_type",
   "types": {
    "Product": {
     "default_analyzer": "",
     "dynamic": false,
     "enabled": true,
     "properties": {
      "categories": {
       "default_analyzer": "",
       "dynamic": true,
       "enabled": true,
       "properties": {
        "\"$ref\"": {
         "enabled": true,
         "dynamic": false,
         "fields": [
          {
           "analyzer": "keyword",
           "index": true,
           "name": "\"$ref\"",
           "type": "text"
          }
         ]
        }
       }
      },
      "description": {
       "default_analyzer": "",
       "dynamic": false,
       "enabled": true,
       "properties": {
        "long": {
         "enabled": true,
         "dynamic": false,
         "fields": [
          {
           "include_in_all": true,
           "index": true,
           "name": "long",
           "type": "text"
          }
         ]
        },
        "short": {
         "enabled": true,
         "dynamic": false,
         "fields": [
          {
           "include_in_all": true,
           "index": true,
           "name": "short",
           "type": "text"
          }
         ]
        }
       }
      },
      "isVisible": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "include_term_vectors": true,
         "index": true,
         "name": "isVisible",
         "type": "boolean"
        }
       ]
      },
      "brandName": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "include_in_all": true,
         "index": true,
         "name": "brandName",
         "type": "text"
        }
       ]
      },
      "fobPriceMax": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "fobPriceMax",
         "store": true,
         "type": "text"
        }
       ]
      },
      "fobPriceMin": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "fobPriceMin",
         "store": true,
         "type": "text"
        }
       ]
      },
      "fobUnit": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "fobUnit",
         "store": true,
         "type": "text"
        }
       ]
      },
      "isActive": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "include_term_vectors": true,
         "index": true,
         "name": "isActive",
         "type": "boolean"
        }
       ]
      },
      "fobCurrency": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "fobCurrency",
         "store": true,
         "type": "text"
        }
       ]
      },
      "keywords": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "analyzer": "keyword",
         "include_in_all": true,
         "index": true,
         "name": "keywords",
         "type": "text"
        }
       ]
      },
      "mainPicture": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "mainPicture",
         "store": true,
         "type": "text"
        }
       ]
      },
      "minOrderQuan": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "minOrderQuan",
         "store": true,
         "type": "text"
        }
       ]
      },
      "minOrderUnit": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "name": "minOrderUnit",
         "store": true,
         "type": "text"
        }
       ]
      },
      "name": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "include_in_all": true,
         "index": true,
         "name": "name",
         "store": true,
         "type": "text"
        }
       ]
      },
      "variationSerials": {
       "enabled": true,
       "dynamic": false,
       "fields": [
        {
         "analyzer": "keyword",
         "index": true,
         "name": "variationSerials",
         "type": "text"
        }
       ]
      }
     }
    }
   }
  },
  "store": {
   "indexType": "scorch",
   "kvStoreName": "mossStore"
  }
 },
 "sourceType": "couchbase",
 "sourceName": "PTTTradeTest",
 "sourceUUID": "7028f16e80f993f5d5f60c93e7eb1147",
 "sourceParams": {},
 "planParams": {
  "maxPartitionsPerPIndex": 171,
  "numReplicas": 0
 },
 "uuid": "7e334514e30a900d"}

我的搜索代码:

Product.searchAsync = function (term, categoryId, variations, limit, skip, sort) {
    return new Promise(function (resolve, reject) {
        var SearchQuery = Couchbase.SearchQuery;
        var SearchFacet = Couchbase.SearchFacet;

        var tqs = []
        if (term) {
            tqs.push(SearchQuery.match(term)); // It search in default field, here it's _all
        }
        if (categoryId) {
            tqs.push(SearchQuery.term(categoryId).field("categories.$ref"));
        }
        if (variations) {
            variations.map(v => tqs.push(SearchQuery.match(v).field("variationSerials")));
        }

        tqs.push(SearchQuery.booleanField(true).field("isActive"));
        tqs.push(SearchQuery.booleanField(true).field("isVisible"));
        var conjunction = SearchQuery.conjuncts(tqs);
        var query = SearchQuery.new("product_search", conjunction);

        query.addFacet("variations", SearchFacet.term("variationSerials", 100));
        query.limit(limit);
        query.skip(skip);
        if (sort)
            query.sort(sort);

        query.fields(["name", "fobCurrency", "fobPriceMin", "fobPriceMax", "fobUnit", "mainPicture", "minOrderQuan", "minOrderUnit"]);

        ottoman.bucket.query(query, (error, result, meta) => {
            if (error) {
                reject(error);
            }
            else {
                var resultset = {
                    hits: result,
                    totalHits: meta.totalHits
                };

                resolve(resultset);

            }
        });
    }.bind(this))
}

我的测试服务器具有2.80 GHz英特尔®至强®处理器E7-4890 v2和12 gb RAM。在单节点中,如果我使用“ Moss”作为索引类型,则我的服务每秒只能响应300个请求。如果我将索引类型更改为“ Scorch”,则每秒增加到500-530个请求。我相信这些效果不是很好。我究竟做错了什么?如何提高性能?

0 个答案:

没有答案