Highlighting Mutivalue field returns String, not List - solr

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.

Related

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

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

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.

How to add custom prefix and suffix string in a field in solr

Like the title said I tried many ways to add a prefix and/or a suffix in a field in solr. More precisely I mean:
For example I have those fields in my schema.xml
field name="field1" type="double" indexed="true" stored="true" multiValued="false"
field name="field2" type="double" indexed="true" stored="true" multiValued="false"
I would like to have my third field like this
"field3" = "{a prefix}field1 field2{a suffix}
The problem is, I saw many ways to copy field or concat other store fields
but I don't want my prefix or my suffix be stored in solr, I just want to have a field3 with two other fields and custom strings that I choose to put in. I ask this question here because after a lot of search I did not find anything good for my purpose.
You can use an StatelessScriptUpdateProcessor to manipulate the contents of the field on the way in, and merge it with the values from field1 and field2.
As you can write regular Javascript in the script referenced from the processor, you can add the prefix and suffix in any way you want, without having to supply it in the request.

Handling one to many relationship in solr

I have a requirement where I have to handle one to many relationship in SOLR.
Say , an entity Person can have multiple names(first name, last name, name type). Now the problem with this is that if I make first name , last name & name type as multi- valued field in my schema.xml it won't help.Because I will not be able figure out which first name will be associated to which last name and which name type.
What I want is if I have a person say P1 with 2 names [name_type1,firstName1,lastName1] & [name_type2,firstName2,lastName2].
Now if I do a full text search firstName1 then I should get back P1.
Is there any way to handling this use case in SOLR?
If your documents looked like the following:
name.first.[type] = John
name.last.[type] = Smith
which can be defined as dynamic fields:
<dynamicField name="name.first.*" type="text" indexed="true" stored="true" />
<dynamicField name="name.last.*" type="text" indexed="true" stored="true" />
and have copy field definitions in your config:
<copyField source="name.first.*" dest="text" maxChars="256" />
<copyField source="name.last.*" dest="text" maxChars="256" />
which will copy all your names into a 'text' field which can be searched on.
With this structure, if the field values are stored (versus just indexed) then it'll be possible to reconstruct all the names from a person document.

Solr: Sort by id desc for > 1000 items

This feels weird, but I'm trying to search and sort on my id (primary) field with solr. I have a query like:
http://foo.com/solr/collection/select?q=*%3A*&sort=id+desc&fl=id+title&wt=json
This returns fields sorted in a descending order, but starting at 999. I have ~1200 items in my index.
From my schema.xml:
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
I did think about making my id an int, but I'd have to kill everything and start over (not a big issue tho).
Any tips?
Cheers,
Tom
If your id field is truly a numeric value and you want to sort by that value, I would recommend one of the following two options.
Change the field type to int and reindex.
Create a new field id_sort that is of type int and use the copyField directive to populate that field with the value from the id field at index time.

Resources