How to use boosting in solrnet while using default query? - solr-boost

I am using SolrNet to do query on my default search field and not on any specific field. How can I use Boost on a specific field in that case? Below is the code snippet.
List filter = BuildQuerySingleLine(arrParams);
var customer = solr.Query(parameters.SingleLineSearch, new QueryOptions
{
FilterQueries = filter,
SpellCheck = new SpellCheckingParameters { Collate = true },
OrderBy = new[] { new SortOrder("score", Order.DESC), SortOrder.Parse("score DESC") },
StartOrCursor = new StartOrCursor.Start(parameters.StartIndex),
Rows = parameters.NumberOfRows
});

At last I found the solution to this problem. For this I have used dismax request handler and passed the qf param value through SOLRNET.
With this you can pass the dynamic boost value to the SOLR query, on different fields.
var extraParams = new Dictionary<string, string> { { "qt", "dismax" }, { "qf", "fieldName^1 FieldName^0.6" } };
var customer = solr.Query(parameters.SingleLineSearch, new QueryOptions
{
StartOrCursor = new StartOrCursor.Start(parameters.StartIndex),
Rows = parameters.NumberOfRows,
},
ExtraParams = extraParams
});

According to this document: Querying and The DisMax Query Parser
var extraParams = new List<KeyValuePair<string, string>>();
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeQuery^10"));
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeOtherQuery^10"));
var options new new QueryOptions();
options.ExtraParams = extraParams; //Since my List implements the right interface
solr.Query(myQuery, options)
the bq parameter should be used to boost the Query. #Abhijit Guha has an excellent answer, to use the same idea on the Field: qf (Query fields with optional boosts)
QueryOptions options = new QueryOptions
{
ExtraParams = new KeyValuePair<string, string>[]
{
new KeyValuePair<string,string>("qt", "dismax"),
new KeyValuePair<string,string>("qf", "title^1")
},
Rows = 10,
Start = 0
};
Thank You!

Related

How to get current filters from PowerBi embedded export report

