You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2016/09/11 21:31:01 UTC
[30/50] [abbrv] lucenenet git commit: Moved Lucene.Net.QueryParser
and Lucene.Net.Tests.QueryParser projects into src\ directory.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Classic/TestMultiFieldQueryParser.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Classic/TestMultiFieldQueryParser.cs b/Lucene.Net.Tests.QueryParser/Classic/TestMultiFieldQueryParser.cs
deleted file mode 100644
index f233c02..0000000
--- a/Lucene.Net.Tests.QueryParser/Classic/TestMultiFieldQueryParser.cs
+++ /dev/null
@@ -1,376 +0,0 @@
-\ufeffusing Lucene.Net.Analysis;
-using Lucene.Net.Documents;
-using Lucene.Net.Index;
-using Lucene.Net.Search;
-using Lucene.Net.Util;
-using NUnit.Framework;
-using System;
-using System.Collections.Generic;
-using System.IO;
-
-namespace Lucene.Net.QueryParser.Classic
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- [TestFixture]
- public class TestMultiFieldQueryParser : LuceneTestCase
- {
- /// <summary>
- /// test stop words parsing for both the non static form, and for the
- /// corresponding static form (qtxt, fields[]).
- /// </summary>
- [Test]
- public void TestStopwordsParsing()
- {
- AssertStopQueryEquals("one", "b:one t:one");
- AssertStopQueryEquals("one stop", "b:one t:one");
- AssertStopQueryEquals("one (stop)", "b:one t:one");
- AssertStopQueryEquals("one ((stop))", "b:one t:one");
- AssertStopQueryEquals("stop", "");
- AssertStopQueryEquals("(stop)", "");
- AssertStopQueryEquals("((stop))", "");
- }
-
- /// <summary>
- /// verify parsing of query using a stopping analyzer
- /// </summary>
- /// <param name="qtxt"></param>
- /// <param name="expectedRes"></param>
- private void AssertStopQueryEquals(string qtxt, string expectedRes)
- {
- string[] fields = { "b", "t" };
- BooleanClause.Occur[] occur = new BooleanClause.Occur[] { BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
- TestQueryParser.QPTestAnalyzer a = new TestQueryParser.QPTestAnalyzer();
- MultiFieldQueryParser mfqp = new MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, a);
-
- Query q = mfqp.Parse(qtxt);
- assertEquals(expectedRes, q.toString());
-
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, qtxt, fields, occur, a);
- assertEquals(expectedRes, q.toString());
- }
-
- [Test]
- public void TestSimple()
- {
- string[] fields = { "b", "t" };
- MultiFieldQueryParser mfqp = new MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, new MockAnalyzer(Random()));
-
- Query q = mfqp.Parse("one");
- assertEquals("b:one t:one", q.toString());
-
- q = mfqp.Parse("one two");
- assertEquals("(b:one t:one) (b:two t:two)", q.toString());
-
- q = mfqp.Parse("+one +two");
- assertEquals("+(b:one t:one) +(b:two t:two)", q.toString());
-
- q = mfqp.Parse("+one -two -three");
- assertEquals("+(b:one t:one) -(b:two t:two) -(b:three t:three)", q.toString());
-
- q = mfqp.Parse("one^2 two");
- assertEquals("((b:one t:one)^2.0) (b:two t:two)", q.toString());
-
- q = mfqp.Parse("one~ two");
- assertEquals("(b:one~2 t:one~2) (b:two t:two)", q.toString());
-
- q = mfqp.Parse("one~0.8 two^2");
- assertEquals("(b:one~0 t:one~0) ((b:two t:two)^2.0)", q.toString());
-
- q = mfqp.Parse("one* two*");
- assertEquals("(b:one* t:one*) (b:two* t:two*)", q.toString());
-
- q = mfqp.Parse("[a TO c] two");
- assertEquals("(b:[a TO c] t:[a TO c]) (b:two t:two)", q.toString());
-
- q = mfqp.Parse("w?ldcard");
- assertEquals("b:w?ldcard t:w?ldcard", q.toString());
-
- q = mfqp.Parse("\"foo bar\"");
- assertEquals("b:\"foo bar\" t:\"foo bar\"", q.toString());
-
- q = mfqp.Parse("\"aa bb cc\" \"dd ee\"");
- assertEquals("(b:\"aa bb cc\" t:\"aa bb cc\") (b:\"dd ee\" t:\"dd ee\")", q.toString());
-
- q = mfqp.Parse("\"foo bar\"~4");
- assertEquals("b:\"foo bar\"~4 t:\"foo bar\"~4", q.toString());
-
- // LUCENE-1213: MultiFieldQueryParser was ignoring slop when phrase had a field.
- q = mfqp.Parse("b:\"foo bar\"~4");
- assertEquals("b:\"foo bar\"~4", q.toString());
-
- // make sure that terms which have a field are not touched:
- q = mfqp.Parse("one f:two");
- assertEquals("(b:one t:one) f:two", q.toString());
-
- // AND mode:
- mfqp.DefaultOperator = QueryParserBase.AND_OPERATOR;
- q = mfqp.Parse("one two");
- assertEquals("+(b:one t:one) +(b:two t:two)", q.toString());
- q = mfqp.Parse("\"aa bb cc\" \"dd ee\"");
- assertEquals("+(b:\"aa bb cc\" t:\"aa bb cc\") +(b:\"dd ee\" t:\"dd ee\")", q.toString());
- }
-
- [Test]
- public void TestBoostsSimple()
- {
- IDictionary<string, float> boosts = new Dictionary<string, float>();
- boosts["b"] = (float)5;
- boosts["t"] = (float)10;
- string[] fields = { "b", "t" };
- MultiFieldQueryParser mfqp = new MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, new MockAnalyzer(Random()), boosts);
-
-
- //Check for simple
- Query q = mfqp.Parse("one");
- assertEquals("b:one^5.0 t:one^10.0", q.toString());
-
- //Check for AND
- q = mfqp.Parse("one AND two");
- assertEquals("+(b:one^5.0 t:one^10.0) +(b:two^5.0 t:two^10.0)", q.toString());
-
- //Check for OR
- q = mfqp.Parse("one OR two");
- assertEquals("(b:one^5.0 t:one^10.0) (b:two^5.0 t:two^10.0)", q.toString());
-
- //Check for AND and a field
- q = mfqp.Parse("one AND two AND foo:test");
- assertEquals("+(b:one^5.0 t:one^10.0) +(b:two^5.0 t:two^10.0) +foo:test", q.toString());
-
- q = mfqp.Parse("one^3 AND two^4");
- assertEquals("+((b:one^5.0 t:one^10.0)^3.0) +((b:two^5.0 t:two^10.0)^4.0)", q.toString());
- }
-
- [Test]
- public void TestStaticMethod1()
- {
- string[] fields = { "b", "t" };
- string[] queries = { "one", "two" };
- Query q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries, fields, new MockAnalyzer(Random()));
- assertEquals("b:one t:two", q.toString());
-
- string[] queries2 = { "+one", "+two" };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries2, fields, new MockAnalyzer(Random()));
- assertEquals("(+b:one) (+t:two)", q.toString());
-
- string[] queries3 = { "one", "+two" };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries3, fields, new MockAnalyzer(Random()));
- assertEquals("b:one (+t:two)", q.toString());
-
- string[] queries4 = { "one +more", "+two" };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries4, fields, new MockAnalyzer(Random()));
- assertEquals("(b:one +b:more) (+t:two)", q.toString());
-
- string[] queries5 = { "blah" };
- try
- {
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries5, fields, new MockAnalyzer(Random()));
- fail();
- }
- catch (ArgumentException e)
- {
- // expected exception, array length differs
- }
-
- // check also with stop words for this static form (qtxts[], fields[]).
- TestQueryParser.QPTestAnalyzer stopA = new TestQueryParser.QPTestAnalyzer();
-
- string[] queries6 = { "((+stop))", "+((stop))" };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries6, fields, stopA);
- assertEquals("", q.toString());
-
- string[] queries7 = { "one ((+stop)) +more", "+((stop)) +two" };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries7, fields, stopA);
- assertEquals("(b:one +b:more) (+t:two)", q.toString());
- }
-
- [Test]
- public void TestStaticMethod2()
- {
- string[] fields = { "b", "t" };
- BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT };
- Query q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, "one", fields, flags, new MockAnalyzer(Random()));
- assertEquals("+b:one -t:one", q.toString());
-
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, "one two", fields, flags, new MockAnalyzer(Random()));
- assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());
-
- try
- {
- BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, "blah", fields, flags2, new MockAnalyzer(Random()));
- fail();
- }
- catch (ArgumentException e)
- {
- // expected exception, array length differs
- }
- }
-
- [Test]
- public void TestStaticMethod2Old()
- {
- string[] fields = { "b", "t" };
- //int[] flags = {MultiFieldQueryParser.REQUIRED_FIELD, MultiFieldQueryParser.PROHIBITED_FIELD};
- BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT };
-
- Query q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, "one", fields, flags, new MockAnalyzer(Random()));//, fields, flags, new MockAnalyzer(random));
- assertEquals("+b:one -t:one", q.toString());
-
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, "one two", fields, flags, new MockAnalyzer(Random()));
- assertEquals("+(b:one b:two) -(t:one t:two)", q.toString());
-
- try
- {
- BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, "blah", fields, flags2, new MockAnalyzer(Random()));
- fail();
- }
- catch (ArgumentException e)
- {
- // expected exception, array length differs
- }
- }
-
- [Test]
- public void TestStaticMethod3()
- {
- string[] queries = { "one", "two", "three" };
- string[] fields = { "f1", "f2", "f3" };
- BooleanClause.Occur[] flags = {BooleanClause.Occur.MUST,
- BooleanClause.Occur.MUST_NOT, BooleanClause.Occur.SHOULD};
- Query q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries, fields, flags, new MockAnalyzer(Random()));
- assertEquals("+f1:one -f2:two f3:three", q.toString());
-
- try
- {
- BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries, fields, flags2, new MockAnalyzer(Random()));
- fail();
- }
- catch (ArgumentException e)
- {
- // expected exception, array length differs
- }
- }
-
- [Test]
- public void TestStaticMethod3Old()
- {
- string[] queries = { "one", "two" };
- string[] fields = { "b", "t" };
- BooleanClause.Occur[] flags = { BooleanClause.Occur.MUST, BooleanClause.Occur.MUST_NOT };
- Query q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries, fields, flags, new MockAnalyzer(Random()));
- assertEquals("+b:one -t:two", q.toString());
-
- try
- {
- BooleanClause.Occur[] flags2 = { BooleanClause.Occur.MUST };
- q = MultiFieldQueryParser.Parse(TEST_VERSION_CURRENT, queries, fields, flags2, new MockAnalyzer(Random()));
- fail();
- }
- catch (ArgumentException e)
- {
- // expected exception, array length differs
- }
- }
-
- [Test]
- public void TestAnalyzerReturningNull()
- {
- string[] fields = new string[] { "f1", "f2", "f3" };
- MultiFieldQueryParser parser = new MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, new AnalyzerReturningNull());
- Query q = parser.Parse("bla AND blo");
- assertEquals("+(f2:bla f3:bla) +(f2:blo f3:blo)", q.toString());
- // the following queries are not affected as their terms are not analyzed anyway:
- q = parser.Parse("bla*");
- assertEquals("f1:bla* f2:bla* f3:bla*", q.toString());
- q = parser.Parse("bla~");
- assertEquals("f1:bla~2 f2:bla~2 f3:bla~2", q.toString());
- q = parser.Parse("[a TO c]");
- assertEquals("f1:[a TO c] f2:[a TO c] f3:[a TO c]", q.toString());
- }
-
- [Test]
- public void TestStopWordSearching()
- {
- Analyzer analyzer = new MockAnalyzer(Random());
- using (var ramDir = NewDirectory())
- {
- using (IndexWriter iw = new IndexWriter(ramDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)))
- {
- Document doc = new Document();
- doc.Add(NewTextField("body", "blah the footest blah", Field.Store.NO));
- iw.AddDocument(doc);
- }
-
- MultiFieldQueryParser mfqp =
- new MultiFieldQueryParser(TEST_VERSION_CURRENT, new string[] { "body" }, analyzer);
- mfqp.DefaultOperator = QueryParser.Operator.AND;
- Query q = mfqp.Parse("the footest");
- using (IndexReader ir = DirectoryReader.Open(ramDir))
- {
- IndexSearcher @is = NewSearcher(ir);
- ScoreDoc[] hits = @is.Search(q, null, 1000).ScoreDocs;
- assertEquals(1, hits.Length);
- }
- }
- }
-
- private class AnalyzerReturningNull : Analyzer
- {
- MockAnalyzer stdAnalyzer = new MockAnalyzer(Random());
-
- public AnalyzerReturningNull()
- : base(PER_FIELD_REUSE_STRATEGY)
- { }
-
- public override System.IO.TextReader InitReader(string fieldName, TextReader reader)
- {
- if ("f1".equals(fieldName))
- {
- // we don't use the reader, so close it:
- IOUtils.CloseWhileHandlingException(reader);
- // return empty reader, so MockTokenizer returns no tokens:
- return new StringReader("");
- }
- else
- {
- return base.InitReader(fieldName, reader);
- }
- }
-
- public override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
- {
- return stdAnalyzer.CreateComponents(fieldName, reader);
- }
- }
-
- [Test]
- public void TestSimpleRegex()
- {
- string[] fields = new string[] { "a", "b" };
- MultiFieldQueryParser mfqp = new MultiFieldQueryParser(TEST_VERSION_CURRENT, fields, new MockAnalyzer(Random()));
-
- BooleanQuery bq = new BooleanQuery(true);
- bq.Add(new RegexpQuery(new Term("a", "[a-z][123]")), BooleanClause.Occur.SHOULD);
- bq.Add(new RegexpQuery(new Term("b", "[a-z][123]")), BooleanClause.Occur.SHOULD);
- assertEquals(bq, mfqp.Parse("/[a-z][123]/"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Classic/TestMultiPhraseQueryParsing.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Classic/TestMultiPhraseQueryParsing.cs b/Lucene.Net.Tests.QueryParser/Classic/TestMultiPhraseQueryParsing.cs
deleted file mode 100644
index 3aaa9b2..0000000
--- a/Lucene.Net.Tests.QueryParser/Classic/TestMultiPhraseQueryParsing.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-\ufeffusing Lucene.Net.Analysis;
-using Lucene.Net.Analysis.Tokenattributes;
-using Lucene.Net.Index;
-using Lucene.Net.Search;
-using Lucene.Net.Util;
-using NUnit.Framework;
-
-namespace Lucene.Net.QueryParser.Classic
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- [TestFixture]
- public class TestMultiPhraseQueryParsing_ : LuceneTestCase
- {
- private class TokenAndPos
- {
- public readonly string token;
- public readonly int pos;
- public TokenAndPos(string token, int pos)
- {
- this.token = token;
- this.pos = pos;
- }
- }
-
- private class CannedAnalyzer : Analyzer
- {
- private readonly TokenAndPos[] tokens;
-
- public CannedAnalyzer(TokenAndPos[] tokens)
- {
- this.tokens = tokens;
- }
-
- public override TokenStreamComponents CreateComponents(string fieldName, System.IO.TextReader reader)
- {
- return new TokenStreamComponents(new CannedTokenizer(reader, tokens));
- }
- }
-
- private class CannedTokenizer : Tokenizer
- {
- private readonly TokenAndPos[] tokens;
- private int upto = 0;
- private int lastPos = 0;
- private readonly ICharTermAttribute termAtt;
- private readonly IPositionIncrementAttribute posIncrAtt;
-
- public CannedTokenizer(System.IO.TextReader reader, TokenAndPos[] tokens)
- : base(reader)
- {
- this.tokens = tokens;
- this.termAtt = AddAttribute<ICharTermAttribute>();
- this.posIncrAtt = AddAttribute<IPositionIncrementAttribute>();
- }
-
- public override sealed bool IncrementToken()
- {
- ClearAttributes();
- if (upto < tokens.Length)
- {
- TokenAndPos token = tokens[upto++];
- termAtt.SetEmpty();
- termAtt.Append(token.token);
- posIncrAtt.PositionIncrement = (token.pos - lastPos);
- lastPos = token.pos;
- return true;
- }
- else
- {
- return false;
- }
- }
- public override void Reset()
- {
- base.Reset();
- this.upto = 0;
- this.lastPos = 0;
- }
- }
-
- [Test]
- public void TestMultiPhraseQueryParsing()
- {
- TokenAndPos[] INCR_0_QUERY_TOKENS_AND = new TokenAndPos[]
- {
- new TokenAndPos("a", 0),
- new TokenAndPos("1", 0),
- new TokenAndPos("b", 1),
- new TokenAndPos("1", 1),
- new TokenAndPos("c", 2)
- };
-
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new CannedAnalyzer(INCR_0_QUERY_TOKENS_AND));
- Query q = qp.Parse("\"this text is acually ignored\"");
- assertTrue("wrong query type!", q is MultiPhraseQuery);
-
- MultiPhraseQuery multiPhraseQuery = new MultiPhraseQuery();
- multiPhraseQuery.Add(new Term[] { new Term("field", "a"), new Term("field", "1") }, -1);
- multiPhraseQuery.Add(new Term[] { new Term("field", "b"), new Term("field", "1") }, 0);
- multiPhraseQuery.Add(new Term[] { new Term("field", "c") }, 1);
-
- assertEquals(multiPhraseQuery, q);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs b/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
deleted file mode 100644
index 369fe92..0000000
--- a/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
+++ /dev/null
@@ -1,564 +0,0 @@
-\ufeffusing Lucene.Net.Analysis;
-using Lucene.Net.Analysis.Tokenattributes;
-using Lucene.Net.Documents;
-using Lucene.Net.QueryParser.Flexible.Standard;
-using Lucene.Net.QueryParser.Util;
-using Lucene.Net.Search;
-using Lucene.Net.Support;
-using NUnit.Framework;
-using System;
-using System.Diagnostics;
-
-namespace Lucene.Net.QueryParser.Classic
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- [TestFixture]
- public class TestQueryParser : QueryParserTestBase
- {
- public class QPTestParser : QueryParser
- {
- public QPTestParser(string f, Analyzer a)
- : base(TEST_VERSION_CURRENT, f, a)
- {
- }
-
- protected internal override Query GetFuzzyQuery(string field, string termStr, float minSimilarity)
- {
- throw new ParseException("Fuzzy queries not allowed");
- }
-
- protected internal override Query GetWildcardQuery(string field, string termStr)
- {
- throw new ParseException("Wildcard queries not allowed");
- }
-
- }
-
- // Moved to QueryParserTestBase
- //public QueryParser GetParser(Analyzer a)
- //{
- // if (a == null) a = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true);
- // QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, DefaultField, a);
- // qp.DefaultOperator = (QueryParserBase.OR_OPERATOR);
- // return qp;
- //}
-
- // Moved to QueryParserTestBase
- //public override ICommonQueryParserConfiguration GetParserConfig(Analyzer a)
- //{
- // return GetParser(a);
- //}
-
- // Moved to QueryParserTestBase
- //public override Query GetQuery(string query, ICommonQueryParserConfiguration cqpC)
- //{
- // Debug.Assert(cqpC != null, "Parameter must not be null");
- // Debug.Assert(cqpC is QueryParser, "Parameter must be instance of QueryParser");
- // QueryParser qp = (QueryParser)cqpC;
- // return qp.Parse(query);
- //}
-
- // Moved to QueryParserTestBase
- //public override Query GetQuery(string query, Analyzer a)
- //{
- // return GetParser(a).Parse(query);
- //}
-
- // Moved to QueryParserTestBase
- //public override bool IsQueryParserException(Exception exception)
- //{
- // return exception is ParseException;
- //}
-
- // Moved to QueryParserTestBase
- //public override void SetDefaultOperatorOR(ICommonQueryParserConfiguration cqpC)
- //{
- // Debug.Assert(cqpC is QueryParser);
- // QueryParser qp = (QueryParser)cqpC;
- // qp.DefaultOperator = QueryParserBase.Operator.OR;
- //}
-
- // Moved to QueryParserTestBase
- //public override void SetDefaultOperatorAND(ICommonQueryParserConfiguration cqpC)
- //{
- // Debug.Assert(cqpC is QueryParser);
- // QueryParser qp = (QueryParser)cqpC;
- // qp.DefaultOperator = QueryParserBase.Operator.AND;
- //}
-
- // Moved to QueryParserTestBase
- //public override void SetAnalyzeRangeTerms(ICommonQueryParserConfiguration cqpC, bool value)
- //{
- // Debug.Assert(cqpC is QueryParser);
- // QueryParser qp = (QueryParser)cqpC;
- // qp.AnalyzeRangeTerms = (value);
- //}
-
- // Moved to QueryParserTestBase
- //public override void SetAutoGeneratePhraseQueries(ICommonQueryParserConfiguration cqpC, bool value)
- //{
- // Debug.Assert(cqpC is QueryParser);
- // QueryParser qp = (QueryParser)cqpC;
- // qp.AutoGeneratePhraseQueries = value;
- //}
-
- // Moved to QueryParserTestBase
- //public override void SetDateResolution(ICommonQueryParserConfiguration cqpC, ICharSequence field, DateTools.Resolution value)
- //{
- // Debug.Assert(cqpC is QueryParser);
- // QueryParser qp = (QueryParser)cqpC;
- // qp.SetDateResolution(field.toString(), value);
- //}
-
- [Test]
- public override void TestDefaultOperator()
- {
- QueryParser qp = GetParser(new MockAnalyzer(Random()));
- // make sure OR is the default:
- assertEquals(QueryParserBase.OR_OPERATOR, qp.DefaultOperator);
- SetDefaultOperatorAND(qp);
- assertEquals(QueryParserBase.AND_OPERATOR, qp.DefaultOperator);
- SetDefaultOperatorOR(qp);
- assertEquals(QueryParserBase.OR_OPERATOR, qp.DefaultOperator);
- }
-
- // LUCENE-2002: when we run javacc to regen QueryParser,
- // we also run a replaceregexp step to fix 2 of the public
- // ctors (change them to protected):
- //
- // protected QueryParser(CharStream stream)
- //
- // protected QueryParser(QueryParserTokenManager tm)
- //
- // This test is here as a safety, in case that ant step
- // doesn't work for some reason.
- [Test]
- public void TestProtectedCtors()
- {
- try
- {
- typeof(QueryParser).GetConstructor(new Type[] { typeof(ICharStream) });
- fail("please switch public QueryParser(CharStream) to be protected");
- }
- catch (Exception nsme)
- {
- // expected
- }
- try
- {
- typeof(QueryParser).GetConstructor(new Type[] { typeof(QueryParserTokenManager) });
- fail("please switch public QueryParser(QueryParserTokenManager) to be protected");
- }
- catch (Exception nsme)
- {
- // expected
- }
- }
-
- private class TestFuzzySlopeExtendabilityQueryParser : QueryParser
- {
- public TestFuzzySlopeExtendabilityQueryParser()
- : base(TEST_VERSION_CURRENT, "a", new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))
- {}
-
- protected internal override Query HandleBareFuzzy(string qfield, Token fuzzySlop, string termImage)
- {
- if (fuzzySlop.image.EndsWith("\u20ac"))
- {
- float fms = FuzzyMinSim;
- try
- {
- fms = float.Parse(fuzzySlop.image.Substring(1, fuzzySlop.image.Length - 2));
- }
- catch (Exception ignored) { }
- float value = float.Parse(termImage);
- return GetRangeQuery(qfield, (value - fms / 2.0f).ToString(), (value + fms / 2.0f).ToString(), true, true);
- }
- return base.HandleBareFuzzy(qfield, fuzzySlop, termImage);
- }
- }
-
- [Test]
- public void TestFuzzySlopeExtendability()
- {
- QueryParser qp = new TestFuzzySlopeExtendabilityQueryParser();
- assertEquals(qp.Parse("a:[11.95 TO 12.95]"), qp.Parse("12.45~1\u20ac"));
- }
-
- private class TestStarParsingQueryParser : QueryParser
- {
- public readonly int[] type = new int[1];
-
- public TestStarParsingQueryParser()
- : base(TEST_VERSION_CURRENT, "field", new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))
- { }
-
- protected internal override Query GetWildcardQuery(string field, string termStr)
- {
- // override error checking of superclass
- type[0] = 1;
- return new TermQuery(new Index.Term(field, termStr));
- }
-
- protected internal override Query GetPrefixQuery(string field, string termStr)
- {
- // override error checking of superclass
- type[0] = 2;
- return new TermQuery(new Index.Term(field, termStr));
- }
-
- protected internal override Query GetFieldQuery(string field, string queryText, bool quoted)
- {
- type[0] = 3;
- return base.GetFieldQuery(field, queryText, quoted);
- }
- }
-
- [Test]
- public override void TestStarParsing()
- {
- TestStarParsingQueryParser qp = new TestStarParsingQueryParser();
-
- TermQuery tq;
-
- tq = (TermQuery)qp.Parse("foo:zoo*");
- assertEquals("zoo", tq.Term.Text());
- assertEquals(2, qp.type[0]);
-
- tq = (TermQuery)qp.Parse("foo:zoo*^2");
- assertEquals("zoo", tq.Term.Text());
- assertEquals(2, qp.type[0]);
- assertEquals(tq.Boost, 2, 0);
-
- tq = (TermQuery)qp.Parse("foo:*");
- assertEquals("*", tq.Term.Text());
- assertEquals(1, qp.type[0]); // could be a valid prefix query in the future too
-
- tq = (TermQuery)qp.Parse("foo:*^2");
- assertEquals("*", tq.Term.Text());
- assertEquals(1, qp.type[0]);
- assertEquals(tq.Boost, 2, 0);
-
- tq = (TermQuery)qp.Parse("*:foo");
- assertEquals("*", tq.Term.Field);
- assertEquals("foo", tq.Term.Text());
- assertEquals(3, qp.type[0]);
-
- tq = (TermQuery)qp.Parse("*:*");
- assertEquals("*", tq.Term.Field);
- assertEquals("*", tq.Term.Text());
- assertEquals(1, qp.type[0]); // could be handled as a prefix query in the
- // future
-
- tq = (TermQuery)qp.Parse("(*:*)");
- assertEquals("*", tq.Term.Field);
- assertEquals("*", tq.Term.Text());
- assertEquals(1, qp.type[0]);
- }
-
- [Test]
- public void TestCustomQueryParserWildcard()
- {
- try
- {
- new QPTestParser("contents", new MockAnalyzer(Random(),
- MockTokenizer.WHITESPACE, false)).Parse("a?t");
- fail("Wildcard queries should not be allowed");
- }
- catch (ParseException expected)
- {
- // expected exception
- }
- }
-
- [Test]
- public void TestCustomQueryParserFuzzy()
- {
- try
- {
- new QPTestParser("contents", new MockAnalyzer(Random(),
- MockTokenizer.WHITESPACE, false)).Parse("xunit~");
- fail("Fuzzy queries should not be allowed");
- }
- catch (ParseException expected)
- {
- // expected exception
- }
- }
-
- /// <summary>
- /// query parser that doesn't expand synonyms when users use double quotes
- /// </summary>
- private class SmartQueryParser : QueryParser
- {
- Analyzer morePrecise = new Analyzer2();
-
- public SmartQueryParser()
- : base(TEST_VERSION_CURRENT, "field", new Analyzer1())
- {
- }
-
- protected internal override Query GetFieldQuery(string field, string queryText, bool quoted)
- {
- if (quoted) return NewFieldQuery(morePrecise, field, queryText, quoted);
- else return base.GetFieldQuery(field, queryText, quoted);
- }
- }
-
- public override void TestNewFieldQuery()
- {
- /** ordinary behavior, synonyms form uncoordinated boolean query */
- QueryParser dumb = new QueryParser(TEST_VERSION_CURRENT, "field",
- new Analyzer1());
- BooleanQuery expanded = new BooleanQuery(true);
- expanded.Add(new TermQuery(new Index.Term("field", "dogs")),
- BooleanClause.Occur.SHOULD);
- expanded.Add(new TermQuery(new Index.Term("field", "dog")),
- BooleanClause.Occur.SHOULD);
- assertEquals(expanded, dumb.Parse("\"dogs\""));
- /** even with the phrase operator the behavior is the same */
- assertEquals(expanded, dumb.Parse("dogs"));
-
- /**
- * custom behavior, the synonyms are expanded, unless you use quote operator
- */
- QueryParser smart = new SmartQueryParser();
- assertEquals(expanded, smart.Parse("dogs"));
-
- Query unexpanded = new TermQuery(new Index.Term("field", "dogs"));
- assertEquals(unexpanded, smart.Parse("\"dogs\""));
- }
-
- // LUCENETODO: fold these into QueryParserTestBase
-
- /// <summary>
- /// adds synonym of "dog" for "dogs".
- /// </summary>
- public class MockSynonymAnalyzer : Analyzer
- {
- public override TokenStreamComponents CreateComponents(string fieldName, System.IO.TextReader reader)
- {
- MockTokenizer tokenizer = new MockTokenizer(reader);
- return new TokenStreamComponents(tokenizer, new MockSynonymFilter(tokenizer));
- }
- }
-
- /// <summary>
- /// simple synonyms test
- /// </summary>
- [Test]
- public void TestSynonyms()
- {
- BooleanQuery expected = new BooleanQuery(true);
- expected.Add(new TermQuery(new Index.Term("field", "dogs")), BooleanClause.Occur.SHOULD);
- expected.Add(new TermQuery(new Index.Term("field", "dog")), BooleanClause.Occur.SHOULD);
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockSynonymAnalyzer());
- assertEquals(expected, qp.Parse("dogs"));
- assertEquals(expected, qp.Parse("\"dogs\""));
- qp.DefaultOperator = (QueryParserBase.Operator.AND);
- assertEquals(expected, qp.Parse("dogs"));
- assertEquals(expected, qp.Parse("\"dogs\""));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("dogs^2"));
- assertEquals(expected, qp.Parse("\"dogs\"^2"));
- }
-
- /// <summary>
- /// forms multiphrase query
- /// </summary>
- [Test]
- public void TestSynonymsPhrase()
- {
- MultiPhraseQuery expected = new MultiPhraseQuery();
- expected.Add(new Index.Term("field", "old"));
- expected.Add(new Index.Term[] { new Index.Term("field", "dogs"), new Index.Term("field", "dog") });
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockSynonymAnalyzer());
- assertEquals(expected, qp.Parse("\"old dogs\""));
- qp.DefaultOperator = (QueryParserBase.Operator.AND);
- assertEquals(expected, qp.Parse("\"old dogs\""));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\"old dogs\"^2"));
- expected.Slop = (3);
- assertEquals(expected, qp.Parse("\"old dogs\"~3^2"));
- }
-
- /// <summary>
- /// adds synonym of "\u570b" for "\u56fd".
- /// </summary>
- protected internal class MockCJKSynonymFilter : TokenFilter
- {
- internal ICharTermAttribute TermAtt;
- internal IPositionIncrementAttribute PosIncAtt;
- internal bool AddSynonym = false;
-
- public MockCJKSynonymFilter(TokenStream input)
- : base(input)
- {
- TermAtt = AddAttribute<ICharTermAttribute>();
- PosIncAtt = AddAttribute<IPositionIncrementAttribute>();
- }
-
- public sealed override bool IncrementToken()
- {
- if (AddSynonym) // inject our synonym
- {
- ClearAttributes();
- TermAtt.SetEmpty().Append("\u570b");
- PosIncAtt.PositionIncrement = 0;
- AddSynonym = false;
- return true;
- }
-
- if (input.IncrementToken())
- {
- AddSynonym = TermAtt.ToString().Equals("\u56fd");
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-
- protected class MockCJKSynonymAnalyzer : Analyzer
- {
- public override TokenStreamComponents CreateComponents(string fieldName, System.IO.TextReader reader)
- {
- Tokenizer tokenizer = new SimpleCJKTokenizer(reader);
- return new TokenStreamComponents(tokenizer, new MockCJKSynonymFilter(tokenizer));
- }
- }
-
- /// <summary>
- /// simple CJK synonym test
- /// </summary>
- [Test]
- public void TestCJKSynonym()
- {
- BooleanQuery expected = new BooleanQuery(true);
- expected.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- expected.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
- assertEquals(expected, qp.Parse("\u56fd"));
- qp.DefaultOperator = (QueryParserBase.Operator.AND);
- assertEquals(expected, qp.Parse("\u56fd"));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\u56fd^2"));
- }
-
- /// <summary>
- /// synonyms with default OR operator
- /// </summary>
- [Test]
- public void TestCJKSynonymsOR()
- {
- BooleanQuery expected = new BooleanQuery();
- expected.Add(new TermQuery(new Index.Term("field", "\u4e2d")), BooleanClause.Occur.SHOULD);
- BooleanQuery inner = new BooleanQuery(true);
- inner.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- inner.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- expected.Add(inner, BooleanClause.Occur.SHOULD);
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
- assertEquals(expected, qp.Parse("\u4e2d\u56fd"));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\u4e2d\u56fd^2"));
- }
-
- /// <summary>
- /// more complex synonyms with default OR operator
- /// </summary>
- [Test]
- public void TestCJKSynonymsOR2()
- {
- BooleanQuery expected = new BooleanQuery();
- expected.Add(new TermQuery(new Index.Term("field", "\u4e2d")), BooleanClause.Occur.SHOULD);
- BooleanQuery inner = new BooleanQuery(true);
- inner.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- inner.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- expected.Add(inner, BooleanClause.Occur.SHOULD);
- BooleanQuery inner2 = new BooleanQuery(true);
- inner2.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- inner2.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- expected.Add(inner2, BooleanClause.Occur.SHOULD);
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
- assertEquals(expected, qp.Parse("\u4e2d\u56fd\u56fd"));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\u4e2d\u56fd\u56fd^2"));
- }
-
- /// <summary>
- /// synonyms with default AND operator
- /// </summary>
- [Test]
- public void TestCJKSynonymsAND()
- {
- BooleanQuery expected = new BooleanQuery();
- expected.Add(new TermQuery(new Index.Term("field", "\u4e2d")), BooleanClause.Occur.MUST);
- BooleanQuery inner = new BooleanQuery(true);
- inner.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- inner.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- expected.Add(inner, BooleanClause.Occur.MUST);
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
- qp.DefaultOperator = (QueryParserBase.Operator.AND);
- assertEquals(expected, qp.Parse("\u4e2d\u56fd"));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\u4e2d\u56fd^2"));
- }
-
- /// <summary>
- /// more complex synonyms with default AND operator
- /// </summary>
- [Test]
- public void TestCJKSynonymsAND2()
- {
- BooleanQuery expected = new BooleanQuery();
- expected.Add(new TermQuery(new Index.Term("field", "\u4e2d")), BooleanClause.Occur.MUST);
- BooleanQuery inner = new BooleanQuery(true);
- inner.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- inner.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- expected.Add(inner, BooleanClause.Occur.MUST);
- BooleanQuery inner2 = new BooleanQuery(true);
- inner2.Add(new TermQuery(new Index.Term("field", "\u56fd")), BooleanClause.Occur.SHOULD);
- inner2.Add(new TermQuery(new Index.Term("field", "\u570b")), BooleanClause.Occur.SHOULD);
- expected.Add(inner2, BooleanClause.Occur.MUST);
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
- qp.DefaultOperator = (QueryParserBase.Operator.AND);
- assertEquals(expected, qp.Parse("\u4e2d\u56fd\u56fd"));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\u4e2d\u56fd\u56fd^2"));
- }
-
- [Test]
- public void TestCJKSynonymsPhrase()
- {
- MultiPhraseQuery expected = new MultiPhraseQuery();
- expected.Add(new Index.Term("field", "\u4e2d"));
- expected.Add(new Index.Term[] { new Index.Term("field", "\u56fd"), new Index.Term("field", "\u570b") });
- QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockCJKSynonymAnalyzer());
- qp.DefaultOperator = (QueryParserBase.Operator.AND);
- assertEquals(expected, qp.Parse("\"\u4e2d\u56fd\""));
- expected.Boost = (2.0f);
- assertEquals(expected, qp.Parse("\"\u4e2d\u56fd\"^2"));
- expected.Slop = (3);
- assertEquals(expected, qp.Parse("\"\u4e2d\u56fd\"~3^2"));
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs b/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
deleted file mode 100644
index 2c2d6e2..0000000
--- a/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
+++ /dev/null
@@ -1,214 +0,0 @@
-\ufeffusing Lucene.Net.Analysis;
-using Lucene.Net.Documents;
-using Lucene.Net.Index;
-using Lucene.Net.Search;
-using Lucene.Net.Store;
-using Lucene.Net.Util;
-using NUnit.Framework;
-using System;
-using System.Collections.Generic;
-
-namespace Lucene.Net.QueryParser.ComplexPhrase
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- [TestFixture]
- public class TestComplexPhraseQuery : LuceneTestCase
- {
- Directory rd;
- Analyzer analyzer;
- DocData[] docsContent = {
- new DocData("john smith", "1", "developer"),
- new DocData("johathon smith", "2", "developer"),
- new DocData("john percival smith", "3", "designer"),
- new DocData("jackson waits tom", "4", "project manager")
- };
-
- private IndexSearcher searcher;
- private IndexReader reader;
-
- string defaultFieldName = "name";
-
- bool inOrder = true;
-
- [Test]
- public void TestComplexPhrases()
- {
- CheckMatches("\"john smith\"", "1"); // Simple multi-term still works
- CheckMatches("\"j* smyth~\"", "1,2"); // wildcards and fuzzies are OK in
- // phrases
- CheckMatches("\"(jo* -john) smith\"", "2"); // boolean logic works
- CheckMatches("\"jo* smith\"~2", "1,2,3"); // position logic works.
- CheckMatches("\"jo* [sma TO smZ]\" ", "1,2"); // range queries supported
- CheckMatches("\"john\"", "1,3"); // Simple single-term still works
- CheckMatches("\"(john OR johathon) smith\"", "1,2"); // boolean logic with
- // brackets works.
- CheckMatches("\"(jo* -john) smyth~\"", "2"); // boolean logic with
- // brackets works.
-
- // CheckMatches("\"john -percival\"", "1"); // not logic doesn't work
- // currently :(.
-
- CheckMatches("\"john nosuchword*\"", ""); // phrases with clauses producing
- // empty sets
-
- CheckBadQuery("\"jo* id:1 smith\""); // mixing fields in a phrase is bad
- CheckBadQuery("\"jo* \"smith\" \""); // phrases inside phrases is bad
- }
-
- [Test]
- public void TestUnOrderedProximitySearches()
- {
- inOrder = true;
- CheckMatches("\"smith jo*\"~2", ""); // ordered proximity produces empty set
-
- inOrder = false;
- CheckMatches("\"smith jo*\"~2", "1,2,3"); // un-ordered proximity
- }
-
- private void CheckBadQuery(String qString)
- {
- ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
- qp.InOrder = inOrder;
- Exception expected = null;
- try
- {
- qp.Parse(qString);
- }
- catch (Exception e)
- {
- expected = e;
- }
- assertNotNull("Expected parse error in " + qString, expected);
- }
-
- private void CheckMatches(string qString, string expectedVals)
- {
- ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
- qp.InOrder = inOrder;
- qp.FuzzyPrefixLength = 1; // usually a good idea
-
- Query q = qp.Parse(qString);
-
- HashSet<string> expecteds = new HashSet<string>();
- string[] vals = expectedVals.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < vals.Length; i++)
- {
- if (vals[i].Length > 0)
- expecteds.Add(vals[i]);
- }
-
- TopDocs td = searcher.Search(q, 10);
- ScoreDoc[] sd = td.ScoreDocs;
- for (int i = 0; i < sd.Length; i++)
- {
- Document doc = searcher.Doc(sd[i].Doc);
- string id = doc.Get("id");
- assertTrue(qString + "matched doc#" + id + " not expected", expecteds
- .Contains(id));
- expecteds.Remove(id);
- }
-
- assertEquals(qString + " missing some matches ", 0, expecteds.Count);
- }
-
- [Test]
- public void TestFieldedQuery()
- {
- CheckMatches("name:\"john smith\"", "1");
- CheckMatches("name:\"j* smyth~\"", "1,2");
- CheckMatches("role:\"developer\"", "1,2");
- CheckMatches("role:\"p* manager\"", "4");
- CheckMatches("role:de*", "1,2,3");
- CheckMatches("name:\"j* smyth~\"~5", "1,2,3");
- CheckMatches("role:\"p* manager\" AND name:jack*", "4");
- CheckMatches("+role:developer +name:jack*", "");
- CheckMatches("name:\"john smith\"~2 AND role:designer AND id:3", "3");
- }
-
- [Test]
- public void TestHashcodeEquals()
- {
- ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
- qp.InOrder = true;
- qp.FuzzyPrefixLength = 1;
-
- String qString = "\"aaa* bbb*\"";
-
- Query q = qp.Parse(qString);
- Query q2 = qp.Parse(qString);
-
- assertEquals(q.GetHashCode(), q2.GetHashCode());
- assertEquals(q, q2);
-
- qp.InOrder = (false); // SOLR-6011
-
- q2 = qp.Parse(qString);
-
- // although the general contract of hashCode can't guarantee different values, if we only change one thing
- // about a single query, it normally should result in a different value (and will with the current
- // implementation in ComplexPhraseQuery)
- assertTrue(q.GetHashCode() != q2.GetHashCode());
- assertTrue(!q.equals(q2));
- assertTrue(!q2.equals(q));
- }
-
- public override void SetUp()
- {
- base.SetUp();
-
- analyzer = new MockAnalyzer(Random());
- rd = NewDirectory();
- using (IndexWriter w = new IndexWriter(rd, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)))
- {
- for (int i = 0; i < docsContent.Length; i++)
- {
- Document doc = new Document();
- doc.Add(NewTextField("name", docsContent[i].Name, Field.Store.YES));
- doc.Add(NewTextField("id", docsContent[i].Id, Field.Store.YES));
- doc.Add(NewTextField("role", docsContent[i].Role, Field.Store.YES));
- w.AddDocument(doc);
- }
- }
- reader = DirectoryReader.Open(rd);
- searcher = NewSearcher(reader);
- }
-
- public override void TearDown()
- {
- reader.Dispose();
- rd.Dispose();
- base.TearDown();
- }
-
-
- private class DocData
- {
- public DocData(string name, string id, string role)
- {
- this.Name = name;
- this.Id = id;
- this.Role = role;
- }
-
- public string Name { get; private set; }
- public string Id { get; private set; }
- public string Role { get; private set; }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Ext/ExtensionStub.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Ext/ExtensionStub.cs b/Lucene.Net.Tests.QueryParser/Ext/ExtensionStub.cs
deleted file mode 100644
index cbef5d8..0000000
--- a/Lucene.Net.Tests.QueryParser/Ext/ExtensionStub.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-\ufeffusing Lucene.Net.Index;
-using Lucene.Net.Search;
-
-namespace Lucene.Net.QueryParser.Ext
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- internal class ExtensionStub : ParserExtension
- {
- public override Query Parse(ExtensionQuery components)
- {
- return new TermQuery(new Term(components.Field, components.RawQueryString));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Ext/TestExtendableQueryParser.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Ext/TestExtendableQueryParser.cs b/Lucene.Net.Tests.QueryParser/Ext/TestExtendableQueryParser.cs
deleted file mode 100644
index 7e2e99e..0000000
--- a/Lucene.Net.Tests.QueryParser/Ext/TestExtendableQueryParser.cs
+++ /dev/null
@@ -1,145 +0,0 @@
-\ufeffusing Lucene.Net.Analysis;
-using Lucene.Net.QueryParser.Classic;
-using Lucene.Net.Search;
-using NUnit.Framework;
-using System.Globalization;
-
-namespace Lucene.Net.QueryParser.Ext
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /// <summary>
- /// Testcase for the class <see cref="ExtendableQueryParser"/>
- /// </summary>
- [TestFixture]
- public class TestExtendableQueryParser : TestQueryParser
- {
- private static char[] DELIMITERS = new char[] {
- Extensions.DEFAULT_EXTENSION_FIELD_DELIMITER, '-', '|' };
-
- public override Classic.QueryParser GetParser(Analyzer a)
- {
- return GetParser(a, null);
- }
-
- public Classic.QueryParser GetParser(Analyzer a, Extensions extensions)
- {
- if (a == null)
- a = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true);
- Classic.QueryParser qp = extensions == null ? new ExtendableQueryParser(
- TEST_VERSION_CURRENT, DefaultField, a) : new ExtendableQueryParser(
- TEST_VERSION_CURRENT, DefaultField, a, extensions);
- qp.DefaultOperator = QueryParserBase.OR_OPERATOR;
- return qp;
- }
-
- [Test]
- public void TestUnescapedExtDelimiter()
- {
- Extensions ext = NewExtensions(':');
- ext.Add("testExt", new ExtensionStub());
- ExtendableQueryParser parser = (ExtendableQueryParser)GetParser(null, ext);
- try
- {
- parser.Parse("aField:testExt:\"foo \\& bar\"");
- fail("extension field delimiter is not escaped");
- }
- catch (ParseException e)
- {
- }
- }
-
- [Test]
- public void TestExtFieldUnqoted()
- {
- for (int i = 0; i < DELIMITERS.Length; i++)
- {
- Extensions ext = NewExtensions(DELIMITERS[i]);
- ext.Add("testExt", new ExtensionStub());
- ExtendableQueryParser parser = (ExtendableQueryParser)GetParser(null,
- ext);
- string field = ext.BuildExtensionField("testExt", "aField");
- Query query = parser.Parse(string.Format(CultureInfo.InvariantCulture, "{0}:foo bar", field));
- assertTrue("expected instance of BooleanQuery but was "
- + query.GetType(), query is BooleanQuery);
- BooleanQuery bquery = (BooleanQuery)query;
- BooleanClause[] clauses = bquery.Clauses;
- assertEquals(2, clauses.Length);
- BooleanClause booleanClause = clauses[0];
- query = booleanClause.Query;
- assertTrue("expected instance of TermQuery but was " + query.GetType(),
- query is TermQuery);
- TermQuery tquery = (TermQuery)query;
- assertEquals("aField", tquery.Term
- .Field);
- assertEquals("foo", tquery.Term.Text());
-
- booleanClause = clauses[1];
- query = booleanClause.Query;
- assertTrue("expected instance of TermQuery but was " + query.GetType(),
- query is TermQuery);
- tquery = (TermQuery)query;
- assertEquals(DefaultField, tquery.Term.Field);
- assertEquals("bar", tquery.Term.Text());
- }
- }
-
- [Test]
- public void TestExtDefaultField()
- {
- for (int i = 0; i < DELIMITERS.Length; i++)
- {
- Extensions ext = NewExtensions(DELIMITERS[i]);
- ext.Add("testExt", new ExtensionStub());
- ExtendableQueryParser parser = (ExtendableQueryParser)GetParser(null,
- ext);
- string field = ext.BuildExtensionField("testExt");
- Query parse = parser.Parse(string.Format(CultureInfo.InvariantCulture, "{0}:\"foo \\& bar\"", field));
- assertTrue("expected instance of TermQuery but was " + parse.GetType(),
- parse is TermQuery);
- TermQuery tquery = (TermQuery)parse;
- assertEquals(DefaultField, tquery.Term.Field);
- assertEquals("foo & bar", tquery.Term.Text());
- }
- }
-
- public Extensions NewExtensions(char delimiter)
- {
- return new Extensions(delimiter);
- }
-
- [Test]
- public void TestExtField()
- {
- for (int i = 0; i < DELIMITERS.Length; i++)
- {
- Extensions ext = NewExtensions(DELIMITERS[i]);
- ext.Add("testExt", new ExtensionStub());
- ExtendableQueryParser parser = (ExtendableQueryParser)GetParser(null,
- ext);
- string field = ext.BuildExtensionField("testExt", "afield");
- Query parse = parser.Parse(string.Format(CultureInfo.InvariantCulture, "{0}:\"foo \\& bar\"", field));
- assertTrue("expected instance of TermQuery but was " + parse.GetType(),
- parse is TermQuery);
- TermQuery tquery = (TermQuery)parse;
- assertEquals("afield", tquery.Term.Field);
- assertEquals("foo & bar", tquery.Term.Text());
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Ext/TestExtensions.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Ext/TestExtensions.cs b/Lucene.Net.Tests.QueryParser/Ext/TestExtensions.cs
deleted file mode 100644
index 4850987..0000000
--- a/Lucene.Net.Tests.QueryParser/Ext/TestExtensions.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-\ufeffusing Lucene.Net.Util;
-using NUnit.Framework;
-using System;
-
-namespace Lucene.Net.QueryParser.Ext
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /// <summary>
- /// Testcase for the <see cref="Extensions"/> class
- /// </summary>
- [TestFixture]
- public class TestExtensions : LuceneTestCase
- {
- private Extensions ext;
-
- public override void SetUp()
- {
- base.SetUp();
- this.ext = new Extensions();
- }
-
- [Test]
- public void TestBuildExtensionField()
- {
- assertEquals("field\\:key", ext.BuildExtensionField("key", "field"));
- assertEquals("\\:key", ext.BuildExtensionField("key"));
-
- ext = new Extensions('.');
- assertEquals("field.key", ext.BuildExtensionField("key", "field"));
- assertEquals(".key", ext.BuildExtensionField("key"));
- }
-
- [Test]
- public void TestSplitExtensionField()
- {
- assertEquals("field\\:key", ext.BuildExtensionField("key", "field"));
- assertEquals("\\:key", ext.BuildExtensionField("key"));
-
- ext = new Extensions('.');
- assertEquals("field.key", ext.BuildExtensionField("key", "field"));
- assertEquals(".key", ext.BuildExtensionField("key"));
- }
-
- [Test]
- public void TestAddGetExtension()
- {
- ParserExtension extension = new ExtensionStub();
- assertNull(ext.GetExtension("foo"));
- ext.Add("foo", extension);
- Assert.AreSame(extension, ext.GetExtension("foo"));
- ext.Add("foo", null);
- assertNull(ext.GetExtension("foo"));
- }
-
- [Test]
- public void TestGetExtDelimiter()
- {
- assertEquals(Extensions.DEFAULT_EXTENSION_FIELD_DELIMITER, this.ext
- .ExtensionFieldDelimiter);
- ext = new Extensions('?');
- assertEquals('?', this.ext.ExtensionFieldDelimiter);
- }
-
- [Test]
- public void TestEscapeExtension()
- {
- assertEquals("abc\\:\\?\\{\\}\\[\\]\\\\\\(\\)\\+\\-\\!\\~", ext
- .EscapeExtensionField("abc:?{}[]\\()+-!~"));
- try
- {
- ext.EscapeExtensionField(null);
- fail("should throw NPE - escape string is null");
- }
- //catch (NullPointerException e)
- catch (Exception e)
- {
- //
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj b/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
deleted file mode 100644
index 2094270..0000000
--- a/Lucene.Net.Tests.QueryParser/Lucene.Net.Tests.QueryParser.csproj
+++ /dev/null
@@ -1,95 +0,0 @@
-\ufeff<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProjectGuid>{5719FB4F-BF80-40E5-BACC-37E8E18FCA2E}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Lucene.Net.Tests.QueryParser</RootNamespace>
- <AssemblyName>Lucene.Net.Tests.QueryParser</AssemblyName>
- <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
- <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
- <Private>True</Private>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Analyzing\TestAnalyzingQueryParser.cs" />
- <Compile Include="Classic\TestMultiFieldQueryParser.cs" />
- <Compile Include="Classic\TestMultiPhraseQueryParsing.cs" />
- <Compile Include="Classic\TestQueryParser.cs" />
- <Compile Include="ComplexPhrase\TestComplexPhraseQuery.cs" />
- <Compile Include="Ext\ExtensionStub.cs" />
- <Compile Include="Ext\TestExtendableQueryParser.cs" />
- <Compile Include="Ext\TestExtensions.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Classic\TestMultiAnalyzer.cs" />
- <Compile Include="Simple\TestSimpleQueryParser.cs" />
- <Compile Include="Surround\Query\BooleanQueryTst.cs" />
- <Compile Include="Surround\Query\ExceptionQueryTst.cs" />
- <Compile Include="Surround\Query\SingleFieldTestDb.cs" />
- <Compile Include="Surround\Query\SrndQueryTest.cs" />
- <Compile Include="Surround\Query\Test01Exceptions.cs" />
- <Compile Include="Surround\Query\Test02Boolean.cs" />
- <Compile Include="Surround\Query\Test03Distance.cs" />
- <Compile Include="Util\QueryParserTestBase.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Lucene.Net.QueryParser\Lucene.Net.QueryParser.csproj">
- <Project>{949ba34b-6ae6-4ce3-b578-61e13e4d76bf}</Project>
- <Name>Lucene.Net.QueryParser</Name>
- </ProjectReference>
- <ProjectReference Include="..\src\Lucene.Net.Analysis.Common\Lucene.Net.Analysis.Common.csproj">
- <Project>{4add0bbc-b900-4715-9526-d871de8eea64}</Project>
- <Name>Lucene.Net.Analysis.Common</Name>
- </ProjectReference>
- <ProjectReference Include="..\src\Lucene.Net.Core\Lucene.Net.csproj">
- <Project>{5d4ad9be-1ffb-41ab-9943-25737971bf57}</Project>
- <Name>Lucene.Net</Name>
- </ProjectReference>
- <ProjectReference Include="..\src\Lucene.Net.TestFramework\Lucene.Net.TestFramework.csproj">
- <Project>{b2c0d749-ce34-4f62-a15e-00cb2ff5ddb3}</Project>
- <Name>Lucene.Net.TestFramework</Name>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/679ad24c/Lucene.Net.Tests.QueryParser/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/Lucene.Net.Tests.QueryParser/Properties/AssemblyInfo.cs b/Lucene.Net.Tests.QueryParser/Properties/AssemblyInfo.cs
deleted file mode 100644
index 549c7bf..0000000
--- a/Lucene.Net.Tests.QueryParser/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-\ufeffusing System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Lucene.Net.Tests.QueryParser")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Lucene.Net.Tests.QueryParser")]
-[assembly: AssemblyCopyright("Copyright � 2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("27d0ae76-3e51-454c-9c4a-f913fde0ed0a")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]