本文整理汇总了Java中org.apache.lucene.document.FieldType.setStored方法的典型用法代码示例。如果您正苦于以下问题:Java FieldType.setStored方法的具体用法?Java FieldType.setStored怎么用?Java FieldType.setStored使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.document.FieldType
的用法示例。
在下文中一共展示了FieldType.setStored方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWith
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
/**
* Creates Lucene Document using two strings: body and title
*
* @return resulted document
*/
public static Document createWith(final String titleStr, final String bodyStr) {
final Document document = new Document();
final FieldType textIndexedType = new FieldType();
textIndexedType.setStored(true);
textIndexedType.setIndexOptions(IndexOptions.DOCS);
textIndexedType.setTokenized(true);
//index title
Field title = new Field("title", titleStr, textIndexedType);
//index body
Field body = new Field("body", bodyStr, textIndexedType);
document.add(title);
document.add(body);
return document;
}
示例2: LuceneUtil
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public LuceneUtil(JasperReportsContext jasperReportsContext, boolean isCaseSensitive, boolean isWholeWordsOnly, boolean removeAccents) {
this.isCaseSensitive = isCaseSensitive;
this.isWholeWordsOnly = isWholeWordsOnly;
this.removeAccents = removeAccents;
this.noneSelector = JRStyledTextAttributeSelector.getNoneSelector(jasperReportsContext);
this.styledTextUtil = JRStyledTextUtil.getInstance(jasperReportsContext);
fieldType = new FieldType();
fieldType.setIndexed(true);
fieldType.setTokenized(true);
fieldType.setStored(true);
fieldType.setStoreTermVectors(true);
fieldType.setStoreTermVectorPositions(true);
fieldType.setStoreTermVectorOffsets(true);
fieldType.freeze();
}
示例3: isAHit
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private boolean isAHit(Query q, String content, Analyzer analyzer) throws IOException{
Directory ramDir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), ramDir, analyzer);
Document doc = new Document();
FieldType fieldType = new FieldType();
fieldType.setIndexed(true);
fieldType.setTokenized(true);
fieldType.setStored(true);
Field field = new Field(FIELD, content, fieldType);
doc.add(field);
writer.addDocument(doc);
writer.close();
DirectoryReader ir = DirectoryReader.open(ramDir);
IndexSearcher is = new IndexSearcher(ir);
int hits = is.search(q, 10).totalHits;
ir.close();
ramDir.close();
if (hits == 1){
return true;
} else {
return false;
}
}
示例4: index
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void index(Item item) throws IOException {
String id = item.getId();
String text = item.getText();
long publicationTIme = item.getPublicationTime();
Document document = new Document();
Field idField = new StringField("id", id, Store.YES);
document.add(idField);
FieldType fieldType = new FieldType();
fieldType.setStored(true);
fieldType.setIndexed(true);
fieldType.setStoreTermVectors(true);
document.add(new Field("text", text, fieldType));
document.add(new LongField("publicationTIme", publicationTIme, LongField.TYPE_STORED));
if(iwriter != null) {
iwriter.addDocument(document);
}
}
示例5: createFields
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
@Override
public List<IndexableField> createFields(SchemaField field, Object value, float boost) {
String externalVal = value.toString();
String[] point = parseCommaSeparatedList(externalVal, dimension);
// TODO: this doesn't currently support polyFields as sub-field types
List<IndexableField> f = new ArrayList<>(dimension+1);
if (field.indexed()) {
for (int i=0; i<dimension; i++) {
SchemaField sf = subField(field, i, schema);
f.add(sf.createField(point[i], sf.indexed() && !sf.omitNorms() ? boost : 1f));
}
}
if (field.stored()) {
String storedVal = externalVal; // normalize or not?
FieldType customType = new FieldType();
customType.setStored(true);
f.add(createField(field.getName(), storedVal, customType, 1f));
}
return f;
}
示例6: filter
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
@Override
public boolean filter(FullConcept concept) {
//index
Document doc = new Document();
/** The customized field type for contents field */
FieldType contentFieldType = new FieldType();
contentFieldType.setIndexed(true);
contentFieldType.setStored(true);
contentFieldType.setStoreTermVectors(true);
contentFieldType.setTokenized(true);
doc.add(new Field("contents", concept.getTitle() + "\n" + concept.getPlainContent(), contentFieldType));
doc.add(new StringField("id", Integer.toString(concept.getId()), Field.Store.YES));
doc.add(new StringField("outId", concept.getOutId(), Field.Store.YES));
doc.add(new Field("title", concept.getTitle(), contentFieldType));
try {
writer.addDocument(doc);
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
示例7: createDocument
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public static Document createDocument(int n, int numFields) {
StringBuilder sb = new StringBuilder();
Document doc = new Document();
sb.append("a");
sb.append(n);
FieldType customType2 = new FieldType(TextField.TYPE_STORED);
customType2.setTokenized(false);
customType2.setOmitNorms(true);
FieldType customType3 = new FieldType();
customType3.setStored(true);
doc.add(new TextField("field1", sb.toString(), Field.Store.YES));
doc.add(new Field("fielda", sb.toString(), customType2));
doc.add(new Field("fieldb", sb.toString(), customType3));
sb.append(" b");
sb.append(n);
for (int i = 1; i < numFields; i++) {
doc.add(new TextField("field" + (i+1), sb.toString(), Field.Store.YES));
}
return doc;
}
示例8: getDoc
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
@Override
public List<Document> getDoc(List<IfcProductRecordText> items) {
List<Document> docs = new ArrayList<Document>();
FieldType storedType = new FieldType();
storedType.setIndexed(true);
storedType.setStored(true);
storedType.setTokenized(true);
FieldType unTokeType = new FieldType();
unTokeType.setIndexed(true);
unTokeType.setStored(true);
unTokeType.setTokenized(false);
for (IfcProductRecordText record : items) {
Document doc = new Document();
Field oid = genStringFieldCheckNull(Key_Oid, record.getOid(), unTokeType);
Field type = genStringFieldCheckNull(Key_Type, record.getType(), storedType);
Field name = genStringFieldCheckNull(Key_Name, record.getName(), storedType);
Field detail = genStringFieldCheckNull(Key_Detail, record.getDetail(), storedType);
doc.add(oid);
doc.add(type);
doc.add(name);
doc.add(detail);
docs.add(doc);
}
return docs;
}
示例9: index
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
public void index() throws CorruptIndexException,
LockObtainFailedException, IOException {
Directory dir = FSDirectory.open(indexDirectory);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41,StandardAnalyzer.STOP_WORDS_SET);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_41, analyzer);
if (indexDirectory.exists()) {
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
} else {
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
}
IndexWriter writer = new IndexWriter(dir, iwc);
for (File f : sourceDirectory.listFiles()) {
System.out.println("Indexing Document "+f.getName());
Document doc = new Document();
FieldType fieldType = new FieldType();
fieldType.setIndexed(true);
fieldType.setIndexOptions(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
fieldType.setStored(true);
fieldType.setStoreTermVectors(true);
fieldType.setTokenized(true);
Field contentField = new Field(fieldName, ExtractText(f), fieldType);
doc.add(contentField);
doc.add(new TextField("FileName", f.getName(), Field.Store.YES));
doc.add(new TextField("FilePath",f.getCanonicalPath(),Field.Store.YES));
writer.addDocument(doc);
}
writer.close();
}
示例10: newField
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private Field newField(String name, String value, Store stored) {
FieldType tagsFieldType = new FieldType();
tagsFieldType.setStored(stored == Store.YES);
IndexOptions idxOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
tagsFieldType.setIndexOptions(idxOptions);
return new Field(name, value, tagsFieldType);
}
示例11: getDocumentWithTermVectors
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
static Document getDocumentWithTermVectors(String fn, String content) throws IOException {
Document doc = new Document();
doc.add(new StringField(FILE_NAME, fn, Field.Store.YES));
doc.add(new StoredField(DOC_SIZE_FIELD_NAME, Commons.getDocumentSize(content)));
FieldType ft = new FieldType();
ft.setStored(true);
ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
ft.setStoreTermVectors(true);
doc.add(new Field(Commons.getFieldName(FIELD_NAME, 1), content, ft));
doc.add(new Field(Commons.getFieldName(FIELD_NAME, 2), content, ft));
doc.add(new Field(Commons.getFieldName(FIELD_NAME, 3), content, ft));
return doc;
}
示例12: getNotTokenizedFieldType
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
/**
* Ritorna un tipo field, stored, not tokenized e indexed
*
* @return field type utilizzabili per chiavi o elementi che non si vogliono
* tokenizzare
*/
public static FieldType getNotTokenizedFieldType() {
FieldType keywordFieldType = new FieldType();
keywordFieldType.setStored(true);
keywordFieldType.setTokenized(false);
keywordFieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
return keywordFieldType;
}
示例13: createFieldType
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
private static FieldType createFieldType(boolean tokenized) {
FieldType answer = new FieldType();
//answer.setIndexed(true);
answer.setStored(true);
answer.setTokenized(tokenized);
// freeze the answer so that it becomes immutable
answer.freeze();
return answer;
}
示例14: testLUCENE_1590
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
/**
* Test adding two fields with the same name, one indexed
* the other stored only. The omitNorms and omitTermFreqAndPositions setting
* of the stored field should not affect the indexed one (LUCENE-1590)
*/
public void testLUCENE_1590() throws Exception {
Document doc = new Document();
// f1 has no norms
FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
customType.setOmitNorms(true);
FieldType customType2 = new FieldType();
customType2.setStored(true);
doc.add(newField("f1", "v1", customType));
doc.add(newField("f1", "v2", customType2));
// f2 has no TF
FieldType customType3 = new FieldType(TextField.TYPE_NOT_STORED);
customType3.setIndexOptions(IndexOptions.DOCS_ONLY);
Field f = newField("f2", "v1", customType3);
doc.add(f);
doc.add(newField("f2", "v2", customType2));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
writer.addDocument(doc);
writer.forceMerge(1); // be sure to have a single segment
writer.close();
TestUtil.checkIndex(dir);
SegmentReader reader = getOnlySegmentReader(DirectoryReader.open(dir));
FieldInfos fi = reader.getFieldInfos();
// f1
assertFalse("f1 should have no norms", fi.fieldInfo("f1").hasNorms());
assertEquals("omitTermFreqAndPositions field bit should not be set for f1", IndexOptions.DOCS_AND_FREQS_AND_POSITIONS, fi.fieldInfo("f1").getIndexOptions());
// f2
assertTrue("f2 should have norms", fi.fieldInfo("f2").hasNorms());
assertEquals("omitTermFreqAndPositions field bit should be set for f2", IndexOptions.DOCS_ONLY, fi.fieldInfo("f2").getIndexOptions());
reader.close();
}
示例15: setFieldType
import org.apache.lucene.document.FieldType; //导入方法依赖的package包/类
/** Used to customize the indexing options of the 4 number fields, and to a lesser degree the XDL field too. Search
* requires indexed=true, and relevancy requires docValues. If these features aren't needed then disable them.
* {@link FieldType#freeze()} is called on the argument. */
public void setFieldType(FieldType fieldType) {
fieldType.freeze();
this.fieldType = fieldType;
//only double's supported right now
if (fieldType.numericType() != FieldType.NumericType.DOUBLE)
throw new IllegalArgumentException("BBoxStrategy only supports doubles at this time.");
//for xdlFieldType, copy some similar options. Don't do docValues since it isn't needed here.
xdlFieldType = new FieldType(StringField.TYPE_NOT_STORED);
xdlFieldType.setStored(fieldType.stored());
xdlFieldType.setIndexed(fieldType.indexed());
xdlFieldType.freeze();
}