Search in sources :

Example 11 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class QueryDriver method main.

public static void main(String[] args) throws Exception {
    if (args.length < 4 || args.length > 5) {
        System.err.println("Usage: QueryDriver <topicsFile> <qrelsFile> <submissionFile> <indexDir> [querySpec]");
        System.err.println("topicsFile: input file containing queries");
        System.err.println("qrelsFile: input file containing relevance judgements");
        System.err.println("submissionFile: output submission file for trec_eval");
        System.err.println("indexDir: index directory");
        System.err.println("querySpec: string composed of fields to use in query consisting of T=title,D=description,N=narrative:");
        System.err.println("\texample: TD (query on Title + Description). The default is T (title only)");
        System.exit(1);
    }
    Path topicsFile = Paths.get(args[0]);
    Path qrelsFile = Paths.get(args[1]);
    Path submissionFile = Paths.get(args[2]);
    SubmissionReport submitLog = new SubmissionReport(new PrintWriter(Files.newBufferedWriter(submissionFile, StandardCharsets.UTF_8)), "lucene");
    FSDirectory dir = FSDirectory.open(Paths.get(args[3]));
    // default to Title-only if not specified.
    String fieldSpec = args.length == 5 ? args[4] : "T";
    IndexReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = new IndexSearcher(reader);
    int maxResults = 1000;
    String docNameField = "docname";
    PrintWriter logger = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()), true);
    // use trec utilities to read trec topics into quality queries
    TrecTopicsReader qReader = new TrecTopicsReader();
    QualityQuery[] qqs = qReader.readQueries(Files.newBufferedReader(topicsFile, StandardCharsets.UTF_8));
    // prepare judge, with trec utilities that read from a QRels file
    Judge judge = new TrecJudge(Files.newBufferedReader(qrelsFile, StandardCharsets.UTF_8));
    // validate topics & judgments match each other
    judge.validateData(qqs, logger);
    Set<String> fieldSet = new HashSet<>();
    if (fieldSpec.indexOf('T') >= 0)
        fieldSet.add("title");
    if (fieldSpec.indexOf('D') >= 0)
        fieldSet.add("description");
    if (fieldSpec.indexOf('N') >= 0)
        fieldSet.add("narrative");
    // set the parsing of quality queries into Lucene queries.
    QualityQueryParser qqParser = new SimpleQQParser(fieldSet.toArray(new String[0]), "body");
    // run the benchmark
    QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);
    qrun.setMaxResults(maxResults);
    QualityStats[] stats = qrun.execute(judge, submitLog, logger);
    // print an avarage sum of the results
    QualityStats avg = QualityStats.average(stats);
    avg.log("SUMMARY", 2, logger, "  ");
    reader.close();
    dir.close();
}
Also used : Path(java.nio.file.Path) IndexSearcher(org.apache.lucene.search.IndexSearcher) FSDirectory(org.apache.lucene.store.FSDirectory) SimpleQQParser(org.apache.lucene.benchmark.quality.utils.SimpleQQParser) SubmissionReport(org.apache.lucene.benchmark.quality.utils.SubmissionReport) IndexReader(org.apache.lucene.index.IndexReader) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet)

Example 12 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class BlockDirectoryTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    file = createTempDir().toFile();
    FSDirectory dir = FSDirectory.open(new File(file, "base").toPath());
    mapperCache = new MapperCache();
    if (random().nextBoolean()) {
        Metrics metrics = new Metrics();
        int blockSize = 8192;
        int slabSize = blockSize * 16384;
        long totalMemory = 1 * slabSize;
        BlockCache blockCache = new BlockCache(metrics, true, totalMemory, slabSize, blockSize);
        BlockDirectoryCache cache = new BlockDirectoryCache(blockCache, "/collection1", metrics, true);
        directory = new BlockDirectory("test", dir, cache, null, true, false);
    } else {
        directory = new BlockDirectory("test", dir, mapperCache, null, true, true);
    }
    random = random();
}
Also used : FSDirectory(org.apache.lucene.store.FSDirectory) File(java.io.File) Before(org.junit.Before)

Example 13 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class IndexMergeTool method main.

public static void main(String[] args) throws IOException {
    if (args.length < 3) {
        System.err.println("Usage: IndexMergeTool <mergedIndex> <index1> <index2> [index3] ...");
        System.exit(1);
    }
    FSDirectory mergedIndex = FSDirectory.open(Paths.get(args[0]));
    IndexWriter writer = new IndexWriter(mergedIndex, new IndexWriterConfig(null).setOpenMode(OpenMode.CREATE));
    Directory[] indexes = new Directory[args.length - 1];
    for (int i = 1; i < args.length; i++) {
        // try to use hardlinks if possible
        indexes[i - 1] = new HardlinkCopyDirectoryWrapper(FSDirectory.open(Paths.get(args[i])));
    }
    System.out.println("Merging...");
    writer.addIndexes(indexes);
    System.out.println("Full merge...");
    writer.forceMerge(1);
    writer.close();
    System.out.println("Done.");
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) FSDirectory(org.apache.lucene.store.FSDirectory) HardlinkCopyDirectoryWrapper(org.apache.lucene.store.HardlinkCopyDirectoryWrapper) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 14 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class IndexBasedSpellChecker method initSourceReader.

private void initSourceReader() {
    if (sourceLocation != null) {
        try {
            FSDirectory luceneIndexDir = FSDirectory.open(new File(sourceLocation).toPath());
            this.reader = DirectoryReader.open(luceneIndexDir);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : FSDirectory(org.apache.lucene.store.FSDirectory) IOException(java.io.IOException) File(java.io.File)

Example 15 with FSDirectory

use of org.apache.lucene.store.FSDirectory in project lucene-solr by apache.

the class BlockDirectory method getFileModified.

private long getFileModified(String name) throws IOException {
    if (in instanceof FSDirectory) {
        File directory = ((FSDirectory) in).getDirectory().toFile();
        File file = new File(directory, name);
        if (!file.exists()) {
            throw new FileNotFoundException("File [" + name + "] not found");
        }
        return file.lastModified();
    } else if (in instanceof HdfsDirectory) {
        return ((HdfsDirectory) in).fileModified(name);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) HdfsDirectory(org.apache.solr.store.hdfs.HdfsDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) File(java.io.File)

Aggregations

FSDirectory (org.apache.lucene.store.FSDirectory)43 File (java.io.File)18 Directory (org.apache.lucene.store.Directory)12 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 IndexSearcher (org.apache.lucene.search.IndexSearcher)9 FileNotFoundException (java.io.FileNotFoundException)5 FileSystem (java.nio.file.FileSystem)5 Document (org.apache.lucene.document.Document)5 IndexReader (org.apache.lucene.index.IndexReader)5 MMapDirectory (org.apache.lucene.store.MMapDirectory)5 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)5 FilterDirectory (org.apache.lucene.store.FilterDirectory)4 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)4 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 Term (org.apache.lucene.index.Term)3 WindowsFS (org.apache.lucene.mockfile.WindowsFS)3 TermQuery (org.apache.lucene.search.TermQuery)3