Java Code Examples for org.apache.lucene.util.Version#LUCENE_40

The following examples show how to use org.apache.lucene.util.Version#LUCENE_40 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Indexer.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
public Indexer(FullTextIndexShared index, Analyzer analyzer) throws IOException {
    IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, analyzer);
    iwc.setMaxBufferedDeleteTerms(1); // The deletion needs to be reflected immediately (on disk)
    this.index = index;
    this.writer = new IndexWriter(index.open(),  iwc);

}
 
Example 2
Source File: HelpManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Search Lucene
 *
 * @param queryStr
 * @param defaultField
 * @return
 * @throws ParseException
 */
protected Set<Resource> searchResources(String queryStr, String defaultField)
throws ParseException
{
	Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
	QueryParser parser = new QueryParser(Version.LUCENE_40, defaultField, analyzer);
	Query query = parser.parse(queryStr);
	return searchResources(query);
}
 
Example 3
Source File: HelpManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Search Lucene
 *
 * @param queryStr
 * @param defaultField
 * @return
 * @throws ParseException
 */
protected Set<Resource> searchResources(String queryStr, String defaultField)
throws ParseException
{
	Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
	QueryParser parser = new QueryParser(Version.LUCENE_40, defaultField, analyzer);
	Query query = parser.parse(queryStr);
	return searchResources(query);
}
 
Example 4
Source File: IndexFiles.java    From word2vec-query-expansion with Apache License 2.0 4 votes vote down vote up
/** Index all text files under a directory. */
  @SuppressWarnings("deprecation")
public static void main(String[] args) {
    String usage = "java org.apache.lucene.demo.IndexFiles"
                 + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n"
                 + "This indexes the documents in DOCS_PATH, creating a Lucene index"
                 + "in INDEX_PATH that can be searched with SearchFiles";
    String indexPath = "index";
    String docsPath = null;
    boolean create = true;
    for(int i=0;i<args.length;i++) {
      if ("-index".equals(args[i])) {
        indexPath = args[i+1];
        i++;
      } else if ("-docs".equals(args[i])) {
        docsPath = args[i+1];
        i++;
      } else if ("-update".equals(args[i])) {
        create = false;
      }
    }

    if (docsPath == null) {
      System.err.println("Usage: " + usage);
      System.exit(1);
    }

    final File docDir = new File(docsPath);
    if (!docDir.exists() || !docDir.canRead()) {
      System.out.println("Document directory '" +docDir.getAbsolutePath()+ "' does not exist or is not readable, please check the path");
      System.exit(1);
    }
    
    Date start = new Date();
    try {
      System.out.println("Indexing to directory '" + indexPath + "'...");

      Directory dir = FSDirectory.open(new File(indexPath));
      Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
      IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, analyzer);

      if (create) {
        // Create a new index in the directory, removing any
        // previously indexed documents:
        iwc.setOpenMode(OpenMode.CREATE);
      } else {
        // Add new documents to an existing index:
        iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
      }

      // Optional: for better indexing performance, if you
      // are indexing many documents, increase the RAM
      // buffer.  But if you do this, increase the max heap
      // size to the JVM (eg add -Xmx512m or -Xmx1g):
      //
      // iwc.setRAMBufferSizeMB(256.0);

      IndexWriter writer = new IndexWriter(dir, iwc);
      indexDocs(writer, docDir);

      // NOTE: if you want to maximize search performance,
      // you can optionally call forceMerge here.  This can be
      // a terribly costly operation, so generally it's only
      // worth it when your index is relatively static (ie
      // you're done adding documents to it):
      //
      // writer.forceMerge(1);

      writer.close();

      Date end = new Date();
      System.out.println(end.getTime() - start.getTime() + " total milliseconds");

    } catch (IOException e) {
      System.out.println(" caught a " + e.getClass() +
       "\n with message: " + e.getMessage());
    }
  }
 
Example 5
Source File: ProtoSerializer.java    From incubator-retired-blur with Apache License 2.0 3 votes vote down vote up
public static void main(String[] args) throws ParseException, IOException {

    QueryParser parser = new QueryParser(Version.LUCENE_40, "", new StandardAnalyzer(Version.LUCENE_40));

    Query query = parser.parse("a:v1 b:v2 c:v3~ c:asda*asda");
    
    SuperQuery superQuery = new SuperQuery(query,ScoreType.SUPER,new Term("_primedoc_"));

    QueryWritable queryWritable = new QueryWritable(superQuery);
    DataOutputBuffer buffer = new DataOutputBuffer();
    queryWritable.write(buffer);
    buffer.close();

    System.out.println(new String(buffer.getData(), 0, buffer.getLength()));

    QueryWritable qw = new QueryWritable();

    DataInputBuffer in = new DataInputBuffer();
    in.reset(buffer.getData(), 0, buffer.getLength());
    qw.readFields(in);

    System.out.println("------------");
    
    System.out.println(qw.getQuery());
    
    System.out.println("------------");

    while (true) {
      run(superQuery);
    }
  }