On the fly field value calculation in Solr - 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.

Related

Additional fields in schema.xml are not showing up when I do a query

Solr version information: 6.6.0
The core is named: solr
Instance: /var/solr/data/new_core
In the /var/solr/data/new_core/conf/ directory I have a custom schema.xml file
I have multiple custom fields like this in the schema.xml file
<field name="nid" type="int" indexed="true" stored="true"/>
When I select the 'solr' core and go to query, these custom fields are not showing up in the results. Here's an example of the results:
{
"response":{"numFound":200,"start":0,"docs":[
{
"id":"koe1eh/node/49",
"site":"https://example.com:1881/",
"hash":"koe1eh",
"ss_language":"und",
"url":"https://example.com:1881/node/49",
"ss_name":"tfadmin",
"tos_name":"tfadmin",
"ss_name_formatted":"tfadmin",
"tos_name_formatted":"tfadmin",
"is_uid":1,
"bs_status":true,
"bs_sticky":false,
"bs_promote":false,
"is_tnid":0,
"bs_translate":false,
"ds_created":"2009-03-12T17:46:06Z",
"ds_changed":"2009-06-18T15:25:33Z",
"ds_last_comment_or_change":"2009-06-18T15:25:33Z",
"tos_content_extra":" (Gifts) ",
"sm_field_apptype":["mousepad"],
"_version_":1588589404094464000,
"timestamp":"2018-01-03T16:28:34Z"}]
}}
The query performed is: http://example.com/solr/solr/select?indent=on&q=*:*&rows=1&wt=json
solrconfig.xml is here: https://pastebin.com/iVhZCqTW
schema.xml is here: https://pastebin.com/UBaUN5EK
I have tried restarting solr, reloading the core, and reindexing with no effect.
It turns out that I was just looking at some entries that did not have those fields. When I altered my query to start on record 900, then I saw the fields I was looking for. I'm not sure what else I may have done to get this working as I've been trying many different things.

How to fetch Payload field value from Solr Query

In My Solr Collection , I have field of type "Payload" and I wanted to see the value stored in specific document . Can you please suggest if there is any way to get the payload field value using Solr Query ?
I tried putting the field name in "fl" parameter list of Solr query but it does not return me Payload field in the result.
Please advice ?
Make sure field is stored. check in schema.xml file if Payload field is set stored="true"
<field name="Payload" type="text_general" indexed="true" stored="true"/>
if it is set to false, change it to true, restart solr and reindex you content. you see Payload field in your results.

SOLR Exact match issue

I have indexed my field in SOLR using field type "string".
My field contains two values "APA" and "APA LN".
I have queried SOLR with q=field:"APA".
With the above query i ma getting the results for both APA and APA LN.
I have to query SOLR to just get "APA".
Any help is appreciated
I presume that your field "field" is TextField or text_general. Can you change it to string and try again?
ie something like this
<field name="customfield" type="string" indexed="true" stored="true" multiValued="false" />
It should not be happening for a type string. The most likely scenario is that you did not fully reindex or did not commit after reindexing.
You can check what your field actually contains in the Admin UI's Schema Browser screen (press load term info).

Boost function with custom indexed string field does not work. Solr 3.6

I'm improving an existing search system which is using Solr 3.6
I'm trying to boost search results using following function:
{!boost b=recip(sub(1,floor(strdist("someText",myField,jw))),1000000,1,1)}searchText
searchText - some text that user searches for;
myField - custom indexed document's field, value cam be empty or not empty string;
In short, this function divides by 1000001 scores of all search results where myField's value is not equal to someText. In this way results with specified myField's value are on top ordered by their original score.
Thus, the field is there, the value is present in the field, but the result's score is also divided and the result is somewhere deep down...
When I use:
fq=myField:[* TO *]
Solr filters out results where field's value is not empty string. So, it is recognized...
There is another legacy string field. When I apply my function using that field, everything works as it should. But when I use my field it fails.
Do you have any ideas of what might be wrong? What should I look for?
Please help. I've spent lots of time without success already, but I'm new to Solr and not able to resolve this issue so far...
Thank you!
I've kept asking people, so, luckily, I've resolved my problem :)
So the problem was in the declaration of the field in schema.xml.
The legacy field was declared like this:
<field name="searchText" type="string" indexed="true" stored="true" multiValued="false"/>
and my field was declared like this:
<field name="myField" type="text" indexed="true" stored="true" multiValued="false"/>
And that's why my boost function did not work.
So I've changed to type "string" and everything works OK now :)

Solr date range search yielding no results

I'm having a hard time pinning down why my Solr date range search is not working. I am building on an existing working search, adding two new fields to assist with accommodation search.
I add the following two fields to the schema - The first is effectively an array of dates, and the second is a single value:
<field name="available_checkin_dates" type="date" indexed="true" stored="false" multiValued="true" />
<field name="available_unit_count" type="int" indexed="true" stored="false" />
I verified that the index document was created and sent to Solr with the two fields populated, but the following search terms yield no results:
* AND available_checkin_dates:[* TO NOW]
* AND available_checkin_dates:[NOW TO *]
* AND available_checkin_dates:"2012-08-31T00:00:00.0000000Z"
* AND available_checkin_dates:"2012-08-31T00:00:00Z"
* AND available_unit_count:1
* AND available_unit_count:*
Either I'm using the wrong syntax, or the documents didn't get indexed. I'm having a hard time reading the catalina logs, and I can't find a tool that inspects the actual indexed documents.
Any ideas on how to help me nail this one down? I'm a relative Solr newbie.
Never mind, there was a problem with the auto-commit settings, so the buffer wasn't getting flushed. Documents were getting committed with commit as false, but the auto-commit settings weren't in place to flush when the level of uncommitted documents reached a certain number.

Resources