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
FastVectorHighlighter.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 using System.Collections.Generic;
20 using System.Text;
21 
22 using Lucene.Net.Index;
23 
24 namespace Lucene.Net.Search.Vectorhighlight
25 {
26  public class FastVectorHighlighter
27  {
28 
29  public static bool DEFAULT_PHRASE_HIGHLIGHT = true;
30  public static bool DEFAULT_FIELD_MATCH = true;
31  private bool phraseHighlight;
32  private bool fieldMatch;
33  private FragListBuilder fragListBuilder;
34  private FragmentsBuilder fragmentsBuilder;
35  private int phraseLimit = Int32.MaxValue;
36 
40  public FastVectorHighlighter():this(DEFAULT_PHRASE_HIGHLIGHT, DEFAULT_FIELD_MATCH)
41  {
42  }
43 
49  public FastVectorHighlighter(bool phraseHighlight, bool fieldMatch):this(phraseHighlight, fieldMatch, new SimpleFragListBuilder(), new ScoreOrderFragmentsBuilder())
50  {
51  }
52 
60  public FastVectorHighlighter(bool phraseHighlight, bool fieldMatch,
61  FragListBuilder fragListBuilder, FragmentsBuilder fragmentsBuilder)
62  {
63  this.phraseHighlight = phraseHighlight;
64  this.fieldMatch = fieldMatch;
65  this.fragListBuilder = fragListBuilder;
66  this.fragmentsBuilder = fragmentsBuilder;
67  }
68 
74  public FieldQuery GetFieldQuery(Query query)
75  {
76  return new FieldQuery(query, phraseHighlight, fieldMatch);
77  }
78 
79 
89  public String GetBestFragment(FieldQuery fieldQuery, IndexReader reader, int docId,
90  String fieldName, int fragCharSize)
91  {
92  FieldFragList fieldFragList = GetFieldFragList(fieldQuery, reader, docId, fieldName, fragCharSize);
93  return fragmentsBuilder.CreateFragment(reader, docId, fieldName, fieldFragList);
94  }
95 
106  public String[] GetBestFragments(FieldQuery fieldQuery, IndexReader reader, int docId,
107  String fieldName, int fragCharSize, int maxNumFragments)
108  {
109  FieldFragList fieldFragList = GetFieldFragList(fieldQuery, reader, docId, fieldName, fragCharSize);
110  return fragmentsBuilder.CreateFragments(reader, docId, fieldName, fieldFragList, maxNumFragments);
111  }
112 
113  private FieldFragList GetFieldFragList(FieldQuery fieldQuery, IndexReader reader, int docId,
114  String fieldName, int fragCharSize)
115  {
116  FieldTermStack fieldTermStack = new FieldTermStack(reader, docId, fieldName, fieldQuery);
117  FieldPhraseList fieldPhraseList = new FieldPhraseList(fieldTermStack, fieldQuery, phraseLimit);
118  return fragListBuilder.CreateFieldFragList(fieldPhraseList, fragCharSize);
119  }
120 
125  public bool IsPhraseHighlight()
126  {
127  return phraseHighlight;
128  }
129 
134  public bool IsFieldMatch()
135  {
136  return fieldMatch;
137  }
138 
143 
144  public int PhraseLimit
145  {
146  get{ return phraseLimit; }
147  set{ this.phraseLimit = value; }
148  }
149  }
150 }