wikimovie_preprocessing/ssquad/src/edu/cmu/ml/ssquad/store/DocumentStore.java
public List<SearchResult> search(String text, Properties otherPosFields, Properties otherNegFields, List<String> additionalFields) throws IOException {
		if (this.searcher == null) this.freeze();
		System.err.println(text);

		// Build a Query object
		QueryBuilder qb = new QueryBuilder(new StandardAnalyzer());
		TreeSet<String> pool = new TreeSet<String>();
		ArrayList<SearchResult> results = new ArrayList<SearchResult>();

		BooleanQuery.Builder bb = new BooleanQuery.Builder();
		for (String s : text.split("@placeholder")) {
			if (s == null || s.trim().length()<2) continue;
			org.apache.lucene.search.Query q = null;
			//System.err.println(s);
			try {
				q = qb.createPhraseQuery("text", s);
				if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
				q = qb.createBooleanQuery("text", s, BooleanClause.Occur.SHOULD);
				if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
                if (additionalFields != null) {
                    for (String field : additionalFields) {
                        q = qb.createPhraseQuery(field, s);
                        if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
                        q = qb.createBooleanQuery(field, s, BooleanClause.Occur.SHOULD);
                        if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
                    }
                }
			} catch(Exception e) {
				throw new IllegalStateException("while running query "+q+" for text '"+s+"'",e);
			}
		}
		if (otherPosFields != null) {
			for (String field : otherPosFields.stringPropertyNames()) {
				org.apache.lucene.search.Query q = qb.createPhraseQuery(field, otherPosFields.getProperty(field));
				if (q != null) bb.add(q,BooleanClause.Occur.MUST);
			}
		}
		if (otherNegFields != null) {
			for (String field : otherNegFields.stringPropertyNames()) {
				org.apache.lucene.search.Query q = qb.createPhraseQuery(field, otherNegFields.getProperty(field));
				if (q != null) bb.add(q,BooleanClause.Occur.MUST_NOT);
			}
		}

		//		org.apache.lucene.search.Query query = qb.createPhraseQuery("content", queryString);
		//		org.apache.lucene.search.Query query = qb.createBooleanQuery("text", queryString);
		BooleanQuery q = bb.build();
		//System.err.println(q.toString());
		// Search for the query
		TopDocs hits = searcher.search(q,TOPK*100);

		// add stored document contents
		if (hits.totalHits != 0 ) {
//			System.err.println(text);
			System.err.println(hits.totalHits+" results");
			for (ScoreDoc sd : hits.scoreDocs) {
				Document doc = searcher.doc(sd.doc);
				//System.err.println(sd.score+"\t"+sd.doc+"\t"+doc.get("content"));
				//System.err.println(sd.score+"\t"+sd.doc+"\t"+doc.get("id"));
                String id = doc.get("id");
				String content = doc.get("content");
				if (!pool.contains(content)) results.add(new SearchResult(sd.score,id,content));
				pool.add(content);
				if (results.size()==TOPK) break;
			}
		} else { System.err.println("No results"); }
		//results.addAll(pool);
		return results;
	}
/**
	 * Searches for the given string in the "content" field
	 */
Searches for the given string in the "content" field
Searches for the given string in the " content " field
public List<SearchResult> search(String text, Properties otherPosFields, Properties otherNegFields, List<String> additionalFields) throws IOException {
		if (this.searcher == null) this.freeze();
		System.err.println(text);
		QueryBuilder qb = new QueryBuilder(new StandardAnalyzer());
		TreeSet<String> pool = new TreeSet<String>();
		ArrayList<SearchResult> results = new ArrayList<SearchResult>();
		BooleanQuery.Builder bb = new BooleanQuery.Builder();
		for (String s : text.split("@placeholder")) {
			if (s == null || s.trim().length()<2) continue;
			org.apache.lucene.search.Query q = null;
			try {
				q = qb.createPhraseQuery("text", s);
				if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
				q = qb.createBooleanQuery("text", s, BooleanClause.Occur.SHOULD);
				if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
                if (additionalFields != null) {
                    for (String field : additionalFields) {
                        q = qb.createPhraseQuery(field, s);
                        if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
                        q = qb.createBooleanQuery(field, s, BooleanClause.Occur.SHOULD);
                        if (q != null) bb.add(q,BooleanClause.Occur.SHOULD);
                    }
                }
			} catch(Exception e) {
				throw new IllegalStateException("while running query "+q+" for text '"+s+"'",e);
			}
		}
		if (otherPosFields != null) {
			for (String field : otherPosFields.stringPropertyNames()) {
				org.apache.lucene.search.Query q = qb.createPhraseQuery(field, otherPosFields.getProperty(field));
				if (q != null) bb.add(q,BooleanClause.Occur.MUST);
			}
		}
		if (otherNegFields != null) {
			for (String field : otherNegFields.stringPropertyNames()) {
				org.apache.lucene.search.Query q = qb.createPhraseQuery(field, otherNegFields.getProperty(field));
				if (q != null) bb.add(q,BooleanClause.Occur.MUST_NOT);
			}
		}
		BooleanQuery q = bb.build();
		TopDocs hits = searcher.search(q,TOPK*100);
		if (hits.totalHits != 0 ) {
			System.err.println(hits.totalHits+" results");
			for (ScoreDoc sd : hits.scoreDocs) {
				Document doc = searcher.doc(sd.doc);
                String id = doc.get("id");
				String content = doc.get("content");
				if (!pool.contains(content)) results.add(new SearchResult(sd.score,id,content));
				pool.add(content);
				if (results.size()==TOPK) break;
			}
		} else { System.err.println("No results"); }
		return results;
	}
