I want to retrieve the existing field groups (from root) and display them in a dropdown list.
I'm using this code to retrieve all the columns (and display which group they're belonging to):
var web = clientContext.Web;
FieldCollection rootFields = web.Fields;
clientContext.Load(
rootFields,
fields => fields
.Include(field => field.Group)
);
clientContext.ExecuteQuery();
foreach (Field _fields in rootFields)
{
fieldsList.Add(new SelectListItem { Text = _fields.Group });
}
This shows a few hundred groups (duplicates ofc), I want to narrow it down to just the few groups that exist, and sort out the duplicates. Or is there another way to do this?
You can do it via Linq:
Distinct will sort the duplicates out of your result.
var results = rootFields.ToList().Select(field => field.Group).Distinct();
foreach (var_group in results)
{
fieldsList.Add(new SelectListItem { Text = _group });
}
Related
I am seeing a very strange behaviour from the Sitecore 7.1 Search when ordering by a string field. The code is something like this:
var indexableItem = new SitecoreIndexableItem(Sitecore.Context.Item);
var searchIndex = ContentSearchManager.GetIndex(indexableItem);
var context = searchIndex.CreateSearchContext();
var results = new List<Item>();
var count = 0;
var totalSearchResults = 0;
var contactColleagues = context.GetQueryable<SearchResultItem>()
.FirstOrDefault(x => x.ItemId == Sitecore.Context.Item.ID);
if (contactColleagues != null)
{
var items = contactColleagues.GetDescendants<ColleagueSearchResultItem>(context)
.Where(x => x.TemplateId == Templates.Colleague);
items = items.OrderBy(x => x.Surname);
var resultItems = items.Page(this.PageNumber, PageSize).GetResults();
}
This all works as expected and returns my dataset ordered by surname as expected. That is until a certainly individual comes along who's surname is "Or". Now Sitecore returns this persons name at the start of the list, no matter what we do.
After some testing I found the same issue happened if I decided to call someone "Andy And", this would appear at the being of the list before "Jeff Aardvark".
I'm assuming this is a bug in the way the data is being presented to the Lucene index.
Has anyone come across this, or have any thoughts about how this could be worked around?
Thanks in advance.
I think you have a problem with stop words. The default analyzer removes them when the item is crawled. You can however prevent this behaviour.
This post explains how to to turn off the stop words filter:
http://blog.horizontalintegration.com/2015/01/08/sitecore-standard-analyzer-turn-off-the-stop-words-filter/
If you look at the surname field in the index using Luke (https://code.google.com/p/luke/) is the value blank? It sounds like potentially dangerous query values are being stripped out either at the index level or as they are being loaded from the index.
I am creating a dashboard with Google Viz and am having trouble with the select event when the data is filtered. It works fine when the page loads and nothing is filtered. However, after filtering the data, it does not select the correct row from the dataTable on 'select' events. Here is my jsfiddle and my listener:
http://jsfiddle.net/5E7zX/1/
google.visualization.events.addListener(rBubbleChart, 'select', function() {
var selection = rBubbleChart.getChart().getSelection();
var item = selection[0];
var school = data.getValue(item.row, 1);
alert('school is: ' + school);
});
When it is unfiltered, the alert box displays the school that was selected. However, when it is filtered on a school, the alert box does not display the correct school (the exception is Air Base Elem because that is the first school in the list).
Any thoughts on how to get the correct row of data once the data is filtered? Thanks.
The selection indices refer to the data as seen by the chart, which is not necessarily the same as your base DataTable, so you need to check against the data used by the chart by calling the getDataTable method to fetch the chart's data, and then referencing that when getting a value:
google.visualization.events.addListener(rBubbleChart, 'select', function() {
var selection = rBubbleChart.getChart().getSelection();
// get the data used by the chart
var dt = rBubbleChart.getDataTable();
// test selection array length, since it can be zero when a user deselects a point!
if (selection.length) {
var item = selection[0];
var school = dt.getValue(item.row, 1);
alert('school is: ' + school);
}
});
I have a table in Dynamo with a hash & range index plus a secondary global index with just a hash. If I try to Query or Save an object I get the following error:
Number of hash keys on table TableName does not match number of hash keys on type ObjectModelType
(Replacing TableName and ObjectModelType with the actual table and model type)
I have the hash properties (both the primary and secondary) decorated with DynamoDBHashKey
Googling the error turns up exactly zero results
Update: Ok, so not exactly zero, obviously it now returns this question!
Update the second: I've tried using the helper API & it works just fine, so I am assuming at this point that the Object Persistence Model doesn't support Global Secondary Indexes
I encountered the same problem and found FromQuery worked, although QueryFilter is actually from the DocumentModel namespace:
var queryFilter = new QueryFilter(SecondaryIndexHashKeyColumn, QueryOperator.Equal, "xxxx");
queryFilter.AddCondition(SecondaryIndexRangeKeyColumn, QueryOperator.LessThan, DateTime.Today);
var items = context.FromQuery<MyItem>(new QueryOperationConfig { IndexName = SecondaryIndexName, Filter = queryFilter }).ToList();
Thank you Brendon for that tip! I was able to adapt it to get deserialization of a multiple result set.
var queryFilter = new QueryFilter(indexedColumnName, QueryOperator.Equal, targetValue);
Table table = Table.LoadTable(client, Configuration.Instance.DynamoTable);
var search = table.Query(new QueryOperationConfig { IndexName = indexName, Filter = queryFilter });
List<MyObject> objects = new List<MyObject>();
List<Document> documentSet = new List<Document>();
do
{
documentSet = search.GetNextSetAsync().Result;
foreach (var document in documentSet)
{
var record = JsonConvert.DeserializeObject<MyObject>(document.ToJson());
objects .Add(record);
}
} while (!search.IsDone);
Thanks x1000!! :)
I have an item structure that doens't correspond to "documents" in the standard Sitecore sense. It corresponds to data items.
One of the relationships that my items have is the following:
Person -> State -> Country
Where a Person has a link field to a State and state's have link fields to a Country.
My question is: How would one write a query to retrieve all of the People who have an eventual link to a Country of a certain abbreviation?
I'm stumped as to how to do it in Sitecore Query. My current solution is using LINQ and several queries.
Assuming that the links between these items where created using a Reference field, such as a Droplink, Treelist, Droptree, etc., you can traverse the references/referrers using the Sitecore Links database.
Here is an example (untested) that starts with a country item and fetches any referring states. The same query is performed on the states to fetch any referring people. The results are added to a generic List<Item> collection.
List<Item> peopleList = new List<Item>();
var countryReferences = Globals.LinkDatabase.GetReferences(countryItem);
var referringStates = countryReferences.Select(c => c.GetTargetItem()).Where(c => c.Template.Key == "state");
foreach (var state in referringStates)
{
var stateReferences = Globals.LinkDatabase.GetReferences(state);
var referringPeople = stateReferences.Select(s => s.GetTargetItem()).Where(s => s.Template.Key == "person");
foreach (var person in referringPeople)
{
peopleList.Add(person);
}
}
I was wondering whether I can obtain a select list with a data-filter. I am aiming to allow the user to select list of friends (obtained via Facebook) to send invitations to.
I found that in the list view we can have a search filter bar; problem: cant multiple select
http://jquerymobile.com/test/docs/lists/lists-search.html
And in the form list, we can select multiple items; problems: no search filter
http://jquerymobile.com/test/docs/forms/selects/ - under "An example of a select with a long list of options:"
I want to find a combination of both, as in have a page with a big list of items that I can select multiple items (in this case friends) and have the ability to search thru them.
Thanks!
Select Menu.
Search Filter Bar
A function to copy the select menu value to the Search Filter Bar
In the same function, simulate Keyup to run the filter and clear Search Filter Bar
$( "#seleMenuID" ).bind( "change", function() {
var val = $('select option:selected').val();
$('.ui-input-text').val(val); //put value of select menu on search bar Filter
function simulateKeyUp(character) { //simulate keyup to run the filter
jQuery.event.trigger({ type : 'keyup', which : character.charCodeAt(0) });
}
$(function() {
$('body').keyup(function(e) {
});
simulateKeyUp("e");
$('.ui-input-text').val(''); //clear filter search bar
});
});
You could create a listview and add a checkbox to each entry in the list. That way, when the user sees a filtered list, they can additionally check the items they want to select.