Solr 6.2.1 combine sort - sorting

I hava a question with solr sort. I load some data into singleinstance solr with two field :
field name="timestamp" type="long" indexed="true" stored="true"
field name="sequence" type="int" indexed="true" stored="true"
then I query it with the
url:http://localhost:8080/solr/second/select?q=*%3A*%0A&sort=timestamp+asc%2Csequence+asc+&fl=timestamp%2Csequence&wt=json&indent=true
but the result is that
"sort":"timestamp asc,sequence asc ",
"wt":"json"}},
"response":{"numFound":3000,"start":0,"docs":[
{
"timestamp":1000001210375,
"sequence":5},
{
"timestamp":1000001995899,
"sequence":9},
{
"timestamp":1000002980757,
"sequence":7},
{
"timestamp":1000005311535,
"sequence":5},
{
"timestamp":1000007582420,
"sequence":0},
{
"timestamp":1000007754398,
"sequence":0},
{
"timestamp":1000007820065,
"sequence":5},
{
"timestamp":1000008875407,
"sequence":7},
{
"timestamp":1000009462491,
"sequence":5},
{
"timestamp":1000010136221,
"sequence":1}]
}}
It sort timestamp in right way, but not sort sequence in asc
Anyone know why?thanks..

It sorts by timestamp first then sequence, so it will only sort by the sequence value when timestamp values are the same.

Related

muddatagrid - access filtered records programmatically

I have a muddatagrid like this which has got the filters and i am able to filter it. Programmatically how can I get the filtered records?
<MudDataGrid Items="#Elements" #ref="dg" Filterable="true" FilterCaseSensitivity=DataGridFilterCaseSensitivity.CaseInsensitive>
<Columns>
<Column T="RequestInfo" Field="RequestId" Title="Request ID" />
<Column T="RequestInfo" Field="ProjectName" Title="Project Name" />
<Column T="RequestInfo" Field="RequestCreatedBy" Title="Created By" />
</Columns>
<NoRecordsContent>
<MudText>No matching records found</MudText>
</NoRecordsContent>
<PagerContent>
<MudDataGridPager T="RequestInfo" />
</PagerContent>
</MudDataGrid>
#code
{
MudDataGrid<RequestInfo> dg;
private async Task somefunction()
{
//this function is invoked after pressing a button in the page and all the filters have been applied.
List<RequestInfo> ll = dg.FilteredItems as List<RequestInfo>;
}
}
This function returns always 0 items. How Do I get to see only the filtered items programmatically?
dg.FilteredItems probably isn't a List when you apply filters. Instead of ... as List<RequestInfo>, call .ToList() on it:
#code
{
MudDataGrid<RequestInfo> dg;
private async Task somefunction()
{
List<RequestInfo> ll = dg.FilteredItems.ToList();
...
}
}
whats the difference between dg.FilteredItems.ToList(); and dg.FilteredItems as List;
The code:
dg.FilteredItems as List<RequestInfo>
is equivalent to:
dg.FilteredItems is List<RequestInfo>
? (List<RequestInfo>)dg.FilteredItems
: (List<RequestInfo>)null
This means that if the IEnumerable dg.FilteredItems is not a List, null will be returned.
The code:
dg.FilteredItems.ToList()
will return a new List, no matter what IEnumerable dg.FilteredItems behind the scenes is (an array, a IList, a ISet, ...)

Solr boost query by field value and inside newest date

