Exemplo n.º 1
0
	void testSrchPunctuation(CuTest *tc ){
		CuAssert(tc,_T("Searcher was not open"),s!=NULL);

		//test punctuation
		_TestSearchesRun(tc, &a,s, _T("a&b") );
		_TestSearchesRun(tc, &a,s, _T("a&&b") );
		_TestSearchesRun(tc, &a,s, _T(".NET") );
	}
Exemplo n.º 2
0
	void testSrchSlop(CuTest *tc ){
#ifdef NO_FUZZY_QUERY
		CuNotImpl(tc,_T("Fuzzy"));
#else
		CuAssert(tc,_T("Searcher was not open"),s!=NULL);
		//test slop
		_TestSearchesRun(tc, &a,s, _T("\"term germ\"~2") );
		_TestSearchesRun(tc, &a,s, _T("\"term germ\"~2 flork") );
		_TestSearchesRun(tc, &a,s, _T("\"term\"~2") );
		_TestSearchesRun(tc, &a,s, _T("\" \"~2 germ") );
		_TestSearchesRun(tc, &a,s, _T("\"term germ\"~2^2") );
#endif
	}
Exemplo n.º 3
0
	void testSrchWildcard(CuTest *tc ){
#ifdef NO_WILDCARD_QUERY
		CuNotImpl(tc,_T("Wildcard"));
#else
		CuAssert(tc,_T("Searcher was not open"),s!=NULL);
		//testWildcard
		_TestSearchesRun(tc, &a,s, _T("term*") );
		_TestSearchesRun(tc, &a,s, _T("term*^2") );
		_TestSearchesRun(tc, &a,s, _T("term~") );
		_TestSearchesRun(tc, &a,s, _T("term^2~") );
		_TestSearchesRun(tc, &a,s, _T("term~^2") );
		_TestSearchesRun(tc, &a,s, _T("term*germ") );
		_TestSearchesRun(tc, &a,s, _T("term*germ^3") );

		//test problem reported by Gary Mangum
		BooleanQuery* bq = _CLNEW BooleanQuery();
		Term* upper = _CLNEW Term(_T("contents"),_T("0105"));
		Term* lower = _CLNEW Term(_T("contents"),_T("0105"));
		RangeQuery* rq=_CLNEW RangeQuery(lower,upper,true);
		bq->add(rq,true,true,false);
		_CLDECDELETE(upper);
		_CLDECDELETE(lower);

		Term* prefix = _CLNEW Term(_T("contents"),_T("reuters21578"));
		PrefixQuery* pq = _CLNEW PrefixQuery(prefix);
		_CLDECDELETE(prefix);
		bq->add(pq,true,true,false);

		Hits* h = NULL;
		try{
			h = s->search( bq );
		}_CLFINALLY(
		_CLDELETE(h);
		_CLDELETE(bq);
		);
Exemplo n.º 4
0
	void testSrchNumbers(CuTest *tc ){
		CuAssert(tc,_T("Searcher was not open"),s!=NULL);

		// The numbers go away because SimpleAnalzyer ignores them
		_TestSearchesRun(tc, &a,s, _T("3") );
		_TestSearchesRun(tc, &a,s, _T("term 1.0 1 2") );
		_TestSearchesRun(tc, &a,s, _T("term term1 term2") );

		_TestSearchesRun(tc, &aStd,s, _T("3") );
		_TestSearchesRun(tc, &aStd,s, _T("term 1.0 1 2") );
		_TestSearchesRun(tc, &aStd,s, _T("term term1 term2") );
	}
Exemplo n.º 5
0
	void TestSearches(const char_t* index){
		long_t start = lucene::util::Misc::currentTimeMillis();
		IndexSearcher s(index);
		SimpleAnalyzer a;
		StandardAnalyzer aStd;
		WhitespaceAnalyzer aWS;

		//simple tests
		cout << "Simple tests\n";
		_TestSearchesRun(a,s, _T("a AND b") );
		_TestSearchesRun(a,s, _T("term term term") );
		_TestSearchesRun(a,s, _T("türm term term") );
		
		_TestSearchesRun(a,s, _T("ümlaut") );

		_TestSearchesRun(a,s, _T("(a AND b)") );
		_TestSearchesRun(a,s, _T("c OR (a AND b)") );
		_TestSearchesRun(a,s, _T("a AND NOT b") );
		_TestSearchesRun(a,s, _T("a AND -b") );
		_TestSearchesRun(a,s, _T("a AND !b") );
		_TestSearchesRun(a,s, _T("a && b") );
		_TestSearchesRun(a,s, _T("a && ! b") );

		_TestSearchesRun(a,s, _T("a OR b") );
		_TestSearchesRun(a,s, _T("a || b") );
		_TestSearchesRun(a,s, _T("a OR !b") );
		_TestSearchesRun(a,s, _T("a OR ! b") );
		_TestSearchesRun(a,s, _T("a OR -b") );

		_TestSearchesRun(a,s, _T("+term -term term") );
		_TestSearchesRun(a,s, _T("foo:term AND field:anotherTerm") );
		_TestSearchesRun(a,s, _T("term AND \"phrase phrase\"") );
		_TestSearchesRun(a,s, _T("\"hello there\"") );

		_TestSearchesRun(a,s,  _T("a AND b") );
		_TestSearchesRun(a,s,  _T("hello") );
		_TestSearchesRun(a,s,  _T("\"hello there\"") );

		_TestSearchesRun(a,s, _T("germ term^2.0") );
		_TestSearchesRun(a,s, _T("term^2.0") );
		_TestSearchesRun(a,s, _T("term^2") );
		_TestSearchesRun(a,s, _T("term^2.3") );
		_TestSearchesRun(a,s, _T("\"germ term\"^2.0") );
		_TestSearchesRun(a,s, _T("\"term germ\"^2") );

		_TestSearchesRun(a,s, _T("(foo OR bar) AND (baz OR boo)") );
		_TestSearchesRun(a,s, _T("((a OR b) AND NOT c) OR d") );
		_TestSearchesRun(a,s, _T("+(apple \"steve jobs\") -(foo bar baz)") );
		_TestSearchesRun(a,s, _T("+title:(dog OR cat) -author:\"bob dole\"") );

		//test punctuation
		cout << "punctuation tests\n";
		_TestSearchesRun(a,s, _T("a&b") );
		_TestSearchesRun(a,s, _T("a&&b") );
		_TestSearchesRun(a,s, _T(".NET") );

		//test slop
		cout << "test slop\n";
		_TestSearchesRun(a,s, _T("\"term germ\"~2") );
		_TestSearchesRun(a,s, _T("\"term germ\"~2 flork") );
		_TestSearchesRun(a,s, _T("\"term\"~2") );
		_TestSearchesRun(a,s, _T("\" \"~2 germ") );
		_TestSearchesRun(a,s, _T("\"term germ\"~2^2") );

		// The numbers go away because SimpleAnalzyer ignores them
		cout << "Numbers test w/ SimpleAnalzyer&StandardAnalyzer\n";
		_TestSearchesRun(a,s, _T("3") );
		_TestSearchesRun(a,s, _T("term 1.0 1 2") );
		_TestSearchesRun(a,s, _T("term term1 term2") );

		_TestSearchesRun(aStd,s, _T("3") );
		_TestSearchesRun(aStd,s, _T("term 1.0 1 2") );
		_TestSearchesRun(aStd,s, _T("term term1 term2") );

		//testWildcard
		cout << "testWildcard\n";
		_TestSearchesRun(a,s, _T("term*") );
		_TestSearchesRun(a,s, _T("term*^2") );
		_TestSearchesRun(a,s, _T("term~") );
		_TestSearchesRun(a,s, _T("term^2~") );
		_TestSearchesRun(a,s, _T("term~^2") );
		_TestSearchesRun(a,s, _T("term*germ") );
		_TestSearchesRun(a,s, _T("term*germ^3") );


		//testEscaped
		cout << "testEscaped\n";
		_TestSearchesRun(aWS,s, _T("\\[brackets") );
		_TestSearchesRun(a,s, _T("\\[brackets") );
		_TestSearchesRun(aWS,s, _T("\\\\") );
		_TestSearchesRun(aWS,s, _T("\\+blah") );
		_TestSearchesRun(aWS,s, _T("\\(blah") );


		//testRange
		cout << "testRange (this can take a long time!)\n";
		_TestSearchesRun(a,s, _T("[ a z]") );
		_TestSearchesRun(a,s, _T("[ a z ]") );
		_TestSearchesRun(a,s, _T("{ a z}") );
		_TestSearchesRun(a,s, _T("{ a z }") );
		_TestSearchesRun(a,s, _T("{ a z }^2.0") );
		_TestSearchesRun(a,s, _T("[ a z] OR bar") );
		_TestSearchesRun(a,s, _T("[ a z] AND bar") );
		_TestSearchesRun(a,s, _T("( bar blar { a z}) ") );
		_TestSearchesRun(a,s, _T("gack ( bar blar { a z}) ") );

		s.close();
		_cout << (lucene::util::Misc::currentTimeMillis()-start) << _T(" milliseconds") << endl;
  }