Solr 8.6 - combine facets on multivalued dateRange field with exclude tags, negate and OR clause - solr

On Solr 8.6, I have a multivalued field of dateRange type which contains an availability table.
<field name="availabilities" docValues="false" type="dateRange" multiValued="true" indexed="true" required="false" stored="true"/>
"availabilities": [
"[2021-12-22T00:00:00Z TO 2022-01-02T23:59:59Z]",
"[2022-01-20T00:00:00Z TO 2022-02-02T23:59:59Z]",
"[2022-02-10T00:00:00Z TO 2022-02-21T23:59:59Z]"
]
With a facet, I want to be able to select the available and/or unavailable people.
The Solr query is as follows and works well.
http://localhost:8985/solr/rby/select?facet=on&facet.query={!key="FQ4#Available now" ex=tag_availabilities}availabilities:[NOW TO NOW]&fl=id,availabilities&fq={!tag=tag_availabilities}availabilities:([NOW TO NOW])&q=*:*&rows=10&wt=json
For the unavailable people query, it does not work when I exclude NOW with {} like this.
http://localhost:8985/solr/rby/select?facet=on&facet.query={!key="FQ4#Unavailable" ex=tag_availabilities}availabilities:{NOW TO NOW}&fl=id,availabilities&fq={!tag=tag_availabilities}availabilities:({NOW TO NOW})&q=*:*&rows=10&wt=json
Solr answers with the following error:
"msg": "Wrong order: 2021-12-30T16:18:06.304 TO 2021-12-30T16:18:06.302",
I found a workaround with - before field but now I can't combine the two filters of the facet with an OR.
http://localhost:8985/solr/rby/select?facet=on&facet.query={!key="FQ4#Unavailable" ex=tag_availabilities}-availabilities:[NOW TO NOW]&fl=id,availabilities&fq={!tag=tag_availabilities}-availabilities:([NOW TO NOW])&q=*:*&rows=1000&wt=json
Thanks for your help

Related

Why Solr Group get only one group,but Solr Facet get only two groups?

Solr:I have a field, the field type is string, the field content is '22 33', when I do Group, why do I get a group? But Facet has two groups
config:
<field name="unit_co" type="text_general" indexed="true" stored="true"/>
group result:
{{
"groupValue":"22",
"doclist":{"numFound":1,"start":0,"docs":\[
{
"unit_co":" 22 33 "}
}}]}}}
facet result:
{
"unit_co":[
"22",1,
"33",1]
}
I tried to solve this problem with other solutions, such as multi-value fields, but Solr does not support groups with multi-value fields.
solr error:can not use FieldCache on multivalued field

Copy-transform a numeric field in Solr?

I have a dynamic numeric multivalued field in my solr schema -
<dynamicField name="*_nm" type="float" indexed="true" stored="true" multiValued="true" omitNorms="false"/>
I'd like to run a function score on said field -
_val_:"if(exists(features.width_nm),mul(exp(div(pow(max(0,sub(abs(sub(features.width_nm,12.00000)),0.00000)),2),-51.93702)),10.00000),0.000000)"
but function queries on multivalued fields aren't properly supported in my version of Solr (5.2.1). Trying the above gives the error -
"can not use FieldCache on multivalued field"
My current work-around for this is during indexing to create another field, numeric single-valued, which contains a "reduced" form of the multivalues.
Currently I do this in Java code.
Is there any way for me to do this directly in Solr? for example using a "copy-field"?
Just for completeness - In solr 6.3 I am able to calculate a function-score on a multivalued field by using the field function with a min/max parameter described here.
Thank you very much!

On the fly field value calculation in Solr

I've 10s of fileds defined in my Solr manaed-schema, out of those two are as below:
<field name="isBookmarked" type="boolean" indexed="true" stored="true" required="false" multiValued="false" />
<field name="bookmarkedPathologists" type="string" indexed="true" stored="true" required="false" multiValued="true" />
Now, here I want to set isBookmarked value to 'true' OR'false' if bookmarkedPathologists has SOME value passed while querying on the fly.
Post that I'm sorting on isBookmarked field.
Is it possible? Help anticipated
I struggled a lot and finally got luck to solve my problem using below possible solution.
As on the fly updated changes need to be committed to Solr before getting sorted result on and hence my application which is Solr Client, couldn't get updated/dirty values to sort on, if any.
So I added a Filter Query to my Simple Query Criteria as * exists(query({!v='bookmarkedPathologists:patho'})) : will filter my all(*) results with new on the fly created field named as exists(query({!v='bookmarkedPathologists:patho'})) in JSON response as below:-
:
:
"isBookmarked": false,
"bookmarkedPathologists": [
"patho1"
],
:
:
"_version_": 1582235372763480000,
"exists(query({!v='bookmarkedPathologists:patho'}))": false
Post that I just put sort-order over the same i.e. exists(query({!v='bookmarkedPathologists:patho'})) as exists(query({!v='bookmarkedPathologists:patho'})) asc
So Solr returned sorted response over exists(query({!v='bookmarkedPathologists:patho'})).
Solr Function Query helped me a lot from Function Queries
As I understand you want to update the field while querying the data from it.
SOLR programmed in java language and to interface with SOLR is done using REST kind of services.
And service for search is on:
/solr/<CollectionName>/select
And service for update is on:
/solr/update
So you can`t do both with using same query.
But you want to update externally (using other query) then refer.

Highlighting Mutivalue field returns String, not List

In Solr, I have several multivalue fields configured, but whenever I query them using highlighting, I get back a single result, instead of a list.
For example, here's my query:
hl=true&
hl.preserveMulti=true&
f.school.hl.alternateField=school&
f.school.hl.fragListBuilder=single&
fl=id,absolute_urlg&
hl.fl=school&
q=university&
start=0&
rows=20&
sort=score+desc&
School is a multiValue field configured like so:
<field name="school"
type="text_en_splitting"
indexed="true"
stored="true"
multiValued="true"
termVectors="true"
termPositions="true"
termOffsets="true"/>
For one document in my collection, school has the value:
[University of California,
Villanova University,
Pitzer College]
The result I want when somebody searches for "University" as they did above is:
["<mark>University</mark> of California",
"Villanova <mark>University</mark>",
"Pitzer College"]
But instead I get:
<mark>University</mark> of California Villanova <mark>University</mark>
Is there something I'm missing? Somehow I'm not getting back a list of results, and values in the multiValue field that don't match aren't being returned.

Sort on field completeness of Solr Documents

I have this Solr field
<field name="listing_thumbnail" type="string" indexed="false" stored="true"/>
Now when the results are shown the fields without the field value should be shown at the last. Is this possible in SOLR? To generalise is it possible to sort documents on field completeness?
You can make use of bq (Boost Query) Parameter of the dismax/edismax query handler. This allows to query if a field is empty or not and then affect the score, but to do so the field needs to be indexed=true.
If you had your field indexed you could add bq=(listing_thumbnail:*) - this would give a push to all documents with a value in that field.

Resources