I am using powerbi embedded and I would like an export button similar to the one used on powerbi.com, that asks if you want to apply the current filters or not.
How can I get the current filters in javaScript in such a way that these can be passed to the back end, or to the javascript api to generate a PDF?
I am using the following code to generate the PDF currently, I just don't know how to get the current configuration current filters and current page selected in javaScript
public PowerBiExportViewModel CreateExport(Guid groupId,
Guid reportId,
IEnumerable<PowerBiReportPage> reportPages,
FileFormat fileFormat,
string urlFilter,
TimeSpan timeOut)
{
var errorMessage = string.Empty;
Stream stream = null;
var fileSuffix = string.Empty;
var securityToken = GetAccessToken();
using (var client = new PowerBIClient(new Uri(BaseAddress), new TokenCredentials(securityToken, "Bearer")))
{
var powerBiReportExportConfiguration = new PowerBIReportExportConfiguration
{
Settings = new ExportReportSettings
{
Locale = "en-gb",
IncludeHiddenPages = false
},
Pages = reportPages?.Select(pn => new ExportReportPage { PageName = pn.Name }).ToList(),
ReportLevelFilters = !string.IsNullOrEmpty(urlFilter) ? new List<ExportFilter>() { new ExportFilter(urlFilter) } : null,
};
var exportRequest = new ExportReportRequest
{
Format = fileFormat,
PowerBIReportConfiguration = powerBiReportExportConfiguration
};
var export = client.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest).Result;
You can go to PowerBi playground and play around with their sample report. Next to "Embed" button you have "Interact" and option to get filters. In response you get JSON with filters. If you are too lazy to go there, here is the code it created for me
// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];
// Get a reference to the embedded report.
report = powerbi.get(embedContainer);
// Get the filters applied to the report.
try {
const filters = await report.getFilters();
Log.log(filters);
}
catch (errors) {
Log.log(errors);
}

DynamoDB for .net: Table name in data model

I am using Dynamodb.net in my application.
I have the following code.
var creds = new BasicAWSCredentials(awsId, awsPassword);
var dynamoClient = new AmazonDynamoDBClient(creds,
awsDynamoDbRegion);
var context = new DynamoDBContext(dynamoClient);
List<ScanCondition> conditions = new List<ScanCondition>();
conditions.Add(new ScanCondition("Id", ScanOperator.Equal, myId));
var response = await context.ScanAsync<Data>(conditions).GetRemainingAsync();
return response;
My Data Model is as:
[DynamoDBTable("MyTable")]
public class Data
{
[DynamoDBHashKey]
public string Id{ get; set; }
public string Name { get; set; }
}
We are harcoding the table table name in our model "Data" as
[DynamoDBTable("MyTable")]
How can we not hardcode this. Is it possible to apply the table name in my actual code itself instead of giving in the model?
Thanks
Is OverrideTableName in DynamoDBOperationConfig what you are looking for ?
Description:
Property that indicates the table to save an object to overriding the
DynamoDBTable attribute declared for the type.
Example:
var x = await DbContext.LoadAsync<T>("hash", new DynamoDBOperationConfig {
OverrideTableName = "NewTableName",
IndexName = indexName
});
Also what you are looking for might be table prefix for every request of DbContext. It will append this prefix to every table. Useful if you want to isolate application specific tables like AppName-MyTable...
Example:
return new DynamoDBContextConfig
{
TableNamePrefix = "MyAppIdentifier",
ConsistentRead = false,
};
another option is to use different prefixes for the tables via
Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig.TableNamePrefix
Property that directs DynamoDBContext to prefix all table names with a specific string. > If property is null or empty, no prefix is used and default table names are used.
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/DynamoDBv2/TDynamoDBContextConfig.html
e.g.:
var credentials = new StoredProfileAWSCredentials("default");
var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
var config = new DynamoDBContextConfig{
TableNamePrefix = "Test."
};
var ctx = new DynamoDBContext(client, config);
await ctx.SaveAsync(item);

Caml Query returning null

I was trying to retrieve documents from document library using CAML Query, but this query returns null. Please help to solve this.
SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)oWebsite.Lists["SampleDocument"];
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><Eq><FieldRef Name='Author' /><Value Type='Text'>Name</Value></Eq></Where>");
SPListItemCollection collListItems = oDocumentLibrary.GetItems(query);
DataTable dt = collListItems.GetDataTable();
You can check Caml query in Caml Designer if the query is returning exact result or not.
Try with Camlex add CamlexNET using Nuget
using CamlexNET;
var caml = Camlex.Query().Where(x => ((string)x["Author"] == "Value").ToString();
var query = new SPQuery
{
Query = caml,
RowLimit = 5000
};
SPList list = web.Lists["Document"];
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem itm in items)
{
//var id = Convert.ToString(itm["ID"]);
}

Listing Activities via Web Services

