示例#1
0
        public static List<SearchVm2> Query(string keyWord, int rowNum, int count)
        {
            //定义solr
            //ISolrOperations<SearchVm2> solr= ServiceLocator.Current.GetInstance<ISolrOperations<SearchVm2>>();

            //建立排序,条件.
            QueryOptions options = new QueryOptions();
            options.Rows = count;//数据条数
            options.Start = 1;//开始项

            //创建查询条件
            var qTB = new SolrQueryByField("text", keyWord);

            //创建条件集合
            List<ISolrQuery> query = new List<ISolrQuery>();
            //添加条件
            query.Add(qTB);

            //按照时间倒排序.
            options.AddOrder(new SortOrder("CreateTime", Order.DESC));

            //条件集合之间的关系
            var qTBO = new SolrMultipleCriteriaQuery(query, "OR");

            //执行查询,有5个重载
            //SolrQueryResults<SearchVm2> results = solr.Query(qTBO,options);

            return null;//results;
        }
 public void AcceptsNulls()
 {
     var q1 = new SolrQuery("1");
     ISolrQuery q2 = null;
     var qm = new SolrMultipleCriteriaQuery(new[] {q1, q2});
     Assert.AreEqual("(1)", Serialize(qm));
 }
 public void Concat()
 {
     var q1 = new SolrQuery("1");
     var q2 = new SolrQuery("2");
     var qm = new SolrMultipleCriteriaQuery(new[] {q1, q2});
     Assert.AreEqual("(1  2)", Serialize(qm));
 }
        public ISolrQueryResults<BaseballGame> ExecuteQuery()
        {
            List<ISolrQuery> fieldQueries = new List<ISolrQuery>();
            QueryOptions options = new QueryOptions();
            options.Facet = BuildBaseFacetQuery();
            options.Rows = 200;

            if (this.AppliedFacets.Count > 0)
            {
                var facetGroups = this.AppliedFacets.Select(t => t.Item1).Distinct().ToList();

                foreach(var group in facetGroups)
                {
                    List<ISolrQuery> queries = this.AppliedFacets.Where(fg => fg.Item1 == group).Select(q => new SolrQueryByField(q.Item1, q.Item2) as ISolrQuery).ToList();
                    SolrMultipleCriteriaQuery smcq =
                        new SolrMultipleCriteriaQuery(queries,"OR");
                    fieldQueries.Add(smcq);
                }

                ISolrQuery multipleCriteriaQuery = new SolrMultipleCriteriaQuery(fieldQueries, "AND");
                options.AddFilterQueries(multipleCriteriaQuery);
            }
            options.OrderBy.Add(new SortOrder(this.CurrentSortTerm, this.SortDirection == "D" ? Order.DESC : Order.ASC));
            options.AddFilterQueries(new SolrQueryByField("docType", DocType.BaseballGame.ToString()));
            ISolrQuery finalQuery = SolrQuery.All;

            if (!string.IsNullOrEmpty(this.SearchTerm))
            {
                finalQuery = new SolrQuery(this.SearchTerm);
            }

            return _solrOperations.Query(finalQuery, options);
        }
 public void Concat_different_types() {
     var q1 = new SolrQuery("1");
     var q2 = new SolrQueryByField("f", "v");
     var qm = new SolrMultipleCriteriaQuery(new ISolrQuery[] {q1, q2});
     Console.WriteLine(Serialize(qm));
     Assert.AreEqual("(1  f:(v))", Serialize(qm));
 }
 public void NullQueries_are_ignored()
 {
     var qm = new SolrMultipleCriteriaQuery(new ISolrQuery[] { new SolrQuery(null), });
     Assert.IsEmpty(Serialize(qm));
 }
 public void Empty()
 {
     var qm = new SolrMultipleCriteriaQuery(new ISolrQuery[] { });
     Assert.IsEmpty(Serialize(qm));
 }
        private ISolrQuery BuildQuery(SearchParameters parameters)
        {
            var        text = parameters.Text;
            ISolrQuery query;

            if (!string.IsNullOrEmpty(text))
            {
                text = text.Replace(":", " ");
                text = text.Replace("!", " ");
                text = text.Replace("{", " ");
                text = text.Replace("}", " ");
                text = text.Replace("[", " ");
                text = text.Replace("]", " ");
                text = text.Replace("(", " ");
                text = text.Replace(")", " ");
                text = text.Replace("^", " ");

                var lang = "";
                if (!CultureHelper.IsNorwegian())
                {
                    lang = "_" + Culture.EnglishCode;
                }

                if (text.Trim().Length == 0)
                {
                    query = SolrQuery.All;
                }
                else if (text.Trim().Length < 5)
                {
                    query = new SolrMultipleCriteriaQuery(new[]
                    {
                        new SolrQuery("registerText" + lang + ":" + text + "^50"),
                        new SolrQuery("registerItemText" + lang + ":" + text + "^50"),
                        new SolrQuery("registerText" + lang + ":" + text + "*^40"),
                        new SolrQuery("registerItemText" + lang + ":" + text + "*^40"),
                        new SolrQuery("allText" + lang + ":" + text + "^1.2"),
                        new SolrQuery("allText" + lang + ":" + text + "*^1.1")
                    });
                }
                else
                {
                    query = new SolrMultipleCriteriaQuery(new[]
                    {
                        new SolrQuery("registerText" + lang + ":\"" + text + "\"^50"),
                        new SolrQuery("registerItemText" + lang + ":\"" + text + "\"^50"),
                        new SolrQuery("allText" + lang + ":\"" + text + "\"~1"), //Fuzzy
                        new SolrQuery("allText2" + lang + ":\"" + text + "\"")   //Stemmer
                        //new SolrQuery("allText3:" + text)        //Fonetisk
                    });
                }
            }
            else
            {
                query = SolrQuery.All;
            }

            if (parameters.excludecodelistvalues)
            {
                query = new SolrMultipleCriteriaQuery(new[]
                                                      { query, new SolrQuery(" NOT CodelistValue:*") });
            }

            Log.Debug("Query: " + query.ToString());
            return(query);
        }
        public void MultipleCriteria_required()
        {
            var q = SolrMultipleCriteriaQuery.Create(new SolrQueryByField("desc", "samsung"), new SolrQueryByRange <decimal>("price", 100, 200));

            Assert.Equal("+(desc:(samsung)  price:[100 TO 200])", Serialize(q.Required()));
        }
 public void EmptyQueries_are_ignored()
 {
     var qm = new SolrMultipleCriteriaQuery(new ISolrQuery[] { new SolrQuery(""), });
     Assert.IsEmpty(qm.Query);
 }
示例#11
0
        public void NullQueries_are_ignored()
        {
            var qm = new SolrMultipleCriteriaQuery(new ISolrQuery[] { new SolrQuery(null), });

            Assert.IsEmpty(Serialize(qm));
        }
示例#12
0
        public void Empty()
        {
            var qm = new SolrMultipleCriteriaQuery(new ISolrQuery[] { });

            Assert.IsEmpty(Serialize(qm));
        }