Package org.apache.lucene.analysis.core

Examples of org.apache.lucene.analysis.core.SimpleAnalyzer


        doc.add(new Field("subject", "weapons",
                TextField.TYPE_NOT_STORED));

        /* setting up a writer with a default (simple) analyzer */
        writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(SKOSAnalysisPlugin.getLuceneVersion(),
                new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion())));

        /* adding the document to the index */
        writer.addDocument(doc);

        /* defining a query that searches over all fields */
 
View Full Code Here


        /* Define different analyzers for different fields */
        Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>();
        analyzerPerField.put("subject", skosAnalyzer);
        PerFieldAnalyzerWrapper indexAnalyzer = new PerFieldAnalyzerWrapper(
                new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion()), analyzerPerField);

        /* setting up a writer with a default (simple) analyzer */
        writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(SKOSAnalysisPlugin.getLuceneVersion(),
                indexAnalyzer));

View Full Code Here

        /* Define different analyzers for different fields */
        Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>();
        analyzerPerField.put("subject", skosAnalyzer);
        PerFieldAnalyzerWrapper indexAnalyzer = new PerFieldAnalyzerWrapper(
                new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion()), analyzerPerField);

        /* setting up a writer with a default (simple) analyzer */
        writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(SKOSAnalysisPlugin.getLuceneVersion(),
                indexAnalyzer));

View Full Code Here

        writer.addDocument(doc);

        searcher = new IndexSearcher(DirectoryReader.open(writer, false));

        StandardQueryParser parser = new StandardQueryParser(new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion()));

        Query query = parser.parse("united nations", "content");

        Assert.assertEquals(1, TestUtil.hitCount(searcher, query));
View Full Code Here

public class TestPerFieldAnalyzerWrapper extends BaseTokenStreamTestCase {
  public void testPerField() throws Exception {
    String text = "Qwerty";

    Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>();
    analyzerPerField.put("special", new SimpleAnalyzer(TEST_VERSION_CURRENT));

    PerFieldAnalyzerWrapper analyzer =
              new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(TEST_VERSION_CURRENT), analyzerPerField);

    TokenStream tokenStream = analyzer.tokenStream("field", text);
View Full Code Here

        if (!("N3".equals(lang) || "RDF/XML".equals(lang) || "TURTLE".equals(lang))) {
            throw new IOException("Invalid RDF serialization format");
        }

        analyzer = new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion());

        skosModel = ModelFactory.createDefaultModel();

        skosModel.read(inputStream, null, lang);
View Full Code Here

     * @param filenameOrURI file name or URI
     * @throws IOException
     */
    public SKOSEngineImpl(String indexPath, String filenameOrURI,
            String... languages) throws IOException {
        analyzer = new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion());

        String langSig = "";
        if (languages != null) {
            this.languages = new TreeSet<String>(Arrays.asList(languages));
            langSig = "-" + join(this.languages.iterator(), '.');
View Full Code Here

        }
        if (languages != null) {
            this.languages = new TreeSet<String>(Arrays.asList(languages));
        }

        analyzer = new SimpleAnalyzer(SKOSAnalysisPlugin.getLuceneVersion());

        skosModel = ModelFactory.createDefaultModel();

        skosModel.read(inputStream, null, format);
View Full Code Here

   * @throws SearchException in case of lock acquisition timeouts, IOException, or if a corrupt index is found
   */
  public static void initializeIndexIfNeeded(Directory directory) {
    //version doesn't really matter as we won't use the Analyzer
    Version version = Environment.DEFAULT_LUCENE_MATCH_VERSION;
    SimpleAnalyzer analyzer = new SimpleAnalyzer( version );
    try {
      if ( ! DirectoryReader.indexExists( directory ) ) {
        try {
          IndexWriterConfig iwriterConfig = new IndexWriterConfig( version, analyzer ).setOpenMode( OpenMode.CREATE );
          //Needs to have a timeout higher than zero to prevent race conditions over (network) RPCs
          //for distributed indexes (Infinispan but probably also NFS and similar)
          iwriterConfig.setWriteLockTimeout( 2000 );
          IndexWriter iw = new IndexWriter( directory, iwriterConfig );
          iw.close();
        }
        catch (LockObtainFailedException lofe) {
          log.lockingFailureDuringInitialization( directory.toString() );
        }
      }
    }
    catch (IOException e) {
      throw new SearchException( "Could not initialize index", e );
    }
    finally {
      analyzer.close();
    }
  }
View Full Code Here

   * @throws SearchException in case of lock acquisition timeouts, IOException, or if a corrupt index is found
   */
  public static void initializeIndexIfNeeded(Directory directory) {
    //version doesn't really matter as we won't use the Analyzer
    Version version = Environment.DEFAULT_LUCENE_MATCH_VERSION;
    SimpleAnalyzer analyzer = new SimpleAnalyzer( version );
    try {
      if ( ! DirectoryReader.indexExists( directory ) ) {
        IndexWriterConfig iwriterConfig = new IndexWriterConfig( version, analyzer ).setOpenMode( OpenMode.CREATE );
        IndexWriter iw = new IndexWriter( directory, iwriterConfig );
        iw.close();
      }
    }
    catch (IOException e) {
      throw new SearchException( "Could not initialize index", e );
    }
    finally {
      analyzer.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.analysis.core.SimpleAnalyzer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.