List of usage examples for org.apache.lucene.index IndexWriter getAnalyzer
public Analyzer getAnalyzer()
From source file:ddf.catalog.pubsub.criteria.contextual.ContextualEvaluator.java
License:Open Source License
/** * Build one Lucene index for the specified XML Document that contains both case-insensitive and * case-sensitive indexed text. Use the provided XPath selectors to extract the indexable text * from the specified XML document.//from www .j a v a 2s . c om * * @param fullDocument * the XML document to be indexed * @param xpathSelectors * the XPath selectors to use to extract the indexable text from the XML document * * @return the Lucene index for the indexed text from the XML document * * @throws IOException */ public static Directory buildIndex(String fullDocument, String[] xpathSelectors) throws IOException { String methodName = "buildIndex"; LOGGER.entry(methodName); // LOGGER.debug( XPathHelper.xmlToString( fullDocument ) ); // 0. Specify the analyzer for tokenizing text. // The same analyzer should be used for indexing and searching ContextualAnalyzer contextualAnalyzer = new ContextualAnalyzer(Version.LUCENE_30); // 1. create the index Directory index = new RAMDirectory(); // Retrieve the text from the document that can be indexed using the specified XPath // selectors String indexableText = getIndexableText(fullDocument, xpathSelectors); // Create an IndexWriter using the case-insensitive StandardAnalyzer // NOTE: the boolean arg in the IndexWriter constructor means to create a new index, // overwriting any existing index IndexWriter indexWriter = new IndexWriter(index, contextualAnalyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); logTokens(indexWriter.getAnalyzer(), FIELD_NAME, fullDocument, "ContextualAnalyzer"); // Add the indexable text to the case-insensitive index writer, assigning it the // "case-insensitive" field name addDoc(indexWriter, FIELD_NAME, indexableText); indexWriter.close(); CaseSensitiveContextualAnalyzer caseSensitiveStandardAnalyzer = new CaseSensitiveContextualAnalyzer( Version.LUCENE_30); // Create a second IndexWriter using the custom case-sensitive StandardAnalyzer // NOTE: set boolean to false to append the case-sensitive indexed text to the existing // index (populated by first IndexWriter) IndexWriter csIndexWriter = new IndexWriter(index, caseSensitiveStandardAnalyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); // Add the indexable text to the case-sensitive index writer, assigning it the // "case-sensitive" field name addDoc(csIndexWriter, CASE_SENSITIVE_FIELD_NAME, indexableText); csIndexWriter.close(); LOGGER.exit(methodName); return index; }
From source file:net.homeip.donaldm.doxmentor4j.indexers.SourceIndexer.java
License:Open Source License
@Override public void setIndexWriter(IndexWriter indexWriter) //------------------------------------------------------- { if (!USE_SOURCE_ANALYZER) { super.setIndexWriter(null); // Don't index source on first pass return;/*w ww. j a v a2 s.com*/ } if ((indexWriter == null) || (indexWriter.getAnalyzer() == null) || (!(indexWriter.getAnalyzer() instanceof SourceCodeAnalyzer))) { DoxMentor4J app = DoxMentor4J.getApp(); java.io.File archiveFile = app.getArchiveFile(); String dirName = app.getIndexDir(); String archiveDirName = app.getArchiveIndexDir(); if (indexWriter != null) try { indexWriter.close(); } catch (Exception e) { } Directory dir = null; try { if (archiveFile != null) IndexFactory.create(archiveFile, archiveDirName, dirName, new SourceIndexer.SourceCodeAnalyzer(), false, false); else IndexFactory.create(dirName, new SourceIndexer.SourceCodeAnalyzer(), false, false); m_indexWriter = IndexFactory.getWriter(); } catch (Exception e) { logger().error("Error opening index directory " + dirName, e); m_indexWriter = null; return; } } else { if (indexWriter.getAnalyzer() instanceof SourceCodeAnalyzer) ((SourceCodeAnalyzer) indexWriter.getAnalyzer()).setStopSet(); m_indexWriter = indexWriter; } }
From source file:org.archive.jbs.lucene.LuceneDocumentWriter.java
License:Apache License
public LuceneDocumentWriter(IndexWriter indexer) { this.indexer = indexer; this.analyzer = indexer.getAnalyzer(); }
From source file:org.hibernate.search.backend.impl.lucene.IndexWriterDelegate.java
License:LGPL
public IndexWriterDelegate(final IndexWriter indexWriter) { this.indexWriter = indexWriter; this.mutableAnalyzer = (ConcurrentlyMutableAnalyzer) indexWriter.getAnalyzer(); ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); }