Solrnet query for Minimum Should Match(mm) - lucene

I am working on Solr version 4.10.2 with ASP.NET MVC.
I have performed one query in Solr like this:
http://localhost:8983/solr/MyCoreName/select?q=red+sony+mobile+bluetooth+&wt=json&indent=true&defType=edismax&mm=50%25&stopwords=true&lowercaseOperators=true
Update
I have performed a query with queryoptions like below:
options = new QueryOptions
{
Rows = pageSize,
Start = (pageIndex - 1) * pageSize,
FilterQueries = _solrQuery.ToArray(),
Facet = new FacetParameters
{
Queries = _solr.ToArray(),
MinCount = 1,
},
ExtraParams = new Dictionary<string, string>
{
{"qt", "edismax"},
{"mm","100%"}
},
SpellCheck = new SpellCheckingParameters { Query = keyword, Collate = true },
};
Then I use this options with below query in which I use LocalParams. Is there any mistake? Is LocalParams and ExtraParams works together?
private static ISolrOperations<MyClass> solr;
SolrQueryResults<MyClass> Results = new SolrQueryResults<MyClass>();
Results = solr.Query(new LocalParams { { "type", "edismax" }, { "qf", "Name^" + nameWeight + " Field1^" + Field1Weight + " Field2^" + Field2Weight " }, { "bq", "InStock:true^"+ flag }} + new SolrQuery(keyword), options);
How can I achieve this from my application using SolrNet? Using which parameter?
Please Advice!

Related

Importing a contact column into Podio

Which app_id should be used for importing into a contact column? Also, what should the mappings parameter look like?
podio.ImporterService.ImportAppItems(fileId, appId, new List<ImportMappingField> {
new ImportMappingField { FieldId = primaryFieldId, Unique = false, Value = new { column_id = "0" }},
new ImportMappingField { FieldId = contactfieldId, Unique = false, Value = new { column_id = "1", app_id = ???, mappings = new []{ ??? }}}
})
Edit:
I figured it out. Below is an example that works for me.
podio.ImporterService.ImportAppItems(373063497, 18803129, new List<ImportMappingField> {
new ImportMappingField {
FieldId = 148580608,
Unique = false,
Value = new { column_id = "0" }
},
new ImportMappingField {
FieldId = 148580614,
Unique = false,
Value = new {
mappings = new []{
new {
field_key = "mail",
unique = "true",
column_id = "4"
}
}
}
}
});
See the API documentation [1]
[1] https://developers.podio.com/doc/contacts

Sensenet Content Picker Customization

I created two custom content types, ProjectContract and PaymentRequest. Under PaymentRequest, I have a reference field Contract which I would like to use to reference ProjectContract. When I am creating/changing PaymentRequest, I need the following:
how can I initialize Content Picker to display ContractNumber field of available ProjectContracts?
how can I display selected ProjectContract's ContractNumber under ReferenceField Grid control?
The SN js code and the mvc contains/returns fix field values. I did not find any setting where I can add custom fields to show.
First of all, what is the version of that SN package, because the oData.svc request will not work on older versions. It is available from 6.2.
About the oData, here is a link: http://wiki.sensenet.com/OData_REST_API
There is another way to solve it, but with this, you need to modify the existion SN codes.
You need to copy (" /Root/Global/scripts/sn/SN.Picker.js ") file into your skin folder with the same structure. (" /Root/Skins/[yourskinfolder]/scripts/sn/SN.ReferenceGrid.js ")
You need to copy (" /Root/Global/scripts/sn/SN.ReferenceGrid.js ") file into your skin folder as well.
Do not modify the original SN file, because it will be overwrite after an SN update.
Next step: copy the following code to line 1068, before the ("$grid.jqGrid({") line, into the InitGrid function.
...
var neededTypeName = "ProjectContract";
var neededFieldName = "ContractNumber";
var findField = false;
o2 = (function () {
var result = [];
var itemArray = [];
$.each(o2, function (index, el) {
el.ContentField = "";
result.push(el);
if (el.ContentTypeName == neededTypeName) {
itemArray.push([index, el.Path]);
findField = true;
}
});
if (findField) {
$.each(itemArray, function (itemIndex, itemElArray) {
var itemId = itemElArray[0];
var itemEl = itemElArray[1];
var thisLength = itemEl.length;
var thislastSplash = itemEl.lastIndexOf("/");
var thisPath = itemEl.substring(0, thislastSplash) + "('" + itemEl.substring(thislastSplash + 1, thisLength) + "')";
$.ajax({
url: "/oData.svc" + thisPath + "?metadata=no$select=Path," + neededFieldName,
dataType: "json",
async: false,
success: function (d) {
result[itemId].ContentField = d.d[neededFieldName];
}
});
});
colNames.splice(6, 0, "ContentField");
colModel.splice(6, 0, { index: "ContentField", name: "ContentField", width: 100 });
return result;
}
return o2;
})();
...
$grid.jqGrid({
...
The "neededTypeName" may contains your content type value, and the "neededFieldName" may contains the field name you want to render.
The other will build up the grid.
This will modify the Content picker table.
You need to add this code into the GetResultDataFromRow function, at line 660 before the return of the function.
...
if (rowdata.ContentField != undefined) {
result.ContentField = rowdata.ContentField;
}
...
This will add the selected item properties from the Content picker to the reference field table.
Then you need to open the SN.ReferenceGrid.js and add the following code into the init function before the "var $grid = $("#" + displayAreaId);"
var neededTypeName = "CustomItem2";
var neededFieldName = "Custom2Num";
var findField = false;
var alreadyAdded = false;
var btnAttr = $("#"+addButtonId).attr("onClick");
if (btnAttr.indexOf(neededTypeName) > -1) {
alreadyAdded = true;
colNames[4].width = 150;
colModel[4].width = 150;
colNames.splice(3, 0, "ContentField");
colModel.splice(3, 0, { index: "ContentField", name: "ContentField", width: 60 });
}
initialSelection = (function () {
var result = [];
var itemArray = [];
$.each(initialSelection, function (index, el) {
el.ContentField = "";
result.push(el);
if (el.ContentTypeName == neededTypeName) {
itemArray.push([index, el.Path]);
findField = true;
}
});
if (findField) {
$.each(itemArray, function (itemIndex, itemElArray) {
var itemId = itemElArray[0];
var itemEl = itemElArray[1];
var thisLength = itemEl.length;
var thislastSplash = itemEl.lastIndexOf("/");
var thisPath = itemEl.substring(0, thislastSplash) + "('" + itemEl.substring(thislastSplash + 1, thisLength) + "')";
$.ajax({
url: "/oData.svc" + thisPath + "?metadata=no$select=Path," + neededFieldName,
dataType: "json",
async: false,
success: function (d) {
result[itemId].ContentField = d.d[neededFieldName];
}
});
});
if (!alreadyAdded) {
colNames.splice(3, 0, "ContentField");
colModel.splice(3, 0, { index: "ContentField", name: "ContentField", width: 100 });
}
return result;
}
return initialSelection;
})();
I hope this will help but the SN version should be helpful.

Create complex JSON objects

Hi I have a question to the azure mobile Service custom API script.
I have a custom script to create a JSON Response.
First step was to get flat objects.
Thsi is my code:
var sql = "SELECT [Project].[id] AS [ID]," +
"[Project].[Name] AS [Name]," +
"FROM [Project]";
request.service.mssql.query(sql, [], {
success: function(results) {
if (results.length === 0) {
response.json(statusCodes.OK, results);
return;
}
var resultSet = [];
results.forEach(function(poi) {
resultSet.push(
{
ID: poi.ID,
Name: poi.Name,
RelatedObjects:
{
[
**???**
]
},
});
})
response.json(statusCodes.OK, resultSet);
}
});
This works very well. Now I want to extend my result objects by some sub objects from a releated table. But not simple singel sub properties (this is easy via join), I want to add collections of sub properties selected from another table.
But I don't know how to get the second query into my code? :(
I think it has to be on "???" marked position.
I want to use this JSON self creating code because my result sets are much more complex as the example shows.
Please help!
Ok I solve it with this messi code...
I'm sure there is a more elegant way to do this but I don't found it yet.
var sql = "SELECT [Project].[ID]" +
",[Project].[Name]" +
"FROM [Project]";
var sql2 = "SELECT [ID]" +
",[UniqueSN]" +
",[Name]" +
"FROM [DataLogger]" +
"WHERE [DataLogger].[ProjectID] = ?";
request.service.mssql.query(sql, [id], {
success: function(results) {
var resultSet = [];
results.forEach(function(poi) {
var loggerResultSet = [];
request.service.mssql.query(sql2, [poi.ID], {
success: function(results2) {
results2.forEach(function(logger) {
loggerResultSet.push(
{
ID: logger.ID,
Name: logger.Name,
UniqueSN: logger.UniqueSN,
});
})
resultSet.push(
{
ID: poi.ID,
Name: poi.Name,
Logger: loggerResultSet,
});
response.json(statusCodes.OK, resultSet);
console.log(JSON.stringify(resultSet));
}
});
})
}
});

How to use eval on jquery plugin variable?

I'm using pnotify, the JQuery plugin.
I want to shorten this code:
$.pnotify.defaults.styling = "jqueryui";
$.pnotify.defaults.delay = 1500;
$.pnotify.defaults.title = 'Error'
$.pnotify.defaults.mouse_reset = false;
$.pnotify.defaults.history = false;
Into something like this:
var darray = { 'styling':'\'jqueryui\'', 'delay':'1500', 'title':'\'Error\'', 'mouse_reset':'false', 'history':'false' };
$.each(darray, function(option,choice){
eval("var $.pnotify.defaults." + option + "=" + choice + ";");
});
However, despite trying all sorts of things, I have failed. Here's some of the things I've tried:
var darray = { 'styling':'\'jqueryui\'', 'delay':'1500', 'title':'\'Error\'', 'mouse_reset':'false', 'history':'false' };
$.each(darray, function(option,choice){
eval("var $.pnotify.defaults." + option + "=" + choice + ";");
});
JSONstring='var $.pnotify.defaults.' + option + "=" + choice + ";";
$.parseJSON(JSONstring);
string99 = 'var $\.pnotify\.defaults\.' + option
$.parseJSON('{string99=choice}');
option='var $.pnotify.defaults.'+option;
var JSONObject= {'option':choice};
$.parseJSON(JSONObject);
Fiddle: http://jsfiddle.net/morossive/kayKn/
You could try this (untested, but you get the idea):
var darray = {
styling: 'jqueryui',
delay: 1500,
title: 'Error',
mouse_reset: false,
history: false
};
for (var mbr in darray) {
$.pnotify.defaults[mbr] = darray[mbr];
}
Because JavaScript treats objects like hashtables, we can iterate over their "keys" (for (var mbr in darray)) and assign new values to new keys in objects. For example:
var obj = {...};
// The following are equivalent:
obj.x = 5;
obj['x'] = 5;
However, I think there may be an even more elegant solution to your problem (don't use this if you are worried about overwriting preexisting values in $.pnotify.defaults, however):
$.pnotify.defaults = {
styling: 'jqueryui',
delay: 1500,
title: 'Error',
mouse_reset: false,
history: false
};
I know you asked how to use eval to solve this, but I think in general any alternative to using eval is probably better.

jqGrid ASP.NET MVC4 initial sort

I'm using jqGrid as TreeGrid with ASP.NET MVC4 and have one problem:
My Model:
OrdersGrid = new JQGrid
{
Columns = new List<JQGridColumn>()
{
new JQGridColumn
{
DataField = "MeasureId",
// always set PrimaryKey for Add,Edit,Delete operations
// if not set, the first column will be assumed as primary key
PrimaryKey = true,
Visible = false,
Sortable = false
},
new JQGridColumn
{
DataField = "Name",
Width = 100,
Sortable = true
},
new JQGridColumn
{
DataField = "Symbol",
Width = 100
},
},
Width = Unit.Pixel(640),
Height = Unit.Percentage(100),
TreeGridSettings = new TreeGridSettings
{
Enabled = true
},
SortSettings = new SortSettings
{
AutoSortByPrimaryKey = false,
InitialSortColumn = "Name",
InitialSortDirection = SortDirection.Asc
}
};
My Controller:
public JsonResult DataRequested()
{
// Get both the grid Model and the data Model
// The data model in our case is an autogenerated linq2sql database based on Northwind.
var gridModel = new NavigatorModel();
...
var hierarchyRows = from measure in measures
select new
{
MeasureId = measure.MeasureId,
Name = measure.Name,
Symbol = measure.Symbol,
//ParentID = measure.ParentMeasureId != null ? measure.ParentMeasureId.ToString() : "",
tree_loaded = true,
tree_parent = measure.ParentMeasureId,
tree_level =LoadAllRowsExpanded_GetRowLevel(measure.ParentMeasureId, measures),
tree_leaf = LoadAllRowsExpanded_IsLeafRow(measure.MeasureId, measures),
tree_expanded = true
};
//var dataModel = new
// return the result of the DataBind method, passing the datasource as a parameter
// jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
return gridModel.OrdersGrid.DataBind(hierarchyRows.AsQueryable());
}
As above you can see that I'm setting the AutoSortByPrimaryKey set to false, but when the page is loaded, grid looks like that:
When I click on one of columns (Name or Symbol) to sort everything becomes fine - the Measure which is wrongly displayed goes under it's parent.
I have tried also with event to sort after "gridInitialize" but also no success.
Any ideas?