SOLR中UNION和MINUS的用法

bakd9h0s  于 2022-11-23  发布在  Solr
关注(0)|答案(2)|浏览(170)

我正在使用solr,我想在SOLR中使用UNION和MINUS的组合。我已经制定了oracle查询。

select * from TESTTABLE where (FT = 'PE' and emis between 10 and 20) or (FT = 'DI' and emis between 10 and 15) 
union (
select * from TESTTABLE where (FT <> 'PE' or emis not between 10 and 20) and (FT <> 'DI' or emis not between 10 and 15) 
minus
select * from TESTTABLE where (FT = 'PE' and emis not between 10 and 20) or (FT = 'DI' and emis not between 10 and 15) 
);

我想制定一个等价的SOLR。请阿西斯我将oracle查询转换为SOLR。

9gm1akwq

9gm1akwq1#

您应该能够在Solr中构建它,只需考虑以下因素:
1.您可以像在sql中一样使用括号

  1. UNION:两个条件x OR y的OR运算
  2. MINUS:只需使用AND NOT连接两个条件:x与非y
    1.记住把所有的都放在一个fq里面,用*:*表示q
    1.注意“NOT x”,在solr中有时你需要一点技巧来使它正确工作,参见here for examples。可能取决于solr的版本
h4cxqtbf

h4cxqtbf2#

举个例子:在Comics和Filmography中获取年龄范围为10到25的图书,并假设有三个字段bookName、bookType和age i,将执行以下操作:-
q=图书类型:漫画书类型:电影类型&fq=年龄:[10至25]
主查询中的两个bookType子句之间没有间隔意味着OR,即带来漫画或电影,并且过滤器查询中的年龄范围,即fq过滤掉年龄不在10到25之间的结果。

相关问题