We have the following setup in our schema.xml:
<field name="last_modified" type="date" indexed="true" stored="true" multiValued="false" omitTermFreqAndPositions="true"/>
...
<field name="prefix" type="string" indexed="true" stored="true" omitTermFreqAndPositions="true"/>
Our goal is to sort the docs by
prefix=9999 with newest docs (last modified) first
prefix=1004 or prefix=1005 with newest docs (last modified) first
Our code:
{!boost b=recip(ms(NOW,last_modified),3.16e11,1,1)}prefix:9999^1000000 OR {!boost b=recip(ms(NOW,last_modified),3.16e-11,1,1)}prefix:1004^600000 OR {!boost b=recip(ms(NOW,last_modified),3.16e-11,1,1)}prefix:1005^600000
Result:
The query above does not work as expected!
We thought that omitTermFreqAndPositions=true will force to prevent ITF and the scoring should work. But it does not seem so!
Please help us with this :-)
So we found a solution!
Create your own Similarity (a simple java class)
For a better and simpler descriptions how, please read How to compile a custom similarity class for SOLR / Lucene using Eclipse
The class we used
package com.luxactive;
import org.apache.lucene.index.FieldInvertState;
import org.apache.lucene.search.similarities.DefaultSimilarity;
public class MyNewSimilarityClass extends DefaultSimilarity {
#Override
public float coord(int overlap, int maxOverlap) {
return 1.0f;
}
#Override
public float idf(long docFreq, long numDocs) {
return 1.0f;
}
#Override
public float lengthNorm(FieldInvertState arg0) {
return 1.0f;
}
#Override
public float tf(float freq) {
return 1.0f;
}
}
Create a simple jar with your Similarity
Copy the jar to any folder into your solr server, we used:
SOLRFOLDER/solr-4.8.0/example/solr/dih
The next steps need to be done to every collection you have!
Edit the solrconfig.xml at: SOLRFOLDER/solr-4.8.0/example/solr/collection/conf/solrconfig.xml
Add <lib dir="../dih" regex=".*\.jar" /> to import the custom jar
Edit the schema.xml in the same folder
Add the following
<!-- DEFAULT Factory for custom com.luxactive.MyNewSimilarityClass -->
<similarity class="solr.SchemaSimilarityFactory"/>
<!-- TYPE String -->
<fieldType name="no_term_frequency_string" class="solr.StrField" sortMissingLast="true" >
<similarity class="com.luxactive.MyNewSimilarityClass"/>
</fieldType>
<!-- TYPE Date -->
<fieldType name="no_term_frequency_date" class="solr.TrieDateField" sortMissingLast="true" >
<similarity class="com.luxactive.MyNewSimilarityClass"/>
</fieldType>
<!-- TYPE Int-->
<fieldType name="no_term_frequency_int" class="solr.TrieIntField" sortMissingLast="true" >
<similarity class="com.luxactive.MyNewSimilarityClass"/>
</fieldType>
Here you define your own field types (int, string and date) that use the new Similarity class which will return a boost value like defined in the MyNewSimilarityClass.
Now edit the fields you want to use your custom Similaritry by setting theyr type to one you created.
From: <field name="last_modified" type="date" indexed="true" stored="true" multiValued="false" />
To: <field name="last_modified" type="no_term_frequency_date" indexed="true" stored="true" multiValued="false" />
Restart the solr server and enjoy your boosting :)

how to sort the field in the mongo document which is inside array

I have below a structured Mongo Document:
{
"_id": value,
"imageShared": {
"imageid": value,
"commentdatadoc": [
{
"whocommented": value,
"commenttext": value,
"commenttimestamp": isodate(111)
},
{
"whocommented": value,
"commenttext": value,
"commenttimestamp": isodate(444)
},
{
"whocommented": value,
"commenttext": value,
"commenttimestamp": isodate(222)
}
]
}
};
Here I want to sort the field commenttimestamp desc. I tried the way below but it is not working...
Query getComments = new Query();
getComments.addCriteria(Criteria.where("imageShared.imageId").is(imageId)).
with(new Sort(Sort.Direction.DESC,"imageShared.commentDataDoc"));
SharedMediaCollec sharedMediaCollec = mongoTemplate.findOne(getComments, SharedMediaCollec.class);
Does anyone have an idea how to sort a document field which is inside array?
When you need to get all documents anyway, it might be far easier to do the sorting in C# after you received the data from MongoDB. An elegant way to do this automatically would be to represent the commentdatadoc array in your C# object with a SortedSet.
But when you definitely want a database-sided solution, you can do it with an aggregation pipeline consisting of a $match-step, a $unwind step and a $sort step. To perform an aggregation with the C# driver, call collection.Aggregate and then set the aggregation stages at the returned IAggregateFluent interface.

Adding Programmatically datasource / dataset to LocalReport

