Showing posts with label grouping. Show all posts
Showing posts with label grouping. Show all posts

Thursday, December 21, 2017

Solr 6.6.2 Grouped Query

Leave a Comment

With having the following setup on Solr 6.6.2:

A Solr cloud collection with documents having the fields ID, ContactId, Properties up and running and unique key on id.

There can be multiple documents with the same ContactId.

Each of the contact documents has a text field properties containing a line of text. Properties field is indexed with separation by ',' so that e.g. Properties:Green hits.

For example:

+----+-----------+--------------+ | ID | ContactId |  Properties  | +----+-----------+--------------+ |  1 | C1        | Blue,Green   | |  2 | C1        | Blue,Yellow  | |  3 | C2        | Green,Yellow | +----+-----------+--------------+ 

Now I need to find all ContactIds where Properties has "Green" AND "Yellow" where it is allowed that this query matches over all documents of this ContactID. So the result would be in that case C1, C2.

I tried to group the results but still I am not able to query on the grouped result.

group=true&group.field=ContactId&group.query=(Green AND Yellow)&q=(Green OR Yellow) 

The idea I followed was query(q) for getting all documents which has either Green OR Yellow than do the grouping on the group.field ContactId and afterwards the group.query with AND Condition of Green AND Yellow. But that did not succeed.

In mySql one would do just a

group_concat(Properties) as grouped  

and do a like over that string:

grouped LIKE '%Green%' AND grouped LIKE '%Yellow%' 

How can I achieve this query on the Solr index?

1 Answers

Answers 1

You can do this by using a Streaming Expression, and fetching the documents contained in the intersection between both your queries (i.e. one query matches Yellow, one matches Green):

intersect(   search(collection, q=Properties:Yellow, fl="ContactId", sort="ContactId asc"),   search(collection, q=Properties:Green, fl="ContactId", sort="ContactId asc"),   on="ContactId" ) 

You give a Streaming Expression through the expr parameter to the /stream request handler. You can also test it directly (without expr=) under "Stream" in the Solr admin interface for your collection.

Other than that, your MySQL example wouldn't really do the same, as it'd include any element that had the text present somewhere - so "Dark Green" would have given a false positive.

Read More

Sunday, April 24, 2016

Grouping listviews in wpf

Leave a Comment

In a UWP app, I can set a CollectionViewSource's Source to a List and it will group it right off the bat. With WPF it seems to work differently. I want to be able to group my list in code behind and just feed it the collection instead of listview doing it for me with the PropertyGroupDescription.

public class MyGroup : ObservableCollection<MyClass> {     public int ID{ get; set; }      public MyGroup (IEnumerable<MyClass> items) : base(items)     {         ID= items.First().ID;     } }  //other code  collectionViewSource.Source = myGroup; 

Then I just bind the collectionViewSource to the ItemSource. How can I do something like this in WPF?

1 Answers

Answers 1

So the difference between UWP and WPF seems from my experience is that in UWP you pre group with ByGroup then feed a List to the CollectionViewSource. In WPF you feed the CollectionViewSource with List then it groups it itself. In UWP The datacontext for the HeaderTemplate is MyGroup. In WPF the datacontext is CollectionViewGroup. I just passed a different object through the binding and it worked.

Read More