Solr average of function result - solr

I have a solr index with documents that have a fields started and stopped which both hold a datetime. I would like solr to output an average difference between them.
To get the difference between started and stopped I have used diff:ms(started, stopped) within fl.
I know you can get stats about a field with stats=true and stats.field=fieldname but if i use either diff or ms(started, stopped) as the field name it errors with an undefined field error.
So is what I want possible? If so, how do i go about it?

You should be able to use the function support in the JSON Faceting API:
q=*:*&
json.facet={
"avg_time": "avg(ms(started, stopped))"
}

Related

How to debug the score value calculated for a document and query string which is displayed on solr admin console?

I have indexed few documents and now while trying to query a string from solr admin console, I am able to retrieve score value for each result retrieved by selecting field as score. But I would need to check the doc score, termfreq and other parameters considered for calculating this score which can help me to debug and understand. Can anyone help me with the possible ways? Are there any certain keywords or fields or query parameters to be specified while querying from solr admin console? Solr Version that I am using is 7.6.0.
Add debug=all (the new version of debugQuery=true) to your query string. It'll include a detailed explanation of how each part of your query contributes to the score.

Solr: how to index date and time

I have Solr 7.2.1 and in my managed-schema.xml file I have a field which represents date object of type "pDate".
Now I need to index also the time of the day, but I saw I can't search for the time with "pDate" field type. If I query solr searching for my_date_field:[2018-03-12T00:00:00.000Z TO *] it works; instead if i search [2018-03-12T12:00:00.000Z TO *] I can't find any results.
so, basically, what type is better to use to achieve that ? Is the field type the origin of the problem ?
Solr Ref Guide says: "Solr’s date fields (DatePointField, DateRangeField and the deprecated TrieDateField) represent "dates" as a point in time with millisecond precision." So the field can not be the origin of your problem.
Check the format "12/03/2018T12:00:00.000Z". Is is really correct? I only know dates formatted like "2018-03-12T12:00:00.000Z". See here Date Formatting
Also find the document in Solr Admin UI and inspect the JSON response. What is the value of my_date_field?
I found the solution,
I had to set $SOLR_TIMEZONE variable in the "solr.in" config file, but the correct value was not "CEST" but "Europe/Rome" for me

Solr 6.1 - Get all token counts for a Facet field across all documents

I have a TextField in my solr schema.xml on which I want to run faceting and find out counts for every tokens in that field across all the documents. Is there a way to get this? I tried following and I thought it was working until I found out that it's not a complete list of tokens that I am getting form this query:
http://solrnode1:8983/solr/mycollection/select?facet.field=PRODUCT_NAME&facet=on&indent=on&q=*:*&wt=json&rows=0
For example, there is one document in that field that says "Education Services 2014" but I don't see any facet token for 'education' with its count. Interestingly if I change my query parameter to q=PRODUCT_NAME:*education* instead of q=*:* then it shows up in faceting with count! I am not sure what's happening here. Am I missing something here?
I think it's a facet.limit which is by default 100. I increased it and its getting more tokens and counts now.

SolrNet query to get records between to fields value

hi guys i have started working on a project which need solr implemtation for searching.
I am using SolrNet Lib and my question is:
I have two field in solr index Maxsal and Minsal and i have Currentsal parameter which contains salary amount. What i want is, get all records which satisfy this condition:
currentsal< Maxsal && currentsal> Minsal
Take a look at Solr range query. It should allow to create query like this
minsal:[* TO PARAM] AND maxsal:[PARAM TO *]
For more information look here - http://www.solrtutorial.com/solr-query-syntax.html
Never noticed that Query() take string parameter too.
So,
Solr.Query("MaxSal<="+parameter && MinSal>=parameter")

Solr get calculated distance while using dismax

I'm starting to think that what I want to do is not possible but thought I would give this a try.
I'm running Solr 3.5.
I currently have two types of search:
A basic spatial query which returns the calulated distance between two points in the score field.
Sample Query from my Solr logs:
?fl=*,score&sort=score+asc&start=0&q={!func}geodist()&sfield=coordinates&pt=59.2363514,18.092783&version=2
A dismax query which allows free text queries on a number of fields.
Sample Query from Solr log:
mm=1&d=100.0&sfield=coordinates&qf=field1^5.0+fields2^3.0&defType=edismax&version=2&fl=*,score&start=1&q=monkeyhopper&pt=59.2363514,18.0927830000&fq={!geofilt}}
I want to replace my first query with the dismax query but I really need to get the calculated distance in the response. Yes, I can calulate the distance programatically but I would prefer not having to do this as Solr has done it for me already.
I still want to be able to sort my dismax query "by relevance", distance or any other field so the score given by my boosts could be interesting for sorting but I don't need it to be returned.
If I understood correctly you want to have the result of a function in your Solr response. The SOLR-2444 issue is what you're looking for I guess: it allows to include in the fl parameter pseudo-fields, functions etc. The only problem is that it's been committed only on trunk, so it isn't available on the current Solr release, neither will be in the coming 3.6 release. You have to wait for the 4 release but I don't think it will take a lot of time. Maybe you can already start playing around with a snapshot of the last successful Jenkins build.
Pseudo-fields are now available in Solr 4+ which allow you to do just this.
http://localhost:8983/solr/collection1/browse?q=*:*&rows=1000&wt=xml&pt=37.763649,-122.24313&sfield=store&fl=dist:geodist()
For instance, this request allows me to return a field "dist" which contains the distance of each entry to the stated point.

Resources