Пример #1
0
        private Query DefineQuery(string term, Guid?userId, Reference type)
        {
            BooleanQuery masterQuery = null;

            if (!string.IsNullOrWhiteSpace(term))
            {
                using (var analyzer = new StandardAnalyzer(version))
                {
                    var parser    = new MultiFieldQueryParser(version, searchFields, analyzer);
                    var termQuery = parser.ParseQuery(term);
                    if (null != termQuery)
                    {
                        masterQuery = masterQuery ?? new BooleanQuery();
                        masterQuery.Add(termQuery, Occur.SHOULD);
                    }
                }
            }

            if (userId.HasValue && Guid.Empty != userId.Value)
            {
                if (masterQuery == null)
                {
                    masterQuery = this.UserQuery(userId.Value);
                }
                else
                {
                    masterQuery.Add(new BooleanClause(this.UserQuery(userId.Value), Occur.MUST));
                }
            }

            if (Reference.None != type)
            {
                if (masterQuery == null)
                {
                    masterQuery = this.TypeQuery(type);
                }
                else
                {
                    masterQuery.Add(new BooleanClause(this.TypeQuery(type), Occur.MUST));
                }
            }

            return((Query)masterQuery ?? new WildcardQuery(new Term(searchFields[0], "*")));
        }