Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
PrefixQuery.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 using IndexReader = Lucene.Net.Index.IndexReader;
21 using Term = Lucene.Net.Index.Term;
22 using ToStringUtils = Lucene.Net.Util.ToStringUtils;
23 
24 namespace Lucene.Net.Search
25 {
26 
34  [Serializable]
36  {
37  private Term prefix;
38 
40  public PrefixQuery(Term prefix)
41  { //will be removed in 3.0
42  this.prefix = prefix;
43  }
44 
46  public virtual Term Prefix
47  {
48  get { return prefix; }
49  }
50 
51  protected internal override FilteredTermEnum GetEnum(IndexReader reader)
52  {
53  return new PrefixTermEnum(reader, prefix);
54  }
55 
57  public override System.String ToString(System.String field)
58  {
59  System.Text.StringBuilder buffer = new System.Text.StringBuilder();
60  if (!prefix.Field.Equals(field))
61  {
62  buffer.Append(prefix.Field);
63  buffer.Append(":");
64  }
65  buffer.Append(prefix.Text);
66  buffer.Append('*');
67  buffer.Append(ToStringUtils.Boost(Boost));
68  return buffer.ToString();
69  }
70 
71  //@Override
72  public override int GetHashCode()
73  {
74  int prime = 31;
75  int result = base.GetHashCode();
76  result = prime * result + ((prefix == null)?0:prefix.GetHashCode());
77  return result;
78  }
79 
80  //@Override
81  public override bool Equals(System.Object obj)
82  {
83  if (this == obj)
84  return true;
85  if (!base.Equals(obj))
86  return false;
87  if (GetType() != obj.GetType())
88  return false;
89  PrefixQuery other = (PrefixQuery) obj;
90  if (prefix == null)
91  {
92  if (other.prefix != null)
93  return false;
94  }
95  else if (!prefix.Equals(other.prefix))
96  return false;
97  return true;
98  }
99  }
100 }