Filter query functions on inconsistent field

I am currently working on a project with a Solr (6.4.0) installation and struggling to get my head around a query, which I believe I need to use a query function to meet my requirements.

My application has one Solr core which spans across 5 different document types (users can index websites, documents, articles etc). The problem I have is that articles have start and end dates so a user may create an article in advance and set a start date of 2 weeks from now. When querying Solr I want to add a function that will explicitly ignore all index-type:article where active date is greater than now, however not exclude other document types like websites etc.

I have been reading up on a Solr Wiki page (https://wiki.apache.org/solr/FunctionQuery#if) where it has some good examples however I think I may be implementing wrong as I am not seeing the desired results. I am using the PECL PHP extension and and adding the query like so:

$query->addFilterQuery("if(exists(active-date), active-date:[* TO NOW], 1)");

If I perform a *:* search around 900 results are returned and the index has circa 8000 records where only 2 article's have active dates that are in the future and the total count of all "articles" is around 200 so it seems to be filtering out of of other "index-types" instead of returning 1 (positive number == true) on the else value.

In summary , I need a query that will look for the field "active-date" (which is only configured on index-type:article), check if the date is in the future - if true then exclude, if false include in result set and if field not present include in result set.

Thanks in advance!


Not sure if you'd actually need a function query:

fq=(index-type:article AND active-date:[* TO NOW]) OR (*:* -active-date:*)

.. as long as the active-date field is present on all article objects. If it's not, you can add an extra condition to OR in any documents that doesn't have the field.

链接地址: http://www.djcxy.com/p/92508.html

上一篇: 什么是提供者和驱动程序

下一篇: 在不一致的字段上过滤查询功能