52 |
* <http://www.apache.org/>. |
* <http://www.apache.org/>. |
53 |
*/ |
*/ |
54 |
|
|
55 |
|
//Code by Pierrick Brihaye |
56 |
|
|
57 |
package org.apache.lucene.search; |
package org.apache.lucene.search; |
58 |
|
|
59 |
import org.apache.lucene.index.Term; |
import org.apache.lucene.index.Term; |
60 |
|
import org.apache.lucene.search.Query; |
61 |
|
import org.apache.lucene.search.TermQuery; |
62 |
|
|
63 |
public class UnanalyzedQuery extends TermQuery { |
public class UnanalyzedQuery extends Query { |
64 |
|
|
65 |
|
protected TermQuery tq = null; |
66 |
|
|
67 |
/** Constructs a query for the term <code>t</code>. */ |
/** Constructs a query for the term <code>t</code>. */ |
68 |
public UnanalyzedQuery(Term t) { |
public UnanalyzedQuery(Term t) { |
69 |
super(t); |
tq = new TermQuery(t); |
|
} |
|
|
|
|
|
public String toString() { |
|
|
return new String("|" + super.toString() + "|"); |
|
70 |
} |
} |
71 |
|
|
72 |
|
/** Returns the term of this query. */ |
73 |
|
public Term getTerm() { return tq.getTerm(); } |
74 |
|
|
75 |
|
protected Weight createWeight(Searcher searcher) { |
76 |
|
return tq.createWeight(searcher); |
77 |
|
} |
78 |
|
|
79 |
|
/** Prints a user-readable version of this query. */ |
80 |
|
public String toString(String field) { |
81 |
|
StringBuffer buffer = new StringBuffer(); |
82 |
|
if (tq.getTerm().field().equals(tq.getTerm().field())) { |
83 |
|
buffer.append(tq.getTerm().field()); |
84 |
|
buffer.append(":"); |
85 |
|
} |
86 |
|
buffer.append("|"); |
87 |
|
buffer.append(tq.getTerm().text()); |
88 |
|
buffer.append("|"); |
89 |
|
if (getBoost() != 1.0f) { |
90 |
|
buffer.append("^"); |
91 |
|
buffer.append(Float.toString(getBoost())); |
92 |
|
} |
93 |
|
return buffer.toString(); |
94 |
|
} |
95 |
|
|
96 |
/** Returns true iff <code>o</code> is equal to this. */ |
/** Returns true iff <code>o</code> is equal to this. */ |
97 |
public boolean equals(Object o) { |
public boolean equals(Object o) { |
98 |
if (!(o instanceof UnanalyzedQuery)) |
if (!(o instanceof UnanalyzedQuery)) |
99 |
return false; |
return false; |
100 |
UnanalyzedQuery other = (UnanalyzedQuery) o; |
UnanalyzedQuery other = (UnanalyzedQuery) o; |
101 |
return (this.getBoost() == other.getBoost()) |
return (tq.getBoost() == other.getBoost()) |
102 |
&& this.getTerm().equals(other.getTerm()); |
&& tq.getTerm().equals(other.getTerm()); |
103 |
} |
} |
104 |
|
|
105 |
|
/** Returns a hash code value for this object.*/ |
106 |
|
public int hashCode() { |
107 |
|
//Copied from TermQuery |
108 |
|
return Float.floatToIntBits(getBoost()) ^ tq.getTerm().hashCode(); |
109 |
|
} |
110 |
|
|
111 |
} |
} |