简体   繁体   English

设置Lucene.Net索引

[英]Setup Lucene.Net Index

I have a database that lists sports and users and has a join table (UserSports): 我有一个列出运动项目和用户的数据库,并具有一个联接表(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

I want to search for sports using lucene.net so I create an index for them and make the name analysed. 我想使用lucene.net搜索体育运动,所以我为他们创建了索引并进行了名称分析。 This works great. 这很好。 When I search for "ball" I get football, baseball, basketball back. 当我搜索“球”时,我会得到足球,棒球和篮球。 What I want to do though is for a particular user only return sports where they DON'T have a record in UserSports. 我想做的是针对特定用户,只返回他们在UserSports中没有记录的运动。 So if Jane searched for "ball" it should only return Football. 因此,如果简搜索“球”,则应该只返回足球。 I can do this in SQL using a not in or a left join ... where join is null and that works fine, but I want to add fuzzy logic searching the Lucene.net gives. 我可以使用not inleft join ... where join is null联接在SQL中进行此操作left join ... where join is null ,可以正常工作,但是我想添加模糊逻辑来搜索Lucene.net给出的逻辑。

What is the best way to index my data in Lucene.Net? 在Lucene.Net中索引数据的最佳方法是什么?

There are tons of ways to do this. 有很多方法可以做到这一点。

Since you will never have extremely large amounts of sports, you could simply query the Lucene index like you actually do, and build a SQL query from it: 由于您永远不会进行过多的运动,因此可以像实际一样简单地查询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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM