Exemple #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;
        }
Exemple #2
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)
             )
         );
 }
Exemple #3
0
 static void ParseTag(XmlNode node, BooleanClause bc)
 {
     switch (node.Name)
     {
         case "group":
             ParseGroupTag(node, bc);
             break;
         case "term":
             ParseTermTag(node, bc);
             break;
     }
 }
Exemple #4
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);
 }
Exemple #5
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);
         }
     }
 }
Exemple #6
0
 public static Query Parse(XmlDocument xml, Query q)
 {
     XmlNode root = xml.FirstChild;
     q.OrderBy = root.Attributes["orderBy"] != null ? root.Attributes["orderBy"].Value : q.OrderBy;
     BooleanClause bc = new BooleanClause(
         GetBoolAttribute(root, "required", false),
         GetBoolAttribute(root, "excluded", false)
         );
     foreach (XmlNode node in root.ChildNodes)
     {
         ParseTag(node, bc);
     }
     q.Add(bc);
     return q;
 }