Example #1
0
        public static ContentList Query(Query query, string[] groups, string[] permissions)
        {
            if (groups != null && groups.Length > 0 && permissions != null && permissions.Length > 0)
            {
                foreach (string permission in permissions)
                {
                    BooleanClause bc = new BooleanClause(true, false);
                    foreach (string role in groups)
                    {
                        bc.AddClause(
                            new TermClause(
                                string.Format("GroupWith{0}Permissions", permission),
                                role,
                                false,
                                false)
                          );
                    }
                    query.Add(bc);
                }
            }

            if (query.OrderBy == null) query.OrderBy = "PublishDate DESC";
            if (query.DefaultField == null) query.DefaultField = "Text";

            ContentList results = new ContentList();
            try
            {

                IndexDocument[] docs = Engine.Search(query);
                Dictionary<Guid, bool> usedResults = new Dictionary<Guid, bool>(docs.Length);

                results.StartIndex = query.StartResultIndex;
                results.EndIndex = query.EndResultIndex;
                results.TotalResults = query.TotalResults;

                for (int i = 0; i < docs.Length; i++)
                {
                    Guid id = new Guid(docs[i].Get("ActiveObjectsID"));
                    if (!usedResults.ContainsKey(id))
                    {
                        usedResults.Add(id, true);
                        results.Add(new Content(docs[i]));
                    }
                    else
                    {
                        LogDuplicate(id, docs[i].Get("Title"));
                    }
                }
                usedResults.Clear();
            }
            catch { }

            return results;
        }
Example #2
0
 static void ParseGroupTag(XmlNode node, BooleanClause parent)
 {
     BooleanClause bc = new BooleanClause(GetBoolAttribute(node, "required", false), GetBoolAttribute(node, "excluded", false));
     foreach (XmlNode child in node.ChildNodes)
     {
         ParseTag(child, bc);
     }
     parent.AddClause(bc);
 }
Example #3
0
 static void ParseTermTag(XmlNode node, BooleanClause boolean)
 {
     string field = node.Attributes["field"] != null ? node.Attributes["field"].Value : null;
     string value = node.Attributes["value"] != null ? node.Attributes["value"].Value : null;
     if(value == null || field == null) return;
     bool isWildcard = value.Contains("*");
     boolean.AddClause(
         new TermClause(
             field,
             value,
             isWildcard,
             GetBoolAttribute(node, "required", false),
             GetBoolAttribute(node, "excluded", false)
             )
         );
 }
Example #4
0
 public void RestrictByGroups(IndexPermissions[] permissions, string[] groups)
 {
     if (groups != null && groups.Length > 0 && permissions != null && permissions.Length > 0)
     {
         foreach (IndexPermissions permission in permissions)
         {
             BooleanClause bc = new BooleanClause(true, false);
             foreach (string role in groups)
             {
                 bc.AddClause(
                     new TermClause(
                         string.Format("GroupWith{0}Permissions", permission),
                         role,
                         false,
                         false)
                   );
             }
             this.Add(bc);
         }
     }
 }