public List < SearchResult > search ( String text , Properties otherPosFields , Properties otherNegFields , List < String > additionalFields ) throws IOException { if ( this . searcher == null ) this . freeze ( ) ; System . err . println ( text ) ; QueryBuilder qb = new QueryBuilder ( new StandardAnalyzer ( ) ) ; TreeSet < String > pool = new TreeSet < String > ( ) ; ArrayList < SearchResult > results = new ArrayList < SearchResult > ( ) ; BooleanQuery . Builder bb = new BooleanQuery . Builder ( ) ; for ( String s : text . split ( "@placeholder" ) ) { if ( s == null || s . trim ( ) . length ( ) < 2 ) continue ; org . apache . lucene . search . Query q = null ; try { q = qb . createPhraseQuery ( "text" , s ) ; if ( q != null ) bb . add ( q , BooleanClause . Occur . SHOULD ) ; q = qb . createBooleanQuery ( "text" , s , BooleanClause . Occur . SHOULD ) ; if ( q != null ) bb . add ( q , BooleanClause . Occur . SHOULD ) ; if ( additionalFields != null ) { for ( String field : additionalFields ) { q = qb . createPhraseQuery ( field , s ) ; if ( q != null ) bb . add ( q , BooleanClause . Occur . SHOULD ) ; q = qb . createBooleanQuery ( field , s , BooleanClause . Occur . SHOULD ) ; if ( q != null ) bb . add ( q , BooleanClause . Occur . SHOULD ) ; } } } catch ( Exception e ) { throw new IllegalStateException ( "while running query " + q + " for text '" + s + "'" , e ) ; } } if ( otherPosFields != null ) { for ( String field : otherPosFields . stringPropertyNames ( ) ) { org . apache . lucene . search . Query q = qb . createPhraseQuery ( field , otherPosFields . getProperty ( field ) ) ; if ( q != null ) bb . add ( q , BooleanClause . Occur . MUST ) ; } } if ( otherNegFields != null ) { for ( String field : otherNegFields . stringPropertyNames ( ) ) { org . apache . lucene . search . Query q = qb . createPhraseQuery ( field , otherNegFields . getProperty ( field ) ) ; if ( q != null ) bb . add ( q , BooleanClause . Occur . MUST_NOT ) ; } } BooleanQuery q = bb . build ( ) ; TopDocs hits = searcher . search ( q , TOPK * 100 ) ; if ( hits . totalHits != 0 ) { System . err . println ( hits . totalHits + " results" ) ; for ( ScoreDoc sd : hits . scoreDocs ) { Document doc = searcher . doc ( sd . doc ) ; String id = doc . get ( "id" ) ; String content = doc . get ( "content" ) ; if ( ! pool . contains ( content ) ) results . add ( new SearchResult ( sd . score , id , content ) ) ; pool . add ( content ) ; if ( results . size ( ) == TOPK ) break ; } } else { System . err . println ( "No results" ) ; } return results ; }
Searches for the given string in the "content" field
Searches for the given string in the " content " field
// Build a Query object //System.err.println(s); //		org.apache.lucene.search.Query query = qb.createPhraseQuery("content", queryString); //		org.apache.lucene.search.Query query = qb.createBooleanQuery("text", queryString); //System.err.println(q.toString()); // Search for the query // add stored document contents //			System.err.println(text); //System.err.println(sd.score+"\t"+sd.doc+"\t"+doc.get("content")); //System.err.println(sd.score+"\t"+sd.doc+"\t"+doc.get("id")); //results.addAll(pool);