public bool tryGetGroup(String name, out AnatomyGroup group)
 {
     return(tags.tryGetGroup(name, out group) ||
            systems.tryGetGroup(name, out group) ||
            regions.tryGetGroup(name, out group) ||
            classifications.tryGetGroup(name, out group) ||
            structures.tryGetGroup(name, out group));
 }
 private IEnumerable <AnatomyGroup> breakdownGroupSearch(String groupTitleFormat, String groupName, IEnumerable <AnatomyFacet> parentFacets, String breakdownFacet, IEnumerable <String> breakdownValues)
 {
     foreach (var breakdownValue in breakdownValues)
     {
         AnatomyGroup resultGroup = new AnatomyGroup(String.Format(groupTitleFormat, groupName, breakdownValue));
         resultGroup.Facets = parentFacets.AddSingle(new AnatomyFacet(breakdownFacet, breakdownValue));
         resultGroup.addAnatomy(search(null, resultGroup.Facets, int.MaxValue));
         if (resultGroup.Count > 0)
         {
             resultGroup.addCommand(new BreakdownSearchCallbackCommand("Show Individual Anatomy", true, () => displayAnatomyForGroup(resultGroup)));
             yield return(resultGroup);
         }
     }
 }
        /// <summary>
        /// Given a set of facets, build an AnatomyGroup and return it.
        /// </summary>
        /// <param name="name">The name to give the group.</param>
        /// <param name="facets">The facets to build the group with.</param>
        /// <returns>A new AnatomyGroup based on the search results. Will return null if there are no results.</returns>
        public AnatomyGroup buildGroupFromFacets(String name, IEnumerable <AnatomyFacet> facets)
        {
            Query        query   = buildQuery(null, facets);
            TopDocs      results = searcher.Search(query, int.MaxValue);
            AnatomyGroup group   = null;

            if (results.TotalHits > 0)
            {
                group = new AnatomyGroup(name);
                foreach (var scoreDoc in results.ScoreDocs)
                {
                    var doc   = searcher.Doc(scoreDoc.Doc);
                    int index = BitConverter.ToInt32(doc.GetBinaryValue("DataIndex"), 0);
                    group.addAnatomy(anatomyList[index]);
                }
                group.addCommand(new BreakdownSearchCallbackCommand("Show Individual Anatomy", true, () =>
                {
                    anatomyController.displayAnatomy(String.Format("{0} Anatomy", group.AnatomicalName), group.SelectableAnatomy, SuggestedDisplaySortMode.Alphabetical);
                }));
            }
            return(group);
        }
 private void displayAnatomyForGroup(AnatomyGroup group)
 {
     anatomyController.displayAnatomy(String.Format("{0} Anatomy", group.AnatomicalName), group.SelectableAnatomy, SuggestedDisplaySortMode.Alphabetical);
 }
 /// <summary>
 /// Breakdown a group
 /// </summary>
 /// <param name="groupTitleFormat">The format for the group title, {0} is the group name and {1} is the breakdown facet name.</param>
 /// <param name="group">The group to break down.</param>
 /// <param name="breakdownFacet">The facet to breakdown the group by.</param>
 private void breakdownGroup(String groupTitleFormat, AnatomyGroup group, AnatomyGroupFacetManager breakdownFacet)
 {
     anatomyController.displayAnatomy(String.Format("{0} by {1}", group.AnatomicalName, breakdownFacet.FacetName),
                                      breakdownGroupSearch(groupTitleFormat, group.AnatomicalName, group.Facets, breakdownFacet.FacetName, breakdownFacet.Select(i => i.AnatomicalName)),
                                      SuggestedDisplaySortMode.Alphabetical);
 }
        public void setAnatomy(IEnumerable <AnatomyIdentifier> anatomyIdentifiers, AnatomyOrganizer organizer)
        {
            if (organizer != null)
            {
                tags.createGroups(organizer.TagProperties);
                systems.createGroups(organizer.SystemProperties);
                regions.createGroups(organizer.RegionProperties);
                classifications.createGroups(organizer.ClassificationProperties);
                structures.createGroups(organizer.StructureProperties);
            }

            directory = new RAMDirectory();

            //Update index
            using (IndexWriter indexWriter = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
            {
                foreach (var anatomy in anatomyIdentifiers)
                {
                    anatomy.addExternalCommand(
                        new BreakdownSearchCallbackCommand("Show Groups", true, () => showGroupsForAnatomy(anatomy))
                    {
                        DisplayInGroup = false
                    });

                    if (anatomy.ShowInTextSearch)
                    {
                        Document document = new Document();
                        int      index    = addAnatomyToIndex(anatomy);
                        document.Add(new Field("Id", index.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                        document.Add(new Field("DataIndex", BitConverter.GetBytes(index), 0, sizeof(int), Field.Store.YES));
                        document.Add(new Field("Name", anatomy.AnatomicalName, Field.Store.YES, Field.Index.ANALYZED));
                        document.Add(new Field("AnatomyType", "Individual", Field.Store.YES, Field.Index.NOT_ANALYZED));
                        foreach (String system in anatomy.Systems)
                        {
                            document.Add(new Field(systems.FacetName, system, Field.Store.YES, Field.Index.NOT_ANALYZED));
                            AnatomyGroup systemGroup = systems.getOrCreateGroup(system);
                            systemGroup.addAnatomy(anatomy);
                        }
                        foreach (String tag in anatomy.Tags)
                        {
                            document.Add(new Field(tags.FacetName, tag, Field.Store.YES, Field.Index.NOT_ANALYZED));
                            AnatomyGroup tagGroup = tags.getOrCreateGroup(tag);
                            tagGroup.addAnatomy(anatomy);
                        }
                        if (!String.IsNullOrEmpty(anatomy.Classification))
                        {
                            document.Add(new Field(classifications.FacetName, anatomy.Classification, Field.Store.YES, Field.Index.NOT_ANALYZED));
                            AnatomyGroup classificationGroup = classifications.getOrCreateGroup(anatomy.Classification);
                            classificationGroup.addAnatomy(anatomy);
                        }
                        if (!String.IsNullOrEmpty(anatomy.Region))
                        {
                            document.Add(new Field(regions.FacetName, anatomy.Region, Field.Store.YES, Field.Index.NOT_ANALYZED));
                            AnatomyGroup regionGroup = regions.getOrCreateGroup(anatomy.Region);
                            regionGroup.addAnatomy(anatomy);
                        }
                        if (!String.IsNullOrEmpty(anatomy.Structure))
                        {
                            document.Add(new Field(structures.FacetName, anatomy.Structure, Field.Store.YES, Field.Index.NOT_ANALYZED));
                            AnatomyGroup structureGroup = structures.getOrCreateGroup(anatomy.Structure);
                            structureGroup.addAnatomy(anatomy);
                        }

                        indexWriter.UpdateDocument(new Term("Id", index.ToString()), document);
                    }
                }

                //Add the groups to the index last so we can be sure they actually have anatomy in them.
                tags.setupGroupDocuments(indexWriter, addAnatomyToIndex);
                systems.setupGroupDocuments(indexWriter, addAnatomyToIndex);
                regions.setupGroupDocuments(indexWriter, addAnatomyToIndex);
                classifications.setupGroupDocuments(indexWriter, addAnatomyToIndex);
                structures.setupGroupDocuments(indexWriter, addAnatomyToIndex);

                indexWriter.Optimize();
            }

            searcher = new IndexSearcher(directory, true);
        }