List of usage examples for org.apache.lucene.document TextField TYPE_STORED
FieldType TYPE_STORED
To view the source code for org.apache.lucene.document TextField TYPE_STORED.
Click Source Link
From source file:alix.lucene.Alix.java
License:Open Source License
/** * Parse field type String//from w w w . j av a2 s . co m * * @param name Name of the field * @param value Value of the field * @param options a string composed of letters in any order following Luke convention to describe fields * IdfpoPSV * I: Indexed * d: docs * f: freqs * p: pos * o: offset * P: payloads * S: Stored * V: TermVector */ public static FieldType fieldType(String options) { FieldType type; if (options == null) return new FieldType(); if ("S".equals(options)) { type = new FieldType(); type.setStored(true); return type; } if (options.contains("S")) { type = new FieldType(TextField.TYPE_STORED); } else { type = new FieldType(TextField.TYPE_NOT_STORED); } // optimize ? type.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); if (options.contains("p")) { type.setStoreTermVectorPositions(true); } if (options.contains("o")) { type.setTokenized(true); type.setStoreTermVectors(true); type.setStoreTermVectorOffsets(true); } if (options.contains("P")) { type.setTokenized(true); type.setStoreTermVectors(true); type.setStoreTermVectorPositions(true); type.setStoreTermVectorPayloads(true); } if (options.contains("V")) { type.setTokenized(true); type.setStoreTermVectors(true); } return type; }
From source file:at.ac.univie.mminf.luceneSKOS.analysis.engine.jena.SKOSEngineImpl.java
License:Apache License
private void indexObject(Resource skos_concept, Document conceptDoc, ObjectProperty property, String field) { StmtIterator stmt_iter = skos_concept.listProperties(property); while (stmt_iter.hasNext()) { RDFNode concept = stmt_iter.nextStatement().getObject(); if (!concept.canAs(Resource.class)) { logger.warn("Error when indexing relationship of concept " + skos_concept.getURI() + " ."); continue; }//w ww . j a v a 2 s .c om Resource resource = concept.as(Resource.class); Field conceptField = new Field(field, resource.getURI(), TextField.TYPE_STORED); conceptDoc.add(conceptField); } }
From source file:at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParserTest.java
License:Apache License
@Test public void queryParserSearch() throws IOException, QueryNodeException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);/*from w ww. ja v a 2 s. co m*/ searcher = new IndexSearcher(DirectoryReader.open(writer, false)); Query query = new SKOSStandardQueryParser(skosAnalyzer).parse("\"fox jumps\"", "content"); Assert.assertEquals(1, TestUtil.hitCount(searcher, query)); Assert.assertEquals("content:\"fox (jumps hops leaps)\"", query.toString()); Assert.assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName()); query = new StandardQueryParser(new StandardAnalyzer(matchVersion)).parse("\"fox jumps\"", "content"); Assert.assertEquals(1, TestUtil.hitCount(searcher, query)); Assert.assertEquals("content:\"fox jumps\"", query.toString()); Assert.assertEquals("org.apache.lucene.search.PhraseQuery", query.getClass().getName()); }
From source file:at.ac.univie.mminf.luceneSKOS.queryparser.flexible.standard.SKOSStandardQueryParserTest.java
License:Apache License
@Test public void queryParserSearchWithBoosts() throws IOException, QueryNodeException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);/*from w w w . ja v a 2 s.c o m*/ searcher = new IndexSearcher(DirectoryReader.open(writer, false)); SKOSStandardQueryParser parser = new SKOSStandardQueryParser(skosAnalyzer); parser.setBoost(SKOSType.ALT, 0.5f); Query query = parser.parse("\"fox jumps\"", "content"); Assert.assertEquals(1, TestUtil.hitCount(searcher, query)); // boosts do not work in phrase queries Assert.assertEquals("content:\"fox (jumps hops leaps)\"", query.toString()); Assert.assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName()); query = parser.parse("fox jumps", "content"); Assert.assertEquals(1, TestUtil.hitCount(searcher, query)); Assert.assertEquals("content:fox (content:jumps content:hops^0.5 content:leaps^0.5)", query.toString()); Assert.assertEquals("org.apache.lucene.search.BooleanQuery", query.getClass().getName()); query = new SKOSStandardQueryParser(new StandardAnalyzer(matchVersion)).parse("fox jumps", "content"); Assert.assertEquals(1, TestUtil.hitCount(searcher, query)); Assert.assertEquals("content:fox content:jumps", query.toString()); Assert.assertEquals("org.apache.lucene.search.BooleanQuery", query.getClass().getName()); }
From source file:at.ac.univie.mminf.luceneSKOS.test.SKOSLabelFilterTest.java
License:Apache License
@Test public void termQuerySearch() throws IOException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);/*from w ww . ja va 2 s . c o m*/ searcher = new IndexSearcher(DirectoryReader.open(writer, false)); TermQuery tq = new TermQuery(new Term("content", "hops")); assertEquals(1, searcher.search(tq, 1).totalHits); }
From source file:at.ac.univie.mminf.luceneSKOS.test.SKOSLabelFilterTest.java
License:Apache License
@Test public void phraseQuerySearch() throws IOException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);/* ww w. j av a 2 s .co m*/ searcher = new IndexSearcher(DirectoryReader.open(writer, false)); PhraseQuery.Builder builder = new PhraseQuery.Builder(); builder.add(new Term("content", "fox")).add(new Term("content", "hops")); assertEquals(1, searcher.search(builder.build(), 1).totalHits); }
From source file:at.ac.univie.mminf.luceneSKOS.test.SKOSLabelFilterTest.java
License:Apache License
@Test public void queryParserSearch() throws IOException, QueryNodeException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);//from w ww . jav a 2 s .c o m searcher = new IndexSearcher(DirectoryReader.open(writer, false)); Query query = new StandardQueryParser(skosAnalyzer).parse("\"fox jumps\"", "content"); assertEquals(1, searcher.search(query, 1).totalHits); assertEquals("content:\"fox (jumps hops leaps)\"", query.toString()); assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName()); query = new StandardQueryParser(new StandardAnalyzer()).parse("\"fox jumps\"", "content"); assertEquals(1, searcher.search(query, 1).totalHits); assertEquals("content:\"fox jumps\"", query.toString()); assertEquals("org.apache.lucene.search.PhraseQuery", query.getClass().getName()); }
From source file:at.ac.univie.mminf.luceneSKOS.test.SKOSLabelFilterTest.java
License:Apache License
@Test public void testTermQuery() throws IOException, QueryNodeException { Document doc = new Document(); doc.add(new Field("content", "I work for the united nations", TextField.TYPE_STORED)); writer.addDocument(doc);/*from w ww.j a v a2 s . c o m*/ searcher = new IndexSearcher(DirectoryReader.open(writer, false)); StandardQueryParser parser = new StandardQueryParser(new SimpleAnalyzer()); Query query = parser.parse("united nations", "content"); assertEquals(1, searcher.search(query, 1).totalHits); }
From source file:at.ac.univie.mminf.luceneSKOS.test.SKOSStandardQueryParserTest.java
License:Apache License
@Test public void queryParserSearch() throws IOException, QueryNodeException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);/*from w w w . jav a2 s .c o m*/ searcher = new IndexSearcher(DirectoryReader.open(writer, false)); Query query = new SKOSStandardQueryParser(skosAnalyzer).parse("\"fox jumps\"", "content"); assertEquals(1, searcher.search(query, 1).totalHits); assertEquals("content:\"fox (jumps hops leaps)\"", query.toString()); assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName()); query = new StandardQueryParser(new StandardAnalyzer()).parse("\"fox jumps\"", "content"); assertEquals(1, searcher.search(query, 1).totalHits); assertEquals("content:\"fox jumps\"", query.toString()); assertEquals("org.apache.lucene.search.PhraseQuery", query.getClass().getName()); }
From source file:at.ac.univie.mminf.luceneSKOS.test.SKOSStandardQueryParserTest.java
License:Apache License
@Test public void queryParserSearchWithBoosts() throws IOException, QueryNodeException { Document doc = new Document(); doc.add(new Field("content", "The quick brown fox jumps over the lazy dog", TextField.TYPE_STORED)); writer.addDocument(doc);//w w w .j ava 2 s.c om searcher = new IndexSearcher(DirectoryReader.open(writer, false)); SKOSStandardQueryParser parser = new SKOSStandardQueryParser(skosAnalyzer); parser.setBoost(SKOSType.ALT, 0.5f); Query query = parser.parse("\"fox jumps\"", "content"); assertEquals(1, searcher.search(query, 1).totalHits); // boosts do not work in phrase queries assertEquals("content:\"fox (jumps hops leaps)\"", query.toString()); assertEquals("org.apache.lucene.search.MultiPhraseQuery", query.getClass().getName()); query = parser.parse("fox jumps", "content"); assertEquals(1, searcher.search(query, 1).totalHits); assertEquals("content:fox (content:jumps content:hops^0.5 content:leaps^0.5)", query.toString()); assertEquals("org.apache.lucene.search.BooleanQuery", query.getClass().getName()); query = new SKOSStandardQueryParser(new StandardAnalyzer()).parse("fox jumps", "content"); assertEquals(1, searcher.search(query, 1).totalHits); assertEquals("content:fox content:jumps", query.toString()); assertEquals("org.apache.lucene.search.BooleanQuery", query.getClass().getName()); }