当前位置: 首页>>代码示例>>Java>>正文


Java WhitespaceAnalyzer类代码示例

本文整理汇总了Java中org.apache.lucene.analysis.WhitespaceAnalyzer的典型用法代码示例。如果您正苦于以下问题:Java WhitespaceAnalyzer类的具体用法?Java WhitespaceAnalyzer怎么用?Java WhitespaceAnalyzer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WhitespaceAnalyzer类属于org.apache.lucene.analysis包,在下文中一共展示了WhitespaceAnalyzer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIndexWriter

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
@Override
protected IndexWriter getIndexWriter() {
  if (++useCount % 1000 == 0) {
    close();
    writer = null;
  }
  if (writer == null) {
    try {
      boolean createIndex = true;
      File testIndexPath = new File(indexPath);
      if (!testIndexPath.exists())
        testIndexPath.mkdirs();
      if (testIndexPath.isDirectory()) {
        if (testIndexPath.list().length > 0)
          createIndex = false;
        writer = new IndexWriter(indexPath, new WhitespaceAnalyzer(), createIndex);
      }
    } catch (Exception ex) {
      log.fatal(ex);
    }
  }
  return writer;
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:24,代码来源:BulkIndexer.java

示例2: select

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
/**
  * Executes a select query.
  * @param query The Lucene query
  * @return An array of record IDs; an empty array if an error occured
* @throws IOException 
  */
 public int[] select(String query, String sortPrefix)  throws ParseException{
   try {
     WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
     BooleanQuery.setMaxClauseCount(20000);//zbog heap-a
     QueryParser p = new QueryParser("KW", sa);
     p.setDefaultOperator(QueryParser.Operator.AND); //default operator je AND a ne OR kao sto je inace inicijalno
     Query q = p.parse(query);
     return select(q, sortPrefix);
   } catch (Exception ex) {
   	if (ex instanceof ParseException )
   		throw (ParseException)ex;
     log.warn(ex);
     return new int[0];
   }
 }
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:22,代码来源:Retriever.java

示例3: getIndexWriter

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
/**
 * Returns a new Lucene index writer. Creates the index if necessary.  
 * @return
 */
protected IndexWriter getIndexWriter() {
  try {
    boolean createIndex = true;
    File testIndexPath = new File(indexPath);
    if (!testIndexPath.exists())
      testIndexPath.mkdirs();
    if (testIndexPath.isDirectory()) {
      if (testIndexPath.list().length > 0)
        createIndex = false;
      return new IndexWriter(indexPath, new WhitespaceAnalyzer(), createIndex);
    }
  } catch (Exception ex) {
    log.fatal(ex);
  }
  return null;
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:21,代码来源:Indexer.java

示例4: init

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
@Override
	public void init() throws IOException, IllegalStateException {
		Files.createDirectories(Paths.get(mentionsFolder));
		Files.createDirectories(Paths.get(resourcesFolder));

		writingOperations.put(KS.RESOURCE, new AtomicInteger(0));
		writingOperations.put(KS.MENTION, new AtomicInteger(0));

		try {
			writers.put(KS.RESOURCE, new IndexWriter(FSDirectory.open(new File(resourcesFolder)), new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED));
			writers.put(KS.MENTION, new IndexWriter(FSDirectory.open(new File(mentionsFolder)), new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED));

//			writers.get(KS.RESOURCE).setUseCompoundFile(true);
//			writers.get(KS.MENTION).setUseCompoundFile(true);

			writers.get(KS.RESOURCE).optimize(MAX_LUCENE_SEGMENTS);
			writers.get(KS.MENTION).optimize(MAX_LUCENE_SEGMENTS);

			readers.put(KS.RESOURCE, writers.get(KS.RESOURCE).getReader());
			readers.put(KS.MENTION, writers.get(KS.MENTION).getReader());
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
	}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:25,代码来源:LuceneDataStore.java

示例5: clearIndex

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
protected static boolean clearIndex(File path) {
	try {
		if (path == null || !path.exists())
			return true; // if path doesnt exist, then there is nothing to
							// clear

		FSDirectory indexDir = new FSDirectoryProvider().getDirectory();
		IndexWriter writer = new IndexWriter(indexDir.open(path),
				new IndexWriterConfig(Version.LUCENE_CURRENT,
						new WhitespaceAnalyzer(Version.LUCENE_CURRENT)));
		writer.deleteAll();
		writer.close();
		return true;
	} catch (Exception ex) {
		org.webdsl.logging.Logger.error(
				"Error while clearing index on location: " + path, ex);
		return false;
	}

}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:21,代码来源:AbstractIndexManager.java

示例6: setAutoCompleteIndex

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
/**
 * Use a different index as the auto completer index or re-open
 * the existing index if <code>autocompleteIndex</code> is the same value
 * as given in the constructor.
 * @param autocompleteIndexDir the autocomplete directory to use
 * @throws AlreadyClosedException if the Autocompleter is already closed
 * @throws  IOException if autocompleter can not open the directory
 */
// TODO: we should make this final as it is called in the constructor
public void setAutoCompleteIndex(Directory autocompleteIndexDir) throws IOException {
  // this could be the same directory as the current autocompleteIndex
  // modifications to the directory should be synchronized
  synchronized (modifyCurrentIndexLock) {
    ensureOpen();
    if (!IndexReader.indexExists(autocompleteIndexDir)) {
        IndexWriter writer = new IndexWriter(autocompleteIndexDir,
          new IndexWriterConfig(Version.LUCENE_CURRENT,
              new WhitespaceAnalyzer(Version.LUCENE_CURRENT)));
        writer.close();
    }
    swapSearcher(autocompleteIndexDir);
  }
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:24,代码来源:AutoCompleter.java

示例7: setUp

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
protected void setUp() throws Exception {
  Directory directory = new RAMDirectory();
  IndexWriter writer = new IndexWriter(directory,
                                       new WhitespaceAnalyzer(Version.LUCENE_41),
                                       IndexWriter.MaxFieldLength.UNLIMITED);
  Document doc1 = new Document();
  doc1.add(new Field("field",
            "the quick brown fox jumped over the lazy dog",
            Field.Store.YES, Field.Index.ANALYZED));
  writer.addDocument(doc1);
  Document doc2 = new Document();
  doc2.add(new Field("field",
            "the fast fox hopped over the hound",
            Field.Store.YES, Field.Index.ANALYZED));
  writer.addDocument(doc2);
  writer.close();

  searcher = new IndexSearcher(directory);
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:20,代码来源:MultiPhraseQueryTest.java

示例8: setUp

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
protected void setUp() throws Exception {
  directory = new RAMDirectory();
  IndexWriter writer =
      new IndexWriter(directory, new WhitespaceAnalyzer(Version.LUCENE_41),
                      IndexWriter.MaxFieldLength.UNLIMITED);
  addPoint(writer, "El Charro", "restaurant", 1, 2);
  addPoint(writer, "Cafe Poca Cosa", "restaurant", 5, 9);
  addPoint(writer, "Los Betos", "restaurant", 9, 6);
  addPoint(writer, "Nico's Taco Shop", "restaurant", 3, 8);

  writer.close();

  searcher = new IndexSearcher(directory);

  query = new TermQuery(new Term("type", "restaurant"));
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:17,代码来源:DistanceSortingTest.java

示例9: testAnalyzer

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
public void testAnalyzer() throws Exception {
  Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
  String queryString = "category:/philosophy/eastern";

  Query query = new QueryParser(Version.LUCENE_41,
                                "contents",
                                analyzer).parse(queryString);
  assertEquals("path got split, yikes!",
               "category:\"philosophy eastern\"",
               query.toString("contents"));

  PerFieldAnalyzerWrapper perFieldAnalyzer =
                          new PerFieldAnalyzerWrapper(analyzer);
  perFieldAnalyzer.addAnalyzer("category",
                                     new WhitespaceAnalyzer(Version.LUCENE_41));
  query = new QueryParser(Version.LUCENE_41,
                          "contents",
                          perFieldAnalyzer).parse(queryString);
  assertEquals("leave category field alone",
               "category:/philosophy/eastern",
               query.toString("contents"));
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:23,代码来源:AnalysisParalysisTest.java

示例10: createAnalyzer

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
public static Analyzer createAnalyzer() {
    final PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new KeywordAnalyzer());
    analyzer.addAnalyzer(DocumentUtil.FIELD_IDENTS, new WhitespaceAnalyzer());
    analyzer.addAnalyzer(DocumentUtil.FIELD_FEATURE_IDENTS, new WhitespaceAnalyzer());
    analyzer.addAnalyzer(DocumentUtil.FIELD_CASE_INSENSITIVE_FEATURE_IDENTS, new DocumentUtil.LCWhitespaceAnalyzer());
    return analyzer;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DocumentUtil.java

示例11: getQueryFilter

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
public static Filter getQueryFilter(String query){
	try{
		WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
		QueryParser p = new QueryParser("contents",sa);
		Query q = p.parse(query);
		Filter filter = new QueryWrapperFilter(q);
		return filter;
	}catch (Exception e){
		return null;
	}
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:12,代码来源:QueryUtils.java

示例12: selectExpand

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
public List<String> selectExpand(String query, String prefix,String text){
  try {
   WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
   BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
   QueryParser p = new QueryParser("contents", sa);
   Query q = p.parse(query);
   Searcher searcher = new IndexSearcher(indexPath);
   StopWatch clock=new StopWatch();
   clock.start();
   Hits hits = searcher.search(q);
   int n = hits.length();
   List <String> expandList = new ArrayList<String>();
   Field[] tmp = null;
   String pom="";
    for (int i = 0; i < n; i++) {
      tmp = hits.doc(i).getFields(prefix);
      if (tmp != null){
        for (int j = 0; j<tmp.length; j++){
      	  pom=tmp[j].stringValue().replace("0start0 ", "");
      	  pom=pom.replace(" 0end0", "");
      	  if(pom.startsWith(text)&&(!expandList.contains(pom))){
      	     expandList.add(pom);
      	  }
        } 
      }
    }
    clock.stop();
    searcher.close();
    return expandList;
  } catch (Exception ex) {
    log.fatal(ex);
    return null;
  }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:35,代码来源:Retriever.java

示例13: loadModel

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
@Override
public void loadModel(String modelPath) throws IOException {
	docsSearcher = new IndexSearcher((new File(modelPath, "docs"))
			.getAbsolutePath());
	String[] fields = { "doc_id", "content", "user_id", "tag" };
	queryParser = new MultiFieldQueryParser(fields,
			new WhitespaceAnalyzer());
}
 
开发者ID:thunlp,项目名称:THUTag,代码行数:9,代码来源:ExpandRankKE.java

示例14: clearIndex

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
/**
 * Removes all terms from the auto complete index.
 * @throws IOException
 * @throws AlreadyClosedException if the Autocompleter is already closed
 */
public void clearIndex() throws IOException {
  synchronized (modifyCurrentIndexLock) {
    ensureOpen();
    final Directory dir = this.autoCompleteIndex;
    final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
        Version.LUCENE_CURRENT,
        new WhitespaceAnalyzer(Version.LUCENE_CURRENT))
        .setOpenMode(OpenMode.CREATE));
    writer.close();
    swapSearcher(dir);
  }
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:18,代码来源:AutoCompleter.java

示例15: indexDictionary

import org.apache.lucene.analysis.WhitespaceAnalyzer; //导入依赖的package包/类
/**
  * Indexes the data from the given reader.
* @param reader Source index reader, from which autocomplete words are obtained for the defined field
* @param field the field of the source index reader to index for autocompletion
* @param mergeFactor mergeFactor to use when indexing
* @param ramMB the max amount or memory in MB to use
* @param optimize whether or not the autocomplete index should be optimized
  * @throws AlreadyClosedException if the Autocompleter is already closed
  * @throws IOException
  */
 public final void indexDictionary(IndexReader reader, String field, int mergeFactor, int ramMB, boolean optimize) throws IOException {
   synchronized (modifyCurrentIndexLock) {
     ensureOpen();
     final Directory dir = this.autoCompleteIndex;
     final Dictionary dict = new LuceneDictionary(reader, field);
     final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT)).setRAMBufferSizeMB(ramMB));
     IndexSearcher indexSearcher = obtainSearcher();
     final List<IndexReader> readers = new ArrayList<IndexReader>();

     if (searcher.maxDoc() > 0) {
       ReaderUtil.gatherSubReaders(readers, searcher.getIndexReader());
     }

     //clear the index
     writer.deleteAll();

     try {
       Iterator<String> iter = dict.getWordsIterator();

     while (iter.hasNext()) {
         String word = iter.next();

         // ok index the word
         Document doc = createDocument(word, reader.docFreq(new Term(field, word)));
         writer.addDocument(doc);
       }
     } finally {
       releaseSearcher(indexSearcher);
     }
     // close writer
     if (optimize)
       writer.optimize();
     writer.close();
     // also re-open the autocomplete index to see our own changes when the next suggestion
     // is fetched:
     swapSearcher(dir);
   }
 }
 
开发者ID:webdsl,项目名称:webdsl,代码行数:49,代码来源:AutoCompleter.java


注:本文中的org.apache.lucene.analysis.WhitespaceAnalyzer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。