def main(cls, argv): allBooks = MatchAllDocsQuery() parser = QueryParser(Version.LUCENE_CURRENT, "contents", StandardAnalyzer(Version.LUCENE_CURRENT)) query = BooleanQuery() query.add(allBooks, BooleanClause.Occur.SHOULD) query.add(parser.parse("java OR action"), BooleanClause.Occur.SHOULD) indexDir = System.getProperty("index.dir") directory = SimpleFSDirectory(File(indexDir)) example = SortingExample(directory) example.displayResults(query, Sort.RELEVANCE) example.displayResults(query, Sort.INDEXORDER) example.displayResults(query, Sort(SortField("category", SortField.STRING))) example.displayResults(query, Sort(SortField("pubmonth", SortField.INT, True))) example.displayResults(query, Sort([SortField("category", SortField.STRING), SortField.FIELD_SCORE, SortField("pubmonth", SortField.INT, True)])) example.displayResults(query, Sort([SortField.FIELD_SCORE, SortField("category", SortField.STRING)])) directory.close()
def setUp(self): fsIndexDir = os.path.join(System.getProperty("java.io.tmpdir", "tmp"), "fs-index") self.rmdir(fsIndexDir) self.ramDir = RAMDirectory() self.fsDir = SimpleFSDirectory(File(fsIndexDir))
def setUp(self): indexDir = os.path.join(System.getProperty('java.io.tmpdir', 'tmp'), 'index-dir') self.rmdir(indexDir) self.dir = SimpleFSDirectory(File(indexDir)) self.addDocuments(self.dir)
def main(cls, argv): if len(argv) < 5: print "Usage: python IndexTuningDemo.py <numDocs> <mergeFactor> <maxMergeDocs> <maxBufferedDocs>" return docsInIndex = int(argv[1]) # create an index called 'index-dir' in a temp directory indexDir = os.path.join(System.getProperty('java.io.tmpdir', 'tmp'), 'index-dir') dir = FSDirectory.getDirectory(indexDir, True) analyzer = SimpleAnalyzer() writer = IndexWriter(dir, analyzer, True) # set variables that affect speed of indexing writer.setMergeFactor(int(argv[2])) writer.setMaxMergeDocs(int(argv[3])) writer.setMaxBufferedDocs(int(argv[4])) # writer.infoStream = System.out print "Merge factor: ", writer.getMergeFactor() print "Max merge docs:", writer.getMaxMergeDocs() print "Max buffered docs:", writer.getMaxBufferedDocs() start = time() for i in xrange(docsInIndex): doc = Document() doc.add( Field("fieldname", "Bibamus", Field.Store.YES, Field.Index.TOKENIZED)) writer.addDocument(doc) writer.close() print "Time: ", timedelta(seconds=time() - start)
def setUp(self): indexDir = os.path.join(System.getProperty("java.io.tmpdir", "tmp"), "index-dir") cIndexDir = "%s-compound" % (indexDir) mIndexDir = "%s-multi" % (indexDir) self.rmdir(cIndexDir) self.rmdir(mIndexDir) self.cDir = SimpleFSDirectory(File(cIndexDir)) self.mDir = SimpleFSDirectory(File(mIndexDir))
def index(self): dirPath = os.path.join(System.getProperty("java.io.tmpdir", "tmp"), "verbose-index") dir = FSDirectory.getDirectory(dirPath, True) writer = IndexWriter(dir, SimpleAnalyzer(), True) writer.setInfoStream(System.out) for i in xrange(100): doc = Document() doc.add(Field("keyword", "goober", Field.Store.YES, Field.Index.UN_TOKENIZED)) writer.addDocument(doc) writer.optimize() writer.close()
def main(cls, argv): indexDir = System.getProperty("index.dir") directory = SimpleFSDirectory(File(indexDir)) reader = IndexReader.open(directory, True) blt = BooksLikeThis(reader) for id in xrange(reader.maxDoc()): if reader.isDeleted(id): continue doc = reader.document(id) print '' print doc.get("title").encode('utf-8') docs = blt.docsLike(id, doc, 10) if not docs: print " None like this" else: for doc in docs: print " ->", doc.get("title").encode('utf-8')
import os, sys, lucene lucene.initVM() baseDir = os.path.dirname(os.path.abspath(sys.argv[0])) sys.path.append(baseDir) from lia.advsearching.BooksLikeThis import BooksLikeThis from lucene import System System.setProperty("index.dir", os.path.join(baseDir, "index")) BooksLikeThis.main(sys.argv)
def setUp(self): indexDir = os.path.join(System.getProperty("java.io.tmpdir", "tmp"), "index-dir") self.dir = SimpleFSDirectory(File(indexDir))
import os, sys, unittest, lucene lucene.initVM() baseDir = os.path.dirname(os.path.abspath(sys.argv[0])) sys.path.append(baseDir) import lia.searching.TermRangeQueryTest from lucene import System System.setProperty("index.dir", os.path.join(baseDir, 'index')) unittest.main(lia.searching.TermRangeQueryTest)
def __init__(self, *args): super(LiaTestCase, self).__init__(*args) self.indexDir = System.getProperty("index.dir")