I'm trying to reproduce the Activities page in Microsoft CRM 4.0 via web services. I can retrieve a list of activities, and I believe I need to use ActivityPointers to retrieve the entities but have so far been unsuccessful. Would I need to loop through every single entity returned from the first query to retrieve the ActivityPointer for it? And if so, how would I then get the "Regarding" field or Subject of the activity (eg: email).
The code to retrieve the activities is:
var svc = GetCrmService();
var cols = new ColumnSet();
cols.Attributes = new[] { "activityid", "addressused", "scheduledstart", "scheduledend", "partyid", "activitypartyid", "participationtypemask", "ownerid" };
var query = new QueryExpression();
query.EntityName = EntityName.activityparty.ToString();
query.ColumnSet = cols;
LinkEntity link = new LinkEntity();
//link.LinkCriteria = filter;
link.LinkFromEntityName = EntityName.activitypointer.ToString();
link.LinkFromAttributeName = "activityid";
link.LinkToEntityName = EntityName.activityparty.ToString();
link.LinkToAttributeName = "activityid";
query.LinkEntities = new[] {link};
var activities = svc.RetrieveMultiple(query);
var entities = new List<ICWebServices.activityparty>();
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse) svc.Execute(request);
//var pointers = new List<activitypointer>();
foreach (activityparty c in activities.BusinessEntities)
{
entities.Add(((activityparty)c));
//the entities don't seem to contain a link to the email which they came from
}
Not sure if I understand your problem, but the field "activityid" in the activitypointer object is the same activityid as the underlying activity (email, task, phonecall, etc). The regardingobjectid is the link to the regarding entity.
Heres what you need to get the equivalent of the Activities page
ColumnSet cols = new ColumnSet()
{
Attributes = new string[] { "subject", "regardingobjectid", "regardingobjectidname", "regardingobjectidtypecode", "activitytypecodename", "createdon", "scheduledstart", "scheduledend" }
};
ConditionExpression condition = new ConditionExpression()
{
AttributeName = "ownerid",
Operator = ConditionOperator.Equal,
Values = new object[] { CurrentUser.systemuserid.Value } //CurrentUser is an systemuser object that represents the current user (WhoAmIRequest)
};
FilterExpression filter = new FilterExpression()
{
Conditions = new ConditionExpression[] { condition },
FilterOperator = LogicalOperator.And
};
QueryExpression query = new QueryExpression()
{
EntityName = EntityName.activitypointer.ToString(),
ColumnSet = cols,
Criteria = filter
};
BusinessEntityCollection activities = svc.RetrieveMultiple(query);
foreach (activitypointer activity in activities)
{
//do something with the activity
//or get the email object
email originalEmail = (email)svc.Retrieve(EntityName.email.ToString(), activity.activityid.Value, new AllColumns());
}

DynamoDB UpdateItem Doesn't Work

This is pretty much straight out of the documentation (http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html), but like most things AWS, it just doesn't work and isn't documented well at all.
The following fails with "The document path provided in the update expression is invalid for update"
var messageId = "f244ed33-d678-4763-8f46-0f06514d5139"
var sequenceId = "00000000-0000-0000-0000-000000000000"
var now = DateTime.UtcNow;
var lastActivityThreshold = now.Subtract(TimeSpan.FromSeconds(10));
var response = client.UpdateItem(new UpdateItemRequest
{
TableName = "TheTable",
Key = new Dictionary<string, AttributeValue> { { "SequenceId", new AttributeValue { S = sequenceId } } },
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{":MessageId", new AttributeValue {S = messageId}},
{":Now", new AttributeValue {N = now.Ticks.ToString()}},
{":LastActivityThreshold", new AttributeValue {N = lastActivityThreshold.Ticks.ToString() }},
},
UpdateExpression = "REMOVE Messages[0] SET LastActivity = :Now",
ConditionExpression = "Messages[0] <> :MessageId AND (LastActivity <= :LastActivityThreshold OR attribute_not_exists(LastActivity))",
ReturnValues = ReturnValue.UPDATED_NEW
});
This is the document I'm trying to update (as seen in JSON view in the AWS Management Console):
{
"LastActivity": {
"N": "635753575712635873"
},
"Messages": {
"SS": [
"f244ed33-d678-4763-8f46-0f06514d5139",
"f668d2a5-3a4a-4564-8384-5b5a51c9bad3"
]
},
"SequenceId": {
"S": "00000000-0000-0000-0000-000000000000"
}
}
I've tried many variations of the code above, striaght down to removing all ExpressionAttributeValues and the ConditionExpression and just using REMOVE Messages[0], but it doesn't work and throws the same error.
It looks like you're trying to apply a document path to a non JSON item. There's no concept of ordering in a set, so if you want to remove the first item, you'll need to load it into memory and iterate over it. In short, you'll need to use a list in this case.