FileDocCategorySizeDatePackage
TestBooleanOr.javaAPI DocApache Lucene 1.95095Mon Feb 20 09:19:32 GMT 2006org.apache.lucene.search

TestBooleanOr

public class TestBooleanOr extends TestCase
Created on 2005. 2. 9.
Adapted to Lucene testcase by Paul Elschot.
author
appler@gmail.com

Fields Summary
private static String
FIELD_T
private static String
FIELD_C
private TermQuery
t1
private TermQuery
t2
private TermQuery
c1
private TermQuery
c2
private IndexSearcher
searcher
Constructors Summary
Methods Summary
private intsearch(org.apache.lucene.search.Query q)


	      
		return searcher.search(q).length();
	
protected voidsetUp()

		super.setUp();

		//
		RAMDirectory rd = new RAMDirectory();

		//
		IndexWriter writer = new IndexWriter(rd, new StandardAnalyzer(), true);

		//
		Document d = new Document();
		d.add(new Field(
				FIELD_T,
				"Optimize not deleting all files",
				Field.Store.YES,
				Field.Index.TOKENIZED));
		d.add(new Field(
				FIELD_C,
				"Deleted When I run an optimize in our production environment.",
				Field.Store.YES,
				Field.Index.TOKENIZED));

		//
		writer.addDocument(d);
		writer.close();

		//
		searcher = new IndexSearcher(rd);
	
public voidtestElements()

		assertEquals(1, search(t1));
		assertEquals(1, search(t2));
		assertEquals(1, search(c1));
		assertEquals(1, search(c2));
	
public voidtestFlat()
T:files T:deleting C:production C:optimize it works.

throws
IOException

		BooleanQuery q = new BooleanQuery();
		q.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
		q.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
		q.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD));
		q.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD));
		assertEquals(1, search(q));
	
public voidtestParenthesisMust()
(T:files T:deleting) (+C:production +C:optimize) it works.

throws
IOException

		BooleanQuery q3 = new BooleanQuery();
		q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
		q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
		BooleanQuery q4 = new BooleanQuery();
		q4.add(new BooleanClause(c1, BooleanClause.Occur.MUST));
		q4.add(new BooleanClause(c2, BooleanClause.Occur.MUST));
		BooleanQuery q2 = new BooleanQuery();
		q2.add(q3, BooleanClause.Occur.SHOULD);
		q2.add(q4, BooleanClause.Occur.SHOULD);
		assertEquals(1, search(q2));
	
public voidtestParenthesisMust2()
(T:files T:deleting) +(C:production C:optimize) not working. results NO HIT.

throws
IOException

		BooleanQuery q3 = new BooleanQuery();
		q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
		q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
		BooleanQuery q4 = new BooleanQuery();
		q4.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD));
		q4.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD));
		BooleanQuery q2 = new BooleanQuery();
		q2.add(q3, BooleanClause.Occur.SHOULD);
		q2.add(q4, BooleanClause.Occur.MUST);
		assertEquals(1, search(q2));
	
public voidtestParenthesisShould()
(T:files T:deleting) (C:production C:optimize) not working. results NO HIT.

throws
IOException

		BooleanQuery q3 = new BooleanQuery();
		q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
		q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
		BooleanQuery q4 = new BooleanQuery();
		q4.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD));
		q4.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD));
		BooleanQuery q2 = new BooleanQuery();
		q2.add(q3, BooleanClause.Occur.SHOULD);
		q2.add(q4, BooleanClause.Occur.SHOULD);
		assertEquals(1, search(q2));