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();
}
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();
}
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.");
}
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);
}
}
}
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();
}
}
Aggregations