protected virtual void AddDecorations(BooleanQuery result)
 {
     Assert.ArgumentNotNull(result, "result");
     global::Sitecore.Security.Accounts.User user = this.User;
     if (user != null)
     {
         result.Add(new TermQuery(new Term(BuiltinFields.Creator, user.Name)), Occur.SHOULD);
         result.Add(new TermQuery(new Term(BuiltinFields.Editor, user.Name)), Occur.SHOULD);
     }
     global::Sitecore.Data.Items.Item item = this.Item;
     if (item != null)
     {
         result.Add(new TermQuery(new Term(BuiltinFields.Path, ShortID.Encode(item.ID).ToLowerInvariant())), Occur.MUST);
         result.Add(new TermQuery(new Term(BuiltinFields.Database, item.Database.Name.ToLowerInvariant())), Occur.MUST);
         if (this.ContentLanguages.Count == 0)
         {
             result.Add(new TermQuery(new Term(BuiltinFields.Language, item.Language.ToString().ToLowerInvariant())), Occur.MUST);
         }
     }
     if (this.ContentLanguages.Count > 0)
     {
         var langQuery = new BooleanQuery(true);
         this.ContentLanguages.ForEach(lang => langQuery.Add(new TermQuery(new Term(BuiltinFields.Language, lang.ToString().ToLowerInvariant())), Occur.SHOULD));
         result.Add(langQuery, Occur.MUST);
     }
     if (!this.IgnoreContentEditorOptions)
     {
         if (!UserOptions.View.ShowHiddenItems)
         {
             result.Add(new TermQuery(new Term(BuiltinFields.Hidden, "1")), Occur.MUST_NOT);
         }
         if (!UserOptions.View.ShowEntireTree && (item != null))
         {
             global::Sitecore.Data.Items.Item item2 = item.Database.GetItem(RootSections.GetSection(item));
             if (item2 != null)
             {
                 result.Add(new TermQuery(new Term(BuiltinFields.Path, ShortID.Encode(item2.ID).ToLowerInvariant())), Occur.MUST);
             }
         }
     }
     if (TemplateID != default(Guid))
     {
         result.Add(new TermQuery(new Term(BuiltinFields.Template, new ShortID(TemplateID).ToString().ToLowerInvariant())), Occur.MUST);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Adds the decorations to the BooleanQuery object. Override in derived class to change the way context affects queries.
        /// </summary>
        /// <param name="result">The result.</param>
        protected override void AddDecorations(BooleanQuery result)
        {
            Assert.ArgumentNotNull(result, "result");
            User user = this.User;

            if (user != null)
            {
                result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Creator, user.Name)), Occur.SHOULD);
                result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Editor, user.Name)), Occur.SHOULD);
            }

            Item item = this.Item;

            if (item != null)
            {
                result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Path, ShortID.Encode(item.ID).ToLowerInvariant())), Occur.MUST);
                result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Database, item.Database.Name)), Occur.MUST);
                // result.Add(new TermQuery(new Term(BuiltinFields.Language, item.Language.ToString())), Occur.MUST);
            }

            if (!this.IgnoreContentEditorOptions)
            {
                if (!UserOptions.View.ShowHiddenItems)
                {
                    result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Hidden, "1")), Occur.MUST_NOT);
                }

                if (!UserOptions.View.ShowEntireTree && (item != null))
                {
                    Item item2 = item.Database.GetItem(RootSections.GetSection(item));
                    if (item2 != null)
                    {
                        result.Add(new TermQuery(new Term(Sitecore.Search.BuiltinFields.Path, ShortID.Encode(item2.ID).ToLowerInvariant())), Occur.MUST);
                    }
                }
            }
        }