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


C# QueryParser.SetEnablePositionIncrements方法代码示例

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


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

示例1: TestSingleCharTokenAnalyzer

        public void TestSingleCharTokenAnalyzer()
        {
            Analyzer analyzer = new SingleCharTokenAnalyzer();
            IndexSearcher src = CreateIndex("[email protected] 1234567890 abcdefgh", analyzer);

            QueryParser p = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "field", analyzer);
            p.SetDefaultOperator(QueryParser.Operator.AND);
            p.SetEnablePositionIncrements(true);

            TopDocs td = null;

            td = src.Search(p.Parse("usergmail"), 10);
            Assert.AreEqual(0, td.totalHits);

            td = src.Search(p.Parse("gmailcom"), 10);
            Assert.AreEqual(0, td.totalHits);

            td = src.Search(p.Parse("678"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("someuser"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("omeuse"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("omeuse 6789"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("user gmail"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("\"user gmail\""), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("[email protected]"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("gmail.com"), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("\"gmail.com 1234\""), 10);
            Assert.AreEqual(1, td.totalHits);

            td = src.Search(p.Parse("\"gmail.com defg\""), 10);
            Assert.AreEqual(0, td.totalHits);

            td = src.Search(p.Parse("gmail.com defg"), 10);
            Assert.AreEqual(1, td.totalHits);
        }
开发者ID:Rationalle,项目名称:ravendb,代码行数:50,代码来源:Analysis.Ext.Test.cs

示例2: TestPositionIncrement

		public virtual void  TestPositionIncrement()
		{
			bool dflt = StopFilter.GetEnablePositionIncrementsDefault();
			StopFilter.SetEnablePositionIncrementsDefault(true);
			try
			{
				QueryParser qp = new QueryParser("a", new StopAnalyzer(new System.String[]{"the", "in", "are", "this"}));
				qp.SetEnablePositionIncrements(true);
				System.String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
				//               0         2                      5           7  8
				int[] expectedPositions = new int[]{1, 3, 4, 6, 9};
				PhraseQuery pq = (PhraseQuery) qp.Parse(qtxt);
				//System.out.println("Query text: "+qtxt);
				//System.out.println("Result: "+pq);
				Term[] t = pq.GetTerms();
				int[] pos = pq.GetPositions();
				for (int i = 0; i < t.Length; i++)
				{
					//System.out.println(i+". "+t[i]+"  pos: "+pos[i]);
					Assert.AreEqual(expectedPositions[i], pos[i], "term " + i + " = " + t[i] + " has wrong term-position!");
				}
			}
			finally
			{
				StopFilter.SetEnablePositionIncrementsDefault(dflt);
			}
		}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:27,代码来源:TestQueryParser.cs


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