Is there any way to add programmatically a datasource / dataset to a Microsoft.Reporting.WebForms.LocalReport when the report-XmlFile (*.rdlc) has no datasource / dataset definitions at design-time?
This works if I already have a datasource / dataset definition in my *.rdlc
C#
public byte[] RenderReport(string reportName, string reportFormat)
{
LocalReport report = LoadReport(reportName);
//Has same name like DataSet in *.rdlc
ReportDataSource rds = new ReportDataSource("DataSet1", getData());
report.DataSources.Clear();
report.DataSources.Add(rds);
return report.Render(reportName);
}
private DataTable getData()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ID",typeof(System.String)));
dt.Columns.Add(new DataColumn("NAME", typeof(System.String)));
dt.Rows.Add(new string[] { "1", "Me" });
return dt;
}
*.rdlc
<DataSources>
<DataSource Name="DataSource1">
<ConnectionProperties>
<DataProvider>System.Data.DataSet</DataProvider>
<ConnectString>/* Local Connection */</ConnectString>
</ConnectionProperties>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</Query>
<Fields>
<Field Name="ID">
<DataField>ID</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="NAME">
<DataField>NAME</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
But if I remove the datasource / dataset definition I get
{Microsoft.Reporting.DefinitionInvalidException: The definition of the
report '' is invalid. --->
Microsoft.ReportingServices.ReportProcessing.ReportPublishingException:
The Value expression for the text box ‘Textbox1’ refers to the field
‘ID’. Report item expressions can only refer to fields within the
current dataset scope or, if inside an aggregate, the specified
dataset scope. Letters in the names of fields must use the correct
case.}
Do I always have to create something like a "Dummy"-DataSource/DataSet or do I miss something in my code?
I hope there is another solution as manipulating the XML before rendering-process, any ideas?
Thanks!
You can't leave RDLC witout DataSets, if you are using it and RDLC is embedded in your project.
Either you leave DataSet fixed and change only it's items either try to load report definition from XML
// Valid XML with dynamic DataSources and DataSets
string s = #"<?xml version=""1.0"" encoding=""utf-8""?><Report ...>...</Report>";
report.LoadReportDefinition(new MemoryStream(Encoding.UTF8.GetBytes(s)));
return report.Render(reportName);

Solrnet date conversion issue

We are using SolrNet API to Index and Search a set of documents which contains three date fields: Date1, Date2, Date3. The C# class has the following definitions for the three fields
public DateTime? Date1{ get; set; }
public DateTime? Date2{ get; set; }
public DateTime? Date3{ get; set; }
The Solr schema definition is as follows:
<field name="Date1" type="date" indexed="false" stored="true" required="false"/>
<field name="Date2" type="date" indexed="false" stored="true" required="false"/>
<field name="Date3" type="date" indexed="false" stored="true" required="false"/>
When we execute a query with a document which has already been indexed, we get the following values returned in the SolrAdmin interface:
<date name="Date1">0001-01-01T00:00:00Z</date>
<date name="Date2">2010-04-10T08:21:18.281Z</date>
<date name="Date3">2007-12-01T03:09:41.093Z</date>
But when we inspect the C# object which gets returned with the SolrQueryResults, it shows the following:
Date1 : {01-01-0001 12:00:00 AM}
Date2 : null
Date3 : null
The first date is being represented as the datetime min value which is expected. But why are the other dates getting null values when these are valid dates in the UTC format?
Is it better to store the date fields as strings in Solr and use a copy field to store it in the solr date format and use this field for date range queries?
Check that you are returning the Date2 and Date3 fields in your SolrNet query results. e.g. Make sure that you are not limiting the fields with &fl parameter via SolrNet Fields QueryOptions or using a requestHandler on the Solr instance that is filtering fields and does not include those fields.
Please try the below code, Hope it helps
using SolrNet;
public List<ISolrQuery> BuildFitlerQuery(DateTime StartDate, DateTime EndDate, string FiledName)
{
var filter = new List<ISolrQuery>();
if (EndDate.Year != 1)// Will create query when end date value is also send
filter.Add(new SolrQueryByRange<DateTime?>(FiledName, StartDate, EndDate));
else
filter.Add(new SolrQueryByRange<DateTime?>(FiledName, StartDate, null));
return filter;
}

Resources