Swiftype自动完成JQuery按文档类型分离结果

Swiftype自动完成JQuery按文档类型分离结果,jquery,ruby-on-rails,autocomplete,jquery-autocomplete,swiftype,Jquery,Ruby On Rails,Autocomplete,Jquery Autocomplete,Swiftype,您好,我正在使用rails的Swiftype gem 我已经让它工作,因为我可以上传文件到他们的网站,并自动完成我的 我遇到的问题是,我正在搜索两种不同的文档类型,并希望在结果中显示它们 我有两种类型的文档:类别和公司 当前,我将显示以下内容: Search: Category Category Company Category Company 我希望它是这样的 Search: Category Category Category --------- C

您好,我正在使用rails的Swiftype gem 我已经让它工作,因为我可以上传文件到他们的网站,并自动完成我的

我遇到的问题是,我正在搜索两种不同的文档类型,并希望在结果中显示它们

我有两种类型的文档:类别和公司

当前,我将显示以下内容:

Search:
  Category
  Category
  Company
  Category
  Company
我希望它是这样的

Search:
  Category
  Category
  Category
  ---------
  Company
  Company
或者像这样更好:

Search:
  Category    |  Company
  Category    |  Company
  Category    |  Company
$(function() {
          var customResultRenderFunction = function(ctx, data) {
            var withSections = [],
              noSections = [];

            $.each(data, function(docType, results) {
              $.each(results, function(idx, result) {
                if (result.sections && result.sections.length > 15) {
                  withSections.push(result);
                } else {
                  noSections.push(result);
                }
              });
            });

            var withSectionsList = $('<ul class="with_sections"></ul>'),
              noSectionsList = $('<ul class="no_sections"></ul>');

            $.each(withSections, function(idx, item) {
              ctx.registerResult($('<li class="result"><p>' + item['name'] + '</p></li>').appendTo(withSectionsList), item);
            });
            $.each(noSections, function(idx, item) {
              ctx.registerResult($('<li class="result"><p>' + item['name'] + '</p></li>').appendTo(noSectionsList), item);
            });
            if (withSections.length > 0) {
              withSectionsList.appendTo(ctx.list);
            }
            if (noSections.length > 0) {
              noSectionsList.appendTo(ctx.list);
            }
          };

          $('#st-search-input').swiftype({
            engineKey:  '<%= ENV['SWIFTYPE_ENGINE_KEY'] %>',
            resultRenderFunction: customResultRenderFunction,
            suggestionListType: 'div',
            resultListSelector: '.result',
            fetchFields: {page: ['url', 'name']}
          });
        });

</script>
我使用的是默认的Swiftype自动完成JS

页面上的JS如下所示:

Search:
  Category    |  Company
  Category    |  Company
  Category    |  Company
$(function() {
          var customResultRenderFunction = function(ctx, data) {
            var withSections = [],
              noSections = [];

            $.each(data, function(docType, results) {
              $.each(results, function(idx, result) {
                if (result.sections && result.sections.length > 15) {
                  withSections.push(result);
                } else {
                  noSections.push(result);
                }
              });
            });

            var withSectionsList = $('<ul class="with_sections"></ul>'),
              noSectionsList = $('<ul class="no_sections"></ul>');

            $.each(withSections, function(idx, item) {
              ctx.registerResult($('<li class="result"><p>' + item['name'] + '</p></li>').appendTo(withSectionsList), item);
            });
            $.each(noSections, function(idx, item) {
              ctx.registerResult($('<li class="result"><p>' + item['name'] + '</p></li>').appendTo(noSectionsList), item);
            });
            if (withSections.length > 0) {
              withSectionsList.appendTo(ctx.list);
            }
            if (noSections.length > 0) {
              noSectionsList.appendTo(ctx.list);
            }
          };

          $('#st-search-input').swiftype({
            engineKey:  '<%= ENV['SWIFTYPE_ENGINE_KEY'] %>',
            resultRenderFunction: customResultRenderFunction,
            suggestionListType: 'div',
            resultListSelector: '.result',
            fetchFields: {page: ['url', 'name']}
          });
        });

</script>
我如何更好地显示它,以分离文档类型