public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader) { BooleanQuery query = new BooleanQuery(); TermEnum enumerator = reader.Terms(prefix); try { System.String prefixText = prefix.Text(); System.String prefixField = prefix.Field(); do { Term term = enumerator.Term(); if (term != null && term.Text().StartsWith(prefixText) && (System.Object) term.Field() == (System.Object) prefixField) { TermQuery tq = new TermQuery(term); // found a match tq.SetBoost(GetBoost()); // set the boost query.Add(tq, false, false); // add to query //System.out.println("added " + term); } else { break; } } while (enumerator.Next()); } finally { enumerator.Close(); } return query; }
// // Search the index with term // public Result Search (string term) { try { Query q1 = QueryParser.Parse (term, "hottext", new StandardAnalyzer ()); Query q2 = QueryParser.Parse (term, "text", new StandardAnalyzer ()); q2.SetBoost (0.7f); Query q3 = QueryParser.Parse (term, "examples", new StandardAnalyzer ()); q3.SetBoost (0.5f); BooleanQuery q = new BooleanQuery(); q.Add (q1, false, false); q.Add (q2, false, false); q.Add (q3, false, false); Hits hits = searcher.Search(q); Result r = new Result (term, hits); Results.Add (r); return r; } catch (IOException) { Console.WriteLine ("No index in {0}", dir); return null; } }
public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader) { FilteredTermEnum enumerator = GetEnum(reader); BooleanQuery query = new BooleanQuery(); try { do { Term t = enumerator.Term(); if (t != null) { TermQuery tq = new TermQuery(t); // found a match tq.SetBoost(GetBoost() * enumerator.Difference()); // set the boost query.Add(tq, false, false); // add to query } } while (enumerator.Next()); } finally { enumerator.Close(); } return query; }
protected internal override Weight CreateWeight(Searcher searcher) { if (termArrays.Count == 1) { // optimize one-term case Term[] terms = (Term[]) termArrays[0]; BooleanQuery boq = new BooleanQuery(); for (int i = 0; i < terms.Length; i++) { boq.Add(new TermQuery(terms[i]), false, false); } boq.SetBoost(GetBoost()); return boq.CreateWeight(searcher); } return new PhrasePrefixWeight(this, searcher); }
/// <summary>Expert: merges the clauses of a set of BooleanQuery's into a single /// BooleanQuery. /// /// <p>A utility for use by {@link #Combine(Query[])} implementations. /// </summary> public static Query MergeBooleanQueries(Query[] queries) { System.Collections.Hashtable allClauses = new System.Collections.Hashtable(); for (int i = 0; i < queries.Length; i++) { BooleanClause[] clauses = ((BooleanQuery) queries[i]).GetClauses(); for (int j = 0; j < clauses.Length; j++) { allClauses.Add(clauses[j], clauses[j]); } } BooleanQuery result = new BooleanQuery(); foreach (BooleanClause booleanClause in allClauses.Keys) { result.Add(booleanClause); } return result; }
/// <summary> Factory method for generating query, given a set of clauses. /// By default creates a boolean query composed of clauses passed in. /// /// Can be overridden by extending classes, to modify query being /// returned. /// /// </summary> /// <param name="clauses">Vector that contains {@link BooleanClause} instances /// to join. /// /// </param> /// <returns> Resulting {@link Query} object. /// </returns> /// <exception cref=""> ParseException throw in overridden method to disallow /// </exception> protected internal virtual Query GetBooleanQuery(System.Collections.ArrayList clauses) { BooleanQuery query = new BooleanQuery(); for (int i = 0; i < clauses.Count; i++) { query.Add((BooleanClause) clauses[i]); } return query; }
/// <summary> FIXME: Describe <code>rewrite</code> method here. /// /// </summary> /// <param name="reader">an <code>Monodoc.Lucene.Net.Index.IndexReader</code> value /// </param> /// <returns> a <code>Query</code> value /// </returns> /// <exception cref=""> IOException if an error occurs /// </exception> public override Query Rewrite(Monodoc.Lucene.Net.Index.IndexReader reader) { BooleanQuery query = new BooleanQuery(); TermEnum enumerator = reader.Terms(lowerTerm); try { bool checkLower = false; if (!inclusive) // make adjustments to set to exclusive checkLower = true; System.String testField = GetField(); do { Term term = enumerator.Term(); if (term != null && (System.Object) term.Field() == (System.Object) testField) { if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0) { checkLower = false; if (upperTerm != null) { int compare = String.CompareOrdinal(upperTerm.Text(), term.Text()); /* if beyond the upper term, or is exclusive and * this is equal to the upper term, break out */ if ((compare < 0) || (!inclusive && compare == 0)) break; } TermQuery tq = new TermQuery(term); // found a match tq.SetBoost(GetBoost()); // set the boost query.Add(tq, false, false); // add to query } } else { break; } } while (enumerator.Next()); } finally { enumerator.Close(); } return query; }