如何分组和计算狮身人面像搜索?

时间:2014-06-19 23:49:41

标签: .net sphinx

我最近在我的项目中使用了sphinx dot net客户端。我是这方面的新手。我设法从sphinx服务器

获取结果

这是我的代码看起来像

    static void Main(string[] args)
    {
        try
        {
            SearchCommand search = new common().ReturnCommand();
            SearchQuery query = new SearchQuery("");
            query.Indexes.Add("SphinxSearch");
            query.MatchMode = MatchMode.Extended;

            query.MaxMatches = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SphinxMaxMathces"]);
            query.Limit = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SphinxLimit"]);
            query.MatchMode = MatchMode.Extended2;

            query.AttributeFilters.Add("CategoryId", 2, false);

            query.Select = "categoryid,SubCategoryId1";

            search.QueryList.Add(query);
            search.Execute();

            foreach (Match match in search.Result.QueryResults[0].Matches)
            {
                Console.WriteLine("Category : {0} , Subcategory : {1} \n ", (int)match.AttributesValues["categoryid"].GetValue(), (int)match.AttributesValues["subcategoryid1"].GetValue());

            }

            Console.WriteLine("\n Total {0} Mathches Found \n", search.Result.QueryResults[0].Matches.Count);
        }
        catch (Exception ex)
        {
            Console.WriteLine("\n" + ex.Message);
        }

        Console.Read();

此代码工作正常,现在我需要根据子类别对事物进行分组并显示计数。所以我已经重新写了我的

    static void Main(string[] args)
    {
        try
        {
            SearchCommand search = new common().ReturnCommand();
            SearchQuery query = new SearchQuery("");
            query.Indexes.Add("SphinxSearch");
            query.MatchMode = MatchMode.Extended;

            query.MaxMatches = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SphinxMaxMathces"]);
            query.Limit = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SphinxLimit"]);
            query.MatchMode = MatchMode.Extended2;

            query.AttributeFilters.Add("CategoryId", 2, false);

            query.Select = "SubCategoryId1,COUNT(*)";

            query.GroupBy = "SubCategoryId1";

            search.QueryList.Add(query);
            search.Execute();

            foreach (Match match in search.Result.QueryResults[0].Matches)
            {
               Console.WriteLine(" Subcategory : {0} \n ", (int)match.AttributesValues["subcategoryid1"].GetValue());
            }

            Console.WriteLine("\n Total {0} Mathches Found \n", search.Result.QueryResults[0].Matches.Count);
        }
        catch (Exception ex)
        {
            Console.WriteLine("\n" + ex.Message);
        }

        Console.Read();

但是这次出现问题,狮身人面像会引发某种内部错误,我花了很多时间来修复错误但却没有弄清楚。

Sphinx服务器返回了查询的错误状态。服务器消息:'内部错误:列'计数()/计数()'不存在于结果集架构中

这是我得到的错误。

0 个答案:

没有答案