【问题标题】:Setup Lucene.Net Index设置 Lucene.Net 索引
【发布时间】:2013-03-18 01:13:18
【问题描述】:

我有一个列出运动和用户的数据库,并有一个连接表 (UserSports):

Sports Table:
ID   Name
1    Running
2    Swimming
3    Football
4    Baseball
5    Basketball

Users Table:
ID    Name
1     George
2     Jane
3     Alex

UsersSports
UserID   SportID
1         2
3         1
2         4
2         5

我想使用 lucene.net 搜索运动,因此我为它们创建了一个索引并分析了名称。这很好用。当我搜索“球”时,我得到了足球、棒球、篮球。我想要做的是,对于特定用户,只返回他们在 UserSports 中没有记录的运动。因此,如果 Jane 搜索“ball”,它应该只返回 Football。我可以使用not inleft join ... where join is null 在SQL 中执行此操作,效果很好,但我想添加模糊逻辑搜索Lucene.net 给出的。

在 Lucene.Net 中索引我的数据的最佳方法是什么?

【问题讨论】:

    标签: c# lucene.net


    【解决方案1】:

    有很多方法可以做到这一点。

    由于您永远不会进行大量的运动,因此您可以像实际一样简单地查询 Lucene 索引,并从中构建 SQL 查询:

    SELECT *
    FROM Sports
    WHERE Sports.ID IN([list from lucene])
    AND NOT EXISTS(
        SELECT 1
        FROM UsersSports
        WHERE UsersSports.UserId = [current user id]
        AND UserSports.SportID = Sports.ID
    )
    

    【讨论】:

    • 如果有很多体育记录(比如 1000 次潜在比赛)怎么办?你还会这样做吗?
    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多