组织 Lunene 目录

发布于 2024-11-02 12:56:54 字数 831 浏览 2 评论 0原文

我有一组记录。每条记录可以有多个技能和一个状态。

因此,您可能有技能 a、b 和 c 的记录以及维多利亚州的记录。

我需要能够在目录中搜索包含维多利亚技能 a 或维多利亚技能 a 和 c 的任何记录。

我无法创建一个有效的目录来以我想要的方式进行搜索。

首先,我创建了一个目录,其中包含 skills: abc state:vic 然后我尝试了 skills: a,b,c state:vic

但搜索这些并没有给我正确的结果。事实上,当我有疑问时;

skills:a,b AND state:vic,
skills: a OR b AND state:vic,
skills: a OR skills:b AND state:vic

以上所有内容都返回一组 skills: a AND state:vic 记录。

有什么想法吗?

编辑

自从发布此内容以来,我已经让它发挥作用,但不确定这是否是正确的方法。

我将所有技能组合到一个领域中,并用空间将它们分开。技能采用 GUID 格式。

然后在我的搜索方法中我这样做;

queryString = "skills:(skill1 OR skill2 OR skill3) AND state:Vic";
Query query = parser.Parse(queryString);

这工作得很好,而且非常快,但是创建一个 queryString 真的是解决这个问题的方法还是有更好的方法?

I have a set of records. Each record can have multiple skills and a single state.

So you might have a record of skills a, b and c and a state of Victoria.

I need to be able to search the directory for any records that have say skill a in Victoria or skill a and c in Victoria.

I'm having trouble creating an effective directory that will allow me to search in the manner I want.

At first i created a directory with skills: a b c state:vic
then i tried skills: a,b,c state:vic

But searching these is not giving me the correct results. In fact when i have a query;

skills:a,b AND state:vic,
skills: a OR b AND state:vic,
skills: a OR skills:b AND state:vic

the above all return a set of records for skills: a AND state:vic.

Any thought?

EDIT

Since posting this I have gotten it to work but am unsure if this is the right approach.

I have combined all the skills into a single field and space seperated them. The skills are in GUID format.

Then in my search method I do this;

queryString = "skills:(skill1 OR skill2 OR skill3) AND state:Vic";
Query query = parser.Parse(queryString);

This works fine and it's very quick but is creating a queryString really the way to go with this or is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月无声 2024-11-09 12:56:54

您可以直接构建 BooleanQuery,而不是通过 QueryParser。这要求您在向用户呈现搜索界面时区分技能和状态输入字段。

var skillQuery = new BooleanQuery {
    { new TermQuery(new Term("skills", "skill1")), Occur.SHOULD },
    { new TermQuery(new Term("skills", "skill2")), Occur.SHOULD },
    { new TermQuery(new Term("skills", "skill3")), Occur.SHOULD }
};

var query = new BooleanQuery() {
    { skillQuery, Occur.MUST },
    { new TermQuery(new Term("state", "Vic")), Occur.MUST }
};
// query = "+(skills:skill1 skills:skill2 skills:skill3) +state:Vic"

在搜索技能时允许自由文本条目仍然需要调用QueryParser.Parse

var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var skillParser = new QueryParser(Version.LUCENE_30, "skills", analyzer);
var skillQuery = skillParser.Parse("skill1, skill2, skill3");
var query = new BooleanQuery() {
    { skillQuery, Occur.MUST },
    { new TermQuery(new Term("state", "Vic")), Occur.MUST }
};
// query = "+(skills:skill1 skills:skill2 skills:skill3) +state:Vic"

You could build your BooleanQuery directly, instead of going via a QueryParser. This requires that you differentate skills- and state input fields when presenting your search interface to your users.

var skillQuery = new BooleanQuery {
    { new TermQuery(new Term("skills", "skill1")), Occur.SHOULD },
    { new TermQuery(new Term("skills", "skill2")), Occur.SHOULD },
    { new TermQuery(new Term("skills", "skill3")), Occur.SHOULD }
};

var query = new BooleanQuery() {
    { skillQuery, Occur.MUST },
    { new TermQuery(new Term("state", "Vic")), Occur.MUST }
};
// query = "+(skills:skill1 skills:skill2 skills:skill3) +state:Vic"

Allowing freetext entries when searching for skills still require a call to QueryParser.Parse.

var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var skillParser = new QueryParser(Version.LUCENE_30, "skills", analyzer);
var skillQuery = skillParser.Parse("skill1, skill2, skill3");
var query = new BooleanQuery() {
    { skillQuery, Occur.MUST },
    { new TermQuery(new Term("state", "Vic")), Occur.MUST }
};
// query = "+(skills:skill1 skills:skill2 skills:skill3) +state:Vic"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文