Commit c5a3a023 authored by mohamad.alturky's avatar mohamad.alturky

Adding File Filters

parent 4b62dd72
File added
File added
File added
File added
File added
File added
File added
File added
File added
package com.search.lucene;
import java.io.IOException;
import com.search.lucene.file.filters.TextFileFilter;
import com.search.lucene.indexers.Indexer;
import com.search.lucene.searchers.Searcher;
import com.search.lucene.settings.LuceneConstants;
import org.apache.lucene.document.Document;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.ScoreDoc;
......@@ -17,6 +22,7 @@ public class Lucene {
try {
createIndex();
search("Kota");
search("s");
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
......
package com.search.lucene.file.filters;
import java.io.File;
import java.io.FileFilter;
public class CSVFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
return pathname.getName().toLowerCase().endsWith(".csv");
}
}
\ No newline at end of file
package com.search.lucene.file.filters;
import java.io.File;
import java.io.FileFilter;
public class PDFFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
return pathname.getName().toLowerCase().endsWith(".pdf");
}
}
\ No newline at end of file
package com.search.lucene;
package com.search.lucene.file.filters;
import java.io.File;
import java.io.FileFilter;
......
package com.search.lucene;
package com.search.lucene.indexers;
import java.io.File;
import java.io.FileFilter;
......@@ -37,8 +37,10 @@ public class Indexer {
Document document = new Document();
TextField contentField = new TextField(LuceneConstants.CONTENTS, new FileReader(file));
TextField fileNameField = new TextField(LuceneConstants.FILE_NAME,
file.getName(),TextField.Store.YES);
TextField filePathField = new TextField(LuceneConstants.FILE_PATH,
file.getCanonicalPath(),TextField.Store.YES);
......
package com.search.lucene;
package com.search.lucene.searchers;
import java.io.IOException;
import java.nio.file.Paths;
......
package com.search.lucene;
package com.search.lucene.settings;
public class LuceneConstants {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment