当前位置: 首页>>代码示例>>C#>>正文


C# BooleanQuery.ToString方法代码示例

本文整理汇总了C#中Lucene.Net.Search.BooleanQuery.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# BooleanQuery.ToString方法的具体用法?C# BooleanQuery.ToString怎么用?C# BooleanQuery.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Search.BooleanQuery的用法示例。


在下文中一共展示了BooleanQuery.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AndExtension

        public void AndExtension()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            BooleanQuery innerQuery = new BooleanQuery();

            Term term = new Term("_name", "value1");
            TermQuery termQuery1 = new TermQuery(term);
            innerQuery.Add(termQuery1, Occur.MUST);

            Term term2 = new Term("_name", "value2");
            TermQuery termQuery2 = new TermQuery(term2);
            innerQuery.Add(termQuery2, Occur.MUST);

            originalQuery.Add(innerQuery, Occur.MUST);
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            builder.And
                (
                    x => x.Term("_name", "value1"),
                    x => x.Term("_name", "value2")
                );
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:28,代码来源:EquivalencyTests.cs

示例2: TestQuery

		public void TestQuery()
		{
			BooleanQuery booleanQuery=new BooleanQuery();
			booleanQuery.Add(new TermQuery(new Term("name","medcl")),BooleanClause.Occur.MUST);
			booleanQuery.Add(new TermQuery(new Term("age","25")),BooleanClause.Occur.MUST);

			new ElasticSearch.Client.ElasticSearchClient("localhost").Search("index", "type", booleanQuery.ToString());
		}
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:8,代码来源:QueryTests.cs

示例3: CaseInsensitiveMandatoryTerm

        public void CaseInsensitiveMandatoryTerm()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "value");
            TermQuery termQuery = new TermQuery(term);
            originalQuery.Add(termQuery, Occur.MUST);
            string queryString = originalQuery.ToString();

            // LuceneQueryable luceneQueryable = new LuceneQueryable();
            //var items = luceneQueryable.Where(x => x.Term("_name", "Value"));
            //Query replacementQuery = luceneQueryable.Build();
            //string newQueryString = replacementQuery.ToString();

            //Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:16,代码来源:QueryableTests.cs

示例4: BoostedCaseInsensitiveMandatoryTerm

        public void BoostedCaseInsensitiveMandatoryTerm()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "value");
            TermQuery termQuery = new TermQuery(term);
            originalQuery.Add(termQuery, Occur.MUST);
            termQuery.Boost = 10;
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            builder.Setup(x => x.Term("_name", "Value", boost:10));
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:17,代码来源:EquivalencyTests.cs

示例5: AddLuceneApiQuery

        public void AddLuceneApiQuery()
        {
            // shows you can add regular lucene queries to lucinq
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "value");
            TermQuery termQuery = new TermQuery(term);
            originalQuery.Add(termQuery, Occur.MUST);
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            TermQuery termQuery2 = new TermQuery(term);
            builder.Add(termQuery2, Matches.Always);
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:18,代码来源:EquivalencyTests.cs

示例6: CaseInsensitiveNonMandatoryWildCard

        public void CaseInsensitiveNonMandatoryWildCard()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "value*");
            WildcardQuery wildcardQuery = new WildcardQuery(term);
            originalQuery.Add(wildcardQuery, Occur.SHOULD);
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            builder.Setup(x => x.WildCard("_name", "Value*", Matches.Sometimes));
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:16,代码来源:EquivalencyTests.cs

示例7: btnSearch_Click

        private void btnSearch_Click(object sender, EventArgs e)
        {
            lstResults.Items.Clear();
            searcher = new IndexSearcher(new RAMDirectory(_indexTarget));
            PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer());
            analyzer.AddAnalyzer("ayat_arabic", new DiacriticAnalyzer(FilterData.stopWords));
            //MyQueryParser parser = new MyQueryParser(new string[] { "ayat_desc", "ayat_urdu", "ayat_arabic" }, analyzer);
            //parser.SetDefaultOperator(QueryParser.Operator.AND);
            //Query q = parser.Parse(txtSearch.Text);
            //Query q = new TermQuery(new Term("ayatno", NumberTools.LongToString(long.Parse(txtSearch.Text))));
            BooleanQuery q = new BooleanQuery();
            long l1 = 1; long l2 = 500; long l3 = 1; long l4 = 1;
            //RangeQuery rq = new RangeQuery(new Term("ayatno", l1.ToString("00000")), new Term("ayatno", l2.ToString("00000")), true);
            //q.Add(rq, true, false);
            q.Add(new TermQuery(new Term("sid", l3.ToString("00000"))), true, false);
            q.Add(new TermQuery(new Term("ayatno", l4.ToString("00000"))), true, false);
            MessageBox.Show(q.ToString());
            Sort sort = new Sort(new string[] { "pid", "sid", "ayatno" });
            hits = searcher.Search(q, sort);
            lblHits.Text = hits.Length() + " hit(s).";
            Application.DoEvents();

            for (int i = 0; i < hits.Length(); i++)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Para: ").Append(hits.Doc(i).Get("pid"));
                sb.Append(", Surat: ").Append(hits.Doc(i).Get("sid"));
                sb.Append(", Verse: ").Append(hits.Doc(i).Get("ayatno"));
                lstResults.Items.Add(sb.ToString());

            }
        }
开发者ID:usmanghani,项目名称:Misc,代码行数:32,代码来源:Form1.cs

示例8: Search

        public static IEnumerable<BaseItem> Search(string searchQuery, int maxHits)
        {
            var results = new List<BaseItem>();

            lock (lockOb)
            {
                try
                {
                    if (searcher == null)
                    {
                        searcher = new IndexSearcher(directory, true);
                    }

                    BooleanQuery finalQuery = new BooleanQuery();

                    MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new string[] { "Name", "Overview" }, analyzer, bonusTerms);

                    string[] terms = searchQuery.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string term in terms)
                        finalQuery.Add(parser.Parse(term.Replace("~", "") + "~0.75"), Occur.SHOULD);
                    foreach (string term in terms)
                        finalQuery.Add(parser.Parse(term.Replace("*", "") + "*"), Occur.SHOULD);

                    logger.Debug("Querying Lucene with query:   " + finalQuery.ToString());

                    long start = DateTime.Now.Ticks;
                    var searchResult = searcher.Search(finalQuery, maxHits);
                    foreach (var searchHit in searchResult.ScoreDocs)
                    {
                        Document hit = searcher.Doc(searchHit.Doc);
                        results.Add(BaseItem.LibraryManager.GetItemById(Guid.Parse(hit.Get("Id"))));
                    }
                    long total = DateTime.Now.Ticks - start;
                    float msTotal = (float)total / TimeSpan.TicksPerMillisecond;
                    logger.Debug(searchResult.ScoreDocs.Length + " result" + (searchResult.ScoreDocs.Length == 1 ? "" : "s") + " in " + msTotal + " ms.");
                }
                catch (Exception e)
                {
                    logger.ErrorException("Error while searching Lucene index", e);
                }
            }

            return results;
        }
开发者ID:snap608,项目名称:MediaBrowser,代码行数:44,代码来源:LuceneSearchEngine.cs

示例9: QueryCaseSensitivePhrase

        public void QueryCaseSensitivePhrase()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "Value");
            PhraseQuery phraseQuery = new PhraseQuery();
            phraseQuery.SetSlop(2);
            phraseQuery.Add(term);
            originalQuery.Add(phraseQuery, BooleanClause.Occur.MUST);
            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder{CaseSensitive = true};
            builder.Setup(x => x.Phrase(2).AddTerm(x, "_name", "Value"));
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:simonproctor,项目名称:Lucinq,代码行数:18,代码来源:EquivalencyTests.cs

示例10: CompositeTermPhraseWildcardTests

        public void CompositeTermPhraseWildcardTests()
        {
            BooleanQuery originalQuery = new BooleanQuery();
            Term term = new Term("_name", "value");
            TermQuery termQuery = new TermQuery(term);
            originalQuery.Add(termQuery, Occur.MUST);
            PhraseQuery phraseQuery = new PhraseQuery();
            Term phraseTerm = new Term("_name", "phrase");
            phraseQuery.Slop = 2;
            phraseQuery.Add(phraseTerm);
            originalQuery.Add(phraseQuery, Occur.MUST);

            Term wildcardTerm = new Term("_name", "*wildcard*");
            WildcardQuery wildcardQuery = new WildcardQuery(wildcardTerm);
            originalQuery.Add(wildcardQuery, Occur.SHOULD);

            string queryString = originalQuery.ToString();

            QueryBuilder builder = new QueryBuilder();
            builder.Setup
                (
                    x => x.Term("_name", "value"),
                    x => x.Phrase(2).AddTerm("_name", "phrase"),
                    x => x.WildCard("_name", "*wildcard*", Matches.Sometimes)
                );
            Query replacementQuery = builder.Build();
            string newQueryString = replacementQuery.ToString();

            Assert.AreEqual(queryString, newQueryString);
            Console.Write(queryString);
        }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:31,代码来源:EquivalencyTests.cs

示例11: TestBooleanOptionalWithTiebreakerAndBoost

        public virtual void TestBooleanOptionalWithTiebreakerAndBoost()
        {
            BooleanQuery q = new BooleanQuery();
            {
                DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.01f);
                q1.Add(Tq("hed", "albino", 1.5f));
                q1.Add(Tq("dek", "albino"));
                q.Add(q1, BooleanClause.Occur.SHOULD); // false,false);
            }
            {
                DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.01f);
                q2.Add(Tq("hed", "elephant", 1.5f));
                q2.Add(Tq("dek", "elephant"));
                q.Add(q2, BooleanClause.Occur.SHOULD); // false,false);
            }
            QueryUtils.Check(Random(), q, s, Similarity);

            ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;

            try
            {
                Assert.AreEqual(4, h.Length, "4 docs should match " + q.ToString());

                float score0 = h[0].Score;
                float score1 = h[1].Score;
                float score2 = h[2].Score;
                float score3 = h[3].Score;

                string doc0 = s.Doc(h[0].Doc).Get("id");
                string doc1 = s.Doc(h[1].Doc).Get("id");
                string doc2 = s.Doc(h[2].Doc).Get("id");
                string doc3 = s.Doc(h[3].Doc).Get("id");

                Assert.AreEqual("d4", doc0, "doc0 should be d4: ");
                Assert.AreEqual("d3", doc1, "doc1 should be d3: ");
                Assert.AreEqual("d2", doc2, "doc2 should be d2: ");
                Assert.AreEqual("d1", doc3, "doc3 should be d1: ");

                Assert.IsTrue(score0 > score1, "d4 does not have a better score then d3: " + score0 + " >? " + score1);
                Assert.IsTrue(score1 > score2, "d3 does not have a better score then d2: " + score1 + " >? " + score2);
                Assert.IsTrue(score2 > score3, "d3 does not have a better score then d1: " + score2 + " >? " + score3);
            }
            catch (Exception e)
            {
                PrintHits("TestBooleanOptionalWithTiebreakerAndBoost", h, s);
                throw e;
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:48,代码来源:TestDisjunctionMaxQuery.cs

示例12: TestBooleanOptionalNoTiebreaker

        public virtual void TestBooleanOptionalNoTiebreaker()
        {
            BooleanQuery q = new BooleanQuery();
            {
                DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
                q1.Add(Tq("hed", "albino"));
                q1.Add(Tq("dek", "albino"));
                q.Add(q1, BooleanClause.Occur.SHOULD); // false,false);
            }
            {
                DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
                q2.Add(Tq("hed", "elephant"));
                q2.Add(Tq("dek", "elephant"));
                q.Add(q2, BooleanClause.Occur.SHOULD); // false,false);
            }
            QueryUtils.Check(Random(), q, s, Similarity);

            ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;

            try
            {
                Assert.AreEqual(4, h.Length, "4 docs should match " + q.ToString());
                float score = h[0].Score;
                for (int i = 1; i < h.Length - 1; i++) // note: -1
                {
                    Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same");
                }
                Assert.AreEqual("d1", s.Doc(h[h.Length - 1].Doc).Get("id"), "wrong last");
                float score1 = h[h.Length - 1].Score;
                Assert.IsTrue(score > score1, "d1 does not have worse score then others: " + score + " >? " + score1);
            }
            catch (Exception e)
            {
                PrintHits("testBooleanOptionalNoTiebreaker", h, s);
                throw e;
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:37,代码来源:TestDisjunctionMaxQuery.cs

示例13: TestBooleanRequiredEqualScores

        public virtual void TestBooleanRequiredEqualScores()
        {
            BooleanQuery q = new BooleanQuery();
            {
                DisjunctionMaxQuery q1 = new DisjunctionMaxQuery(0.0f);
                q1.Add(Tq("hed", "albino"));
                q1.Add(Tq("dek", "albino"));
                q.Add(q1, BooleanClause.Occur.MUST); // true,false);
                QueryUtils.Check(Random(), q1, s, Similarity);
            }
            {
                DisjunctionMaxQuery q2 = new DisjunctionMaxQuery(0.0f);
                q2.Add(Tq("hed", "elephant"));
                q2.Add(Tq("dek", "elephant"));
                q.Add(q2, BooleanClause.Occur.MUST); // true,false);
                QueryUtils.Check(Random(), q2, s, Similarity);
            }

            QueryUtils.Check(Random(), q, s, Similarity);

            ScoreDoc[] h = s.Search(q, null, 1000).ScoreDocs;

            try
            {
                Assert.AreEqual(3, h.Length, "3 docs should match " + q.ToString());
                float score = h[0].Score;
                for (int i = 1; i < h.Length; i++)
                {
                    Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same");
                }
            }
            catch (Exception e)
            {
                PrintHits("testBooleanRequiredEqualScores1", h, s);
                throw e;
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:37,代码来源:TestDisjunctionMaxQuery.cs

示例14: DoTest

        private void DoTest(Random random, PrintWriter @out, bool useCompoundFiles, int MAX_DOCS)
        {
            Directory directory = newDirectory();
              Analyzer analyzer = new MockAnalyzer(random);
              IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
              MergePolicy mp = conf.MergePolicy;
              mp.NoCFSRatio = useCompoundFiles ? 1.0 : 0.0;
              IndexWriter writer = new IndexWriter(directory, conf);
              if (VERBOSE)
              {
            Console.WriteLine("TEST: now build index MAX_DOCS=" + MAX_DOCS);
              }

              for (int j = 0; j < MAX_DOCS; j++)
              {
            Document d = new Document();
            d.Add(newTextField(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES));
            d.Add(newTextField(ID_FIELD, Convert.ToString(j), Field.Store.YES));
            writer.addDocument(d);
              }
              writer.Dispose();

              // try a search without OR
              IndexReader reader = DirectoryReader.Open(directory);
              IndexSearcher searcher = newSearcher(reader);

              Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
              @out.println("Query: " + query.ToString(PRIORITY_FIELD));
              if (VERBOSE)
              {
            Console.WriteLine("TEST: search query=" + query);
              }

              Sort sort = new Sort(SortField.FIELD_SCORE, new SortField(ID_FIELD, SortField.Type.INT));

              ScoreDoc[] hits = searcher.Search(query, null, MAX_DOCS, sort).scoreDocs;
              PrintHits(@out, hits, searcher);
              CheckHits(hits, MAX_DOCS, searcher);

              // try a new search with OR
              searcher = newSearcher(reader);
              hits = null;

              BooleanQuery booleanQuery = new BooleanQuery();
              booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY)), BooleanClause.Occur_e.SHOULD);
              booleanQuery.Add(new TermQuery(new Term(PRIORITY_FIELD, MED_PRIORITY)), BooleanClause.Occur_e.SHOULD);
              @out.println("Query: " + booleanQuery.ToString(PRIORITY_FIELD));

              hits = searcher.search(booleanQuery, null, MAX_DOCS, sort).scoreDocs;
              PrintHits(@out, hits, searcher);
              CheckHits(hits, MAX_DOCS, searcher);

              reader.Close();
              directory.Close();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:55,代码来源:TestSearchForDuplicates.cs

示例15: Search

        //Main search algorithm
        public IEnumerable<Result> Search(string fieldName, string searchTerm)
        {
            DocType docType = DocType.SONG;
            Query mainQuery;
            switch(fieldName)
            {
                case F_ARTIST:
                    docType=DocType.ARTIST;
                    break;
                case F_ALBUM:
                    docType=DocType.ALBUM;
                    break;
                case F_GENRE:
                    docType=DocType.GENRE;
                    break;
            }
            IndexSearcher searcher = new IndexSearcher(luceneIndexDirectory);
            BooleanQuery booleanQuery = new BooleanQuery();
            QueryParser qp = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, fieldName, analyzer);
            try
            {
                mainQuery = qp.Parse(searchTerm);
            }
            catch (ParseException e)
            {
                console.Log(e.Message);
                return null;
            }
            Query DocTypeQuery = new TermQuery(new Term(F_DOCTYPE, docType.ToString()));
            booleanQuery.Add(mainQuery, Occur.MUST);
            booleanQuery.Add(DocTypeQuery, Occur.MUST);
            console.Log("query: " + booleanQuery.ToString());
            TopDocs hitsFound = searcher.Search(booleanQuery , Int32.MaxValue);
            List<Result> results = new List<Result>();
            Result sampleResult = null;

            for (int i = 0; i < hitsFound.TotalHits; i++)
            {
                sampleResult = new Result();
                Document doc = searcher.Doc(hitsFound.ScoreDocs[i].Doc);
                //key moment
                fillResult(sampleResult, fieldName, doc);
                float score = hitsFound.ScoreDocs[i].Score;
                sampleResult.Score = score;
                results.Add(sampleResult);
            }
            return results.OrderByDescending(x => x.Score).ToList();
        }
开发者ID:vash47,项目名称:kyokufind,代码行数:49,代码来源:LuceneService.cs


注:本文中的Lucene.Net.Search.BooleanQuery.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。