本文整理汇总了Java中org.apache.lucene.index.TermPositionVector类的典型用法代码示例。如果您正苦于以下问题:Java TermPositionVector类的具体用法?Java TermPositionVector怎么用?Java TermPositionVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TermPositionVector类属于org.apache.lucene.index包,在下文中一共展示了TermPositionVector类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: populate
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
private static final void populate(final TermPositionVector termVector,
final String[] terms, final Collection<SnippetVector> vectors,
Timer parentTimer) throws SearchLibException {
Timer t = new Timer(parentTimer, "indexesOf");
int[] termsIdx = termVector.indexesOf(terms, 0, terms.length);
t.end(null);
int i = 0;
for (int termId : termsIdx) {
Timer termTimer = new Timer(parentTimer, "term " + terms[i]);
if (termId != -1) {
t = new Timer(termTimer, "getOffsets");
TermVectorOffsetInfo[] offsets = termVector.getOffsets(termId);
t.end(null);
t = new Timer(termTimer, "getTermPositions");
int[] positions = termVector.getTermPositions(termId);
t.end(null);
t = new Timer(termTimer, "SnippetVector");
int j = 0;
for (TermVectorOffsetInfo offset : offsets)
vectors.add(new SnippetVector(i, offset, positions[j++]));
t.end(null);
}
termTimer.end(null);
i++;
}
}
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:27,代码来源:SnippetVectors.java
示例2: extractTermVectorIterator
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
final static Iterator<SnippetVector> extractTermVectorIterator(
final int docId, final ReaderInterface reader,
final SnippetQueries snippetQueries, final String fieldName,
List<FieldValueItem> values, CompiledAnalyzer analyzer,
final Timer parentTimer, final long expiration) throws IOException,
ParseException, SyntaxError, SearchLibException {
if (ArrayUtils.isEmpty(snippetQueries.terms))
return null;
Timer t = new Timer(parentTimer, "getTermPositionVector " + fieldName);
TermPositionVector termVector = getTermPositionVector(
snippetQueries.terms, reader, docId, fieldName, values,
analyzer, t);
t.end(null);
if (termVector == null)
return null;
Collection<SnippetVector> vectors = new ArrayList<SnippetVector>();
t = new Timer(parentTimer, "populate");
populate(termVector, snippetQueries.terms, vectors, t);
t.end(null);
t = new Timer(parentTimer, "removeIncludes");
vectors = removeIncludes(vectors);
t.end(null);
t = new Timer(parentTimer, "checkQueries");
snippetQueries.checkQueries(vectors, t, expiration);
t.end(null);
t = new Timer(parentTimer, "removeNonQuery");
vectors = removeNonQuery(vectors);
t.end(null);
return vectors.iterator();
}
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:39,代码来源:SnippetVectors.java
示例3: getTermPositionVector
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
private static final TermPositionVector getTermPositionVector(
final String[] terms, final ReaderInterface readerInterface,
final int docId, final String field, List<FieldValueItem> values,
CompiledAnalyzer analyzer, Timer timer) throws IOException,
SearchLibException, ParseException, SyntaxError {
TermFreqVector termFreqVector = readerInterface.getTermFreqVector(
docId, field);
if (termFreqVector != null)
if (termFreqVector instanceof TermPositionVector)
return (TermPositionVector) termFreqVector;
if (analyzer == null)
return null;
SnippetTermPositionVector stpv = new SnippetTermPositionVector(field,
terms);
int positionOffset = 0;
int characterOffset = 0;
List<TokenTerm> tokenTerms = new ArrayList<TokenTerm>();
for (FieldValueItem fieldValueItem : values) {
if (fieldValueItem.value == null)
continue;
analyzer.populate(fieldValueItem.value, tokenTerms);
positionOffset = stpv.addCollection(tokenTerms, characterOffset,
positionOffset);
characterOffset += fieldValueItem.value.length() + 1;
tokenTerms.clear();
}
stpv.compile();
return stpv;
}
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:30,代码来源:SnippetVectors.java
示例4: toList
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
public final static List<IndexTerm> toList(TermFreqVector termVector) {
if (termVector == null)
return null;
String[] terms = termVector.getTerms();
if (terms == null)
return null;
int[] frequencies = termVector.getTermFrequencies();
List<IndexTerm> indexTerms = new ArrayList<IndexTerm>(terms.length);
if (termVector instanceof TermPositionVector)
toListPosition((TermPositionVector) termVector, terms, frequencies, indexTerms);
else
toListFreq(termVector, terms, frequencies, indexTerms);
return indexTerms;
}
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:15,代码来源:IndexDocumentResult.java
示例5: toListPosition
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
private final static void toListPosition(TermPositionVector termVector, String[] terms, int[] frequencies,
List<IndexTerm> indexTerms) {
int i = 0;
for (String term : terms) {
IndexTerm indexTerm =
new IndexTerm(term, frequencies[i], termVector.getTermPositions(i), termVector.getOffsets(i));
indexTerms.add(indexTerm);
i++;
}
}
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:11,代码来源:IndexDocumentResult.java
示例6: main
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length != 0) {
QUERY = args[0];
}
// 将庖丁封装成符合Lucene要求的Analyzer规范
Analyzer analyzer = new PaodingAnalyzer();
//读取本类目录下的text.txt文件
String content = ContentReader.readText(English.class);
//接下来是标准的Lucene建立索引和检索的代码
Directory ramDir = new RAMDirectory();
IndexWriter writer = new IndexWriter(ramDir, analyzer);
Document doc = new Document();
Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(fd);
writer.addDocument(doc);
writer.optimize();
writer.close();
IndexReader reader = IndexReader.open(ramDir);
String queryString = QUERY;
QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
Query query = parser.parse(queryString);
Searcher searcher = new IndexSearcher(ramDir);
query = query.rewrite(reader);
System.out.println("Searching for: " + query.toString(FIELD_NAME));
Hits hits = searcher.search(query);
BoldFormatter formatter = new BoldFormatter();
Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
query));
highlighter.setTextFragmenter(new SimpleFragmenter(50));
for (int i = 0; i < hits.length(); i++) {
String text = hits.doc(i).get(FIELD_NAME);
int maxNumFragmentsRequired = 5;
String fragmentSeparator = "...";
TermPositionVector tpv = (TermPositionVector) reader
.getTermFreqVector(hits.id(i), FIELD_NAME);
TokenStream tokenStream = TokenSources.getTokenStream(tpv);
String result = highlighter.getBestFragments(tokenStream, text,
maxNumFragmentsRequired, fragmentSeparator);
System.out.println("\n" + result);
}
reader.close();
}
开发者ID:no8899,项目名称:paoding-for-lucene-2.4,代码行数:48,代码来源:English.java
示例7: main
import org.apache.lucene.index.TermPositionVector; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length != 0) {
QUERY = args[0];
}
// 将庖丁封装成符合Lucene要求的Analyzer规范
Analyzer analyzer = new PaodingAnalyzer();
//读取本类目录下的text.txt文件
String content = ContentReader.readText(Chinese.class);
//接下来是标准的Lucene建立索引和检索的代码
Directory ramDir = new RAMDirectory();
IndexWriter writer = new IndexWriter(ramDir, analyzer);
Document doc = new Document();
Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(fd);
writer.addDocument(doc);
writer.optimize();
writer.close();
IndexReader reader = IndexReader.open(ramDir);
String queryString = QUERY;
QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
Query query = parser.parse(queryString);
Searcher searcher = new IndexSearcher(ramDir);
query = query.rewrite(reader);
System.out.println("Searching for: " + query.toString(FIELD_NAME));
Hits hits = searcher.search(query);
BoldFormatter formatter = new BoldFormatter();
Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
query));
highlighter.setTextFragmenter(new SimpleFragmenter(50));
for (int i = 0; i < hits.length(); i++) {
String text = hits.doc(i).get(FIELD_NAME);
int maxNumFragmentsRequired = 5;
String fragmentSeparator = "...";
TermPositionVector tpv = (TermPositionVector) reader
.getTermFreqVector(hits.id(i), FIELD_NAME);
TokenStream tokenStream = TokenSources.getTokenStream(tpv);
String result = highlighter.getBestFragments(tokenStream, text,
maxNumFragmentsRequired, fragmentSeparator);
System.out.println("\n" + result);
}
reader.close();
}
开发者ID:no8899,项目名称:paoding-for-lucene-2.4,代码行数:48,代码来源:Chinese.java
注:本文中的org.apache.lucene.index.TermPositionVector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论