I am using Solr 8.1.1.
Now I have a date field "_created", i need to facet on this field, so I get the document count for "past month", "past 3 months", "past 6 months", "past year".
I managed to get the facets for "past 3 months" and "past 6 months" using one range faceting . However, I could not facet on the same field for "past month", "past year". I assume these would be another two range faceting.
Could anyone please help on this? really appreciated!
Related
On Solr, I would like to get facets of a field date but according to a day of the week,
for example, if I have 3 records with the following values on the date field:
16/11
22/11
23/11
I would like to get the following facet:
Sunday: 2,
Monday: 1
Is it possible?
Solr does not having anything which could provide you the day of the week based on the date.
You need to index the weeks data in a separate field.
Where your fields would be holding the values like SUNDAY, MONDAY etc..
Once you have this field and indexed the data in solr.
Then you could be able to achieve the faceting based on the weeks.
I am trying the range facet on a field called popularity .
facet=true&facet.range=popularity&facet.range.gap=1&facet.range.start=1&facet.range.end=5.001
I am getting the below result
"popularity":{
"counts":[
"1.0",3,
"2.0",0,
"3.0",8,
"4.0",21,
"5.0",23],
But when I am adding the filter query - fq=popularity:[3 TO 4} , I am getting 11 results, I see all the results are having popularity between 3 to 4, but why when faceting on popularity it is under counting the items ?
Thanks
I am using Apache Solr 8 with products as documents. Each document includes sales within the last X days that I want to boost, as well as a title and other fields.
Say productA has been sold 5 times, I want to boost it with score+10; a productB has been sold 50 times, I want to boost the score by 30.
I tried to use a boostFunction that looks like (edismax query parser)
q=Coffee&qf=title&bf=if(lt(sales,5),10,if(lt(sales,50),30))
Solr now returns documents that have nothing to do with my "Coffee"-Query but just match the boostfunction. There are even results with score "0".
E.g.
Rank;Score;Sales;Title
1;58.53;55;Coffee big
2;38.11;50;Coffee
3;30;55;Tea
Any idea to get rid of those "only boost function"-matches?
Found the answer!
My Query-Fields actually included boostings like
&qf=title^2 longDescription^0 whatever^0...
Instead of excluding the results found in those 0-boosted fields, solr adds them and matches with - well score 0.
When I remove the 0-boostings, everything works as intended.
My Solr schema has a fieldtype tdate of class solr.TrieDateField
<field name="timestamp" type="tdate" indexed="true" stored="true" default="NOW"/>
So when I add documents to the index the timestamp field looks like this:
"timestamp": "2015-11-03T15:52:51.418Z"
Now to filter all documents of the current year I add a range filter to the query:
/select?q=*:*&fq=timestamp:[NOW/YEAR TO NOW/YEAR+1YEAR}
But how would I filter for any year, let's say 2014?
The only thing I could come up with was to create a date range spanning the entire year from the first to the last millisecond:
/select?q=*%3A*&wt=json&indent=true&fq=timestamp:[2014-01-01T0:00:00.000Z TO 2014-12-31T23:59:59.999Z}
Is there a way to get to the same result by just passing in the year as a four digit string?
After some research I believe it is not possible for a TrieDateField to filter on year granularity, other than the proposed solution. You would need a solr.DateRangeField for that.
However it is possible to add a single argument to the query string telling Solr how to conceive NOW, which is an epoch time (milliseconds) chosen in the year we want to filter by.
&fq=timestamp:[NOW/YEAR TO NOW/YEAR+1YEAR}&NOW=1388534400000
1388534400000 represents midnight the 1st of january 2014. But any other epoch timestamp representing a moment in 2014 will be fine.
https://cwiki.apache.org/confluence/display/solr/Working+with+Dates
I want to show max 5 results(docs) from each facets on first page. How can I achieve it in Solr 4.x
for e.g I have thousands of matching products(docs) in TV, Music System, Books etc categories. If I search "Music" keyword, I should get max 5 matching results(docs) from all categories.
Thanks in advance.
Edit: I want to set limit on results(docs) not on facet list. And this limit is on each facet not on all result. If there are 3 categories, 15 results(docs) can be display on page, if 4, max 20 results(docs) can be display.
To limit search results you need to use param rows=5
For more info - http://wiki.apache.org/solr/CommonQueryParameters#rows