基于搜索的一组关键词 [英] Search based on a set of keywords

查看:87
本文介绍了基于搜索的一组关键词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要基于一组关键词进行搜索,返回所有这些关键字相关的广告。那么结果与广告计算每个类别分类的列表。

I need to make a search based on a set of keywords, that return all the Ads related with those keywords. Then the result is a list of Categories with the Ads Count for each Category.

搜索是在KeywordSearch表制作:

The search is made in a KeywordSearch Table:

public class KeywordSearch
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Keyword Keyword { get; set; }
}

在此,关键字表是:

Where the Keyword Table is:

public class Keyword
{
    public int Id { get; set; }
    public string Name { get; set; }
}

该广告与使用下表中的关键词相关的:

The Ads are related with the Keywords using the following Table:

public class KeywordAdCategory
{
    [Key]
    [Column("Keyword_Id", Order = 0)]
    public int Keyword_Id { get; set; }

    [Key]
    [Column("Ad_Id", Order = 1)]
    public int Ad_Id { get; set; }

    [Key]
    [Column("Category_Id", Order = 2)]
    public int Category_Id { get; set; }
}

最后,分类表:

public class Category
{
    public int Id { get; set; }
    public string Name { get; set; }
}

例如:


  • 关键词:梅赛德斯 - 奔驰和GLK

  • KeywordSearch:奔驰和奔驰关键字梅赛德斯 - 奔驰
                  GLK关键字GLK

  • 类别:汽车总动员和卡车

  • 广告:汽车 - 奔驰GLK
        卡车 - 奔驰Citan

  • Keywords: "Mercedes-Benz" and "GLK"
  • KeywordSearch: "Mercedes" and "Benz" for the Keyword "Mercedes-Benz" "GLK" for the Keyword "GLK"
  • Category: "Cars" and "Trucks"
  • Ads: Car - Mercedes-Benz GLK Truck - Mercedes-Benz Citan

如果我搜索梅赛德斯 - 奔驰我得到:

If I search "Mercedes-Benz" I get:


  • 汽车:1

  • 卡车:1

如果我搜索梅赛德斯 - 奔驰GLK我得到:

If I search "Mercedes-Benz GLK" I get:


  • 汽车:1

如果我搜索奔驰Citan我得到:

If I search "Mercedes Citan" I get:


  • 卡车:1

我得到什么到现在为止:

What I get until now:

var keywordIds = from k in keywordSearchQuery
                    where splitKeywords.Contains(k.Name)
                    select k.Keyword.Id;

var matchingKac = from kac in keywordAdCategoryQuery
                    where keywordIds.Distinct().Contains(kac.Keyword_Id)
                    select kac;

var addIDs = from kac in matchingKac
             group kac by kac.Ad_Id into d
             where d.Count() == splitKeywords.Count()
             select d.Key;

var groupedKac = from kac in keywordAdCategoryQuery
                    where addIDs.Contains(kac.Ad_Id)               <--- EDIT2
                    group kac by new { kac.Category_Id, kac.Ad_Id };

var result = from grp in groupedKac
                group grp by grp.Key.Category_Id into final
                join c in categoryQuery on final.Key equals c.Id
                select new CategoryGetAllBySearchDto
                {
                    Id = final.Key,
                    Name = c.Name,
                    ListController = c.ListController,
                    ListAction = c.ListAction,
                    SearchCount = final.Count()
                };

问题是,我不能只匹配所有关键词的广告。

The problem is that I can't get only the Ads that match all Keywords.

编辑:

当一个关键字,如奔驰,行,其中d.Count()== splitKeywords.Count()失败,因为d.count = 1和splitkeywords.Count =制成的2个或更多KeywordSearches 2梅赛德斯 - 奔驰

When a keyword is made of 2 or more KeywordSearches like "Mercedes-Benz", the line "where d.Count() == splitKeywords.Count()" fails, because d.count = 1 and splitkeywords.Count = 2 for "Mercedes-Benz"

任何帮助吗?

推荐答案

如果你试图让自己的搜索引擎,你可能会fail.Why你不尝试Lucene的。
这里有一个链接 http://lucenenet.apache.org/
干杯

If you try to make your own search engine you will probably fail.Why don't you try Lucene. Here's a link http://lucenenet.apache.org/. Cheers

这篇关于基于搜索的一组关键词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