Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
lucene
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamad.alturky
lucene
Commits
2dad8d38
Commit
2dad8d38
authored
Mar 24, 2024
by
mohamad.alturky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring, adding engine and documents representers
parent
bba89b70
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
150 additions
and
52 deletions
+150
-52
Lucene.java
src/main/java/com/search/lucene/Lucene.java
+7
-7
IDocumentRepresenter.java
...ments/representers/abstractions/IDocumentRepresenter.java
+7
-0
CSVDocumentStringRepresenter.java
...senters/implementations/CSVDocumentStringRepresenter.java
+11
-0
PDFDocumentStringRepresenter.java
...senters/implementations/PDFDocumentStringRepresenter.java
+11
-0
TextDocumentStringRepresenter.java
...enters/implementations/TextDocumentStringRepresenter.java
+11
-0
ISearchEngine.java
.../com/search/lucene/engine/abstractions/ISearchEngine.java
+12
-0
LuceneEngine.java
...om/search/lucene/engine/implementations/LuceneEngine.java
+32
-0
CSVFileFilter.java
...ch/lucene/file/filters/implementations/CSVFileFilter.java
+1
-1
PDFFileFilter.java
...ch/lucene/file/filters/implementations/PDFFileFilter.java
+1
-1
TextFileFilter.java
...h/lucene/file/filters/implementations/TextFileFilter.java
+1
-1
IFileIndexer.java
...com/search/lucene/indexers/abstractions/IFileIndexer.java
+1
-1
CSVFileIndexer.java
...earch/lucene/indexers/implementations/CSVFileIndexer.java
+12
-9
PDFFileIndexer.java
...earch/lucene/indexers/implementations/PDFFileIndexer.java
+10
-9
TextFileIndexer.java
...arch/lucene/indexers/implementations/TextFileIndexer.java
+10
-7
CSVFileSearcher.java
...rch/lucene/searchers/implementations/CSVFileSearcher.java
+4
-4
PDFFileSearcher.java
...rch/lucene/searchers/implementations/PDFFileSearcher.java
+5
-5
TextFileSearcher.java
...ch/lucene/searchers/implementations/TextFileSearcher.java
+5
-6
Constants.java
src/main/java/com/search/lucene/settings/Constants.java
+2
-1
IndexType.java
src/main/java/com/search/lucene/settings/IndexType.java
+7
-0
No files found.
src/main/java/com/search/lucene/Lucene.java
View file @
2dad8d38
...
@@ -2,10 +2,10 @@ package com.search.lucene;
...
@@ -2,10 +2,10 @@ package com.search.lucene;
import
java.io.IOException
;
import
java.io.IOException
;
import
com.search.lucene.file.filters.TextFileFilter
;
import
com.search.lucene.file.filters.
implementations.
TextFileFilter
;
import
com.search.lucene.indexers.TextFileIndexer
;
import
com.search.lucene.indexers.
implementations.
TextFileIndexer
;
import
com.search.lucene.searchers.TextFileSearcher
;
import
com.search.lucene.searchers.
implementations.
TextFileSearcher
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.queryparser.classic.ParseException
;
import
org.apache.lucene.queryparser.classic.ParseException
;
import
org.apache.lucene.search.ScoreDoc
;
import
org.apache.lucene.search.ScoreDoc
;
...
@@ -31,10 +31,10 @@ public class Lucene {
...
@@ -31,10 +31,10 @@ public class Lucene {
}
}
private
static
void
createIndex
()
throws
IOException
{
private
static
void
createIndex
()
throws
IOException
{
indexer
=
new
TextFileIndexer
(
indexDir
);
indexer
=
new
TextFileIndexer
(
indexDir
,
new
TextFileFilter
()
);
int
numIndexed
;
int
numIndexed
;
long
startTime
=
System
.
currentTimeMillis
();
long
startTime
=
System
.
currentTimeMillis
();
numIndexed
=
indexer
.
createIndex
(
dataDir
,
new
TextFileFilter
()
);
numIndexed
=
indexer
.
createIndex
(
dataDir
);
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
indexer
.
close
();
indexer
.
close
();
System
.
out
.
println
(
numIndexed
+
" File indexed, time taken: "
System
.
out
.
println
(
numIndexed
+
" File indexed, time taken: "
...
@@ -52,7 +52,7 @@ public class Lucene {
...
@@ -52,7 +52,7 @@ public class Lucene {
for
(
ScoreDoc
scoreDoc
:
hits
.
scoreDocs
)
{
for
(
ScoreDoc
scoreDoc
:
hits
.
scoreDocs
)
{
Document
doc
=
textFileSearcher
.
getDocument
(
scoreDoc
);
Document
doc
=
textFileSearcher
.
getDocument
(
scoreDoc
);
System
.
out
.
println
(
"File: "
System
.
out
.
println
(
"File: "
+
doc
.
get
(
Lucene
Constants
.
FILE_PATH
));
+
doc
.
get
(
Constants
.
FILE_PATH
));
}
}
}
}
}
}
src/main/java/com/search/lucene/documents/representers/abstractions/IDocumentRepresenter.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
documents
.
representers
.
abstractions
;
import
org.apache.lucene.document.Document
;
public
interface
IDocumentRepresenter
<
T
>
{
T
Represent
(
Document
indexedDocument
);
}
src/main/java/com/search/lucene/documents/representers/implementations/CSVDocumentStringRepresenter.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
documents
.
representers
.
implementations
;
import
com.search.lucene.documents.representers.abstractions.IDocumentRepresenter
;
import
org.apache.lucene.document.Document
;
public
class
CSVDocumentStringRepresenter
implements
IDocumentRepresenter
<
String
>
{
@Override
public
String
Represent
(
Document
indexedDocument
)
{
return
null
;
}
}
src/main/java/com/search/lucene/documents/representers/implementations/PDFDocumentStringRepresenter.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
documents
.
representers
.
implementations
;
import
com.search.lucene.documents.representers.abstractions.IDocumentRepresenter
;
import
org.apache.lucene.document.Document
;
public
class
PDFDocumentStringRepresenter
implements
IDocumentRepresenter
<
String
>
{
@Override
public
String
Represent
(
Document
indexedDocument
)
{
return
null
;
}
}
src/main/java/com/search/lucene/documents/representers/implementations/TextDocumentStringRepresenter.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
documents
.
representers
.
implementations
;
import
com.search.lucene.documents.representers.abstractions.IDocumentRepresenter
;
import
org.apache.lucene.document.Document
;
public
class
TextDocumentStringRepresenter
implements
IDocumentRepresenter
<
String
>
{
@Override
public
String
Represent
(
Document
indexedDocument
)
{
return
null
;
}
}
src/main/java/com/search/lucene/engine/abstractions/ISearchEngine.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
engine
.
abstractions
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.queryparser.classic.ParseException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
public
interface
ISearchEngine
{
void
createIndexForDirectory
(
String
directoryPath
)
throws
IOException
;
ArrayList
<
Document
>
search
(
String
searchQuery
)
throws
IOException
,
ParseException
;
}
src/main/java/com/search/lucene/engine/implementations/LuceneEngine.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
engine
.
implementations
;
import
com.search.lucene.engine.abstractions.ISearchEngine
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.queryparser.classic.ParseException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
public
class
LuceneEngine
implements
ISearchEngine
{
private
final
ArrayList
<
IFileIndexer
>
indexers
;
private
final
ArrayList
<
ISearcher
>
searchers
;
public
LuceneEngine
(
ArrayList
<
IFileIndexer
>
indexers
,
ArrayList
<
ISearcher
>
searchers
)
{
this
.
indexers
=
indexers
;
this
.
searchers
=
searchers
;
}
@Override
public
void
createIndexForDirectory
(
String
directoryPath
)
throws
IOException
{
for
(
var
indexer
:
indexers
){
indexer
.
createIndex
(
directoryPath
);
}
}
@Override
public
ArrayList
<
Document
>
search
(
String
searchQuery
)
throws
IOException
,
ParseException
{
return
null
;
}
}
src/main/java/com/search/lucene/file/filters/CSVFileFilter.java
→
src/main/java/com/search/lucene/file/filters/
implementations/
CSVFileFilter.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
file
.
filters
;
package
com
.
search
.
lucene
.
file
.
filters
.
implementations
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
...
...
src/main/java/com/search/lucene/file/filters/PDFFileFilter.java
→
src/main/java/com/search/lucene/file/filters/
implementations/
PDFFileFilter.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
file
.
filters
;
package
com
.
search
.
lucene
.
file
.
filters
.
implementations
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
...
...
src/main/java/com/search/lucene/file/filters/TextFileFilter.java
→
src/main/java/com/search/lucene/file/filters/
implementations/
TextFileFilter.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
file
.
filters
;
package
com
.
search
.
lucene
.
file
.
filters
.
implementations
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
...
...
src/main/java/com/search/lucene/indexers/abstractions/IFileIndexer.java
View file @
2dad8d38
...
@@ -4,5 +4,5 @@ import java.io.FileFilter;
...
@@ -4,5 +4,5 @@ import java.io.FileFilter;
import
java.io.IOException
;
import
java.io.IOException
;
public
interface
IFileIndexer
{
public
interface
IFileIndexer
{
int
createIndex
(
String
dataDirectoryPath
,
FileFilter
filter
)
throws
IOException
;
int
createIndex
(
String
dataDirectoryPath
)
throws
IOException
;
}
}
src/main/java/com/search/lucene/indexers/CSVFileIndexer.java
→
src/main/java/com/search/lucene/indexers/
implementations/
CSVFileIndexer.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
indexers
;
package
com
.
search
.
lucene
.
indexers
.
implementations
;
import
com.opencsv.CSVReader
;
import
com.opencsv.CSVReader
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Field
;
import
org.apache.lucene.document.Field
;
...
@@ -23,8 +24,10 @@ import java.util.ArrayList;
...
@@ -23,8 +24,10 @@ import java.util.ArrayList;
public
class
CSVFileIndexer
implements
IFileIndexer
{
public
class
CSVFileIndexer
implements
IFileIndexer
{
private
final
IndexWriter
writer
;
private
final
IndexWriter
writer
;
private
final
IFileFilter
filter
;
public
CSVFileIndexer
(
String
indexDirectoryPath
)
throws
IOException
{
public
CSVFileIndexer
(
String
indexDirectoryPath
,
IFileFilter
filter
)
throws
IOException
{
this
.
filter
=
filter
;
//this directory will contain the indexes
//this directory will contain the indexes
Directory
indexDirectory
=
Directory
indexDirectory
=
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
...
@@ -53,11 +56,11 @@ public class CSVFileIndexer implements IFileIndexer {
...
@@ -53,11 +56,11 @@ public class CSVFileIndexer implements IFileIndexer {
for
(
int
i
=
0
;
i
<
nextRecord
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
nextRecord
.
length
;
i
++)
{
Document
document
=
new
Document
();
Document
document
=
new
Document
();
document
.
add
(
new
TextField
(
Lucene
Constants
.
COLUMN
,
columns
[
i
],
Field
.
Store
.
YES
));
document
.
add
(
new
TextField
(
Constants
.
COLUMN
,
columns
[
i
],
Field
.
Store
.
YES
));
document
.
add
(
new
TextField
(
Lucene
Constants
.
VALUE
,
nextRecord
[
i
],
Field
.
Store
.
YES
));
document
.
add
(
new
TextField
(
Constants
.
VALUE
,
nextRecord
[
i
],
Field
.
Store
.
YES
));
document
.
add
(
new
TextField
(
LuceneConstants
.
LINE
,
Integer
.
toString
(
line
),
Field
.
Store
.
YES
));
document
.
add
(
new
TextField
(
Constants
.
ROW
,
Integer
.
toString
(
line
),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Lucene
Constants
.
FILE_PATH
,
file
.
getCanonicalPath
(),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Constants
.
FILE_PATH
,
file
.
getCanonicalPath
(),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Lucene
Constants
.
FILE_NAME
,
file
.
getName
(),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Constants
.
FILE_NAME
,
file
.
getName
(),
Field
.
Store
.
YES
));
documents
.
add
(
document
);
documents
.
add
(
document
);
System
.
out
.
print
(
nextRecord
[
i
]
+
"\t"
);
System
.
out
.
print
(
nextRecord
[
i
]
+
"\t"
);
}
}
...
@@ -76,7 +79,7 @@ public class CSVFileIndexer implements IFileIndexer {
...
@@ -76,7 +79,7 @@ public class CSVFileIndexer implements IFileIndexer {
}
}
@Override
@Override
public
int
createIndex
(
String
dataDirectoryPath
,
FileFilter
filter
)
public
int
createIndex
(
String
dataDirectoryPath
)
throws
IOException
{
throws
IOException
{
File
[]
files
=
new
File
(
dataDirectoryPath
).
listFiles
();
File
[]
files
=
new
File
(
dataDirectoryPath
).
listFiles
();
...
...
src/main/java/com/search/lucene/indexers/PDFFileIndexer.java
→
src/main/java/com/search/lucene/indexers/
implementations/
PDFFileIndexer.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
indexers
;
package
com
.
search
.
lucene
.
indexers
.
implementations
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.TextField
;
import
org.apache.lucene.document.TextField
;
...
@@ -17,18 +18,18 @@ import org.apache.pdfbox.text.PDFTextStripper;
...
@@ -17,18 +18,18 @@ import org.apache.pdfbox.text.PDFTextStripper;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.FileFilter
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
public
class
PDFFileIndexer
implements
IFileIndexer
{
public
class
PDFFileIndexer
implements
IFileIndexer
{
private
final
IndexWriter
writer
;
private
final
IndexWriter
writer
;
private
final
IFileFilter
filter
;
public
PDFFileIndexer
(
String
indexDirectoryPath
)
throws
IOException
{
public
PDFFileIndexer
(
String
indexDirectoryPath
,
IFileFilter
fileFilter
)
throws
IOException
{
//this directory will contain the indexes
//this directory will contain the indexes
Directory
indexDirectory
=
Directory
indexDirectory
=
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
this
.
filter
=
fileFilter
;
//create the indexer
//create the indexer
writer
=
new
IndexWriter
(
indexDirectory
,
new
IndexWriterConfig
(
new
StandardAnalyzer
()));
writer
=
new
IndexWriter
(
indexDirectory
,
new
IndexWriterConfig
(
new
StandardAnalyzer
()));
}
}
...
@@ -42,9 +43,9 @@ public class PDFFileIndexer implements IFileIndexer {
...
@@ -42,9 +43,9 @@ public class PDFFileIndexer implements IFileIndexer {
PDDocument
pdDocument
=
PDDocument
.
load
(
file
);
PDDocument
pdDocument
=
PDDocument
.
load
(
file
);
String
content
=
new
PDFTextStripper
().
getText
(
pdDocument
);
String
content
=
new
PDFTextStripper
().
getText
(
pdDocument
);
Document
document
=
new
Document
();
Document
document
=
new
Document
();
document
.
add
(
new
TextField
(
Lucene
Constants
.
CONTENTS
,
content
,
Field
.
Store
.
YES
));
document
.
add
(
new
TextField
(
Constants
.
CONTENTS
,
content
,
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Lucene
Constants
.
FILE_PATH
,
file
.
getCanonicalPath
(),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Constants
.
FILE_PATH
,
file
.
getCanonicalPath
(),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Lucene
Constants
.
FILE_NAME
,
file
.
getName
(),
Field
.
Store
.
YES
));
document
.
add
(
new
StringField
(
Constants
.
FILE_NAME
,
file
.
getName
(),
Field
.
Store
.
YES
));
writer
.
addDocument
(
document
);
writer
.
addDocument
(
document
);
pdDocument
.
close
();
pdDocument
.
close
();
...
@@ -58,7 +59,7 @@ public class PDFFileIndexer implements IFileIndexer {
...
@@ -58,7 +59,7 @@ public class PDFFileIndexer implements IFileIndexer {
}
}
@Override
@Override
public
int
createIndex
(
String
dataDirectoryPath
,
FileFilter
filter
)
public
int
createIndex
(
String
dataDirectoryPath
)
throws
IOException
{
throws
IOException
{
File
[]
files
=
new
File
(
dataDirectoryPath
).
listFiles
();
File
[]
files
=
new
File
(
dataDirectoryPath
).
listFiles
();
...
...
src/main/java/com/search/lucene/indexers/TextFileIndexer.java
→
src/main/java/com/search/lucene/indexers/
implementations/
TextFileIndexer.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
indexers
;
package
com
.
search
.
lucene
.
indexers
.
implementations
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.FileFilter
;
...
@@ -6,8 +6,9 @@ import java.io.FileReader;
...
@@ -6,8 +6,9 @@ import java.io.FileReader;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.TextField
;
import
org.apache.lucene.document.TextField
;
...
@@ -19,8 +20,10 @@ import org.apache.lucene.store.FSDirectory;
...
@@ -19,8 +20,10 @@ import org.apache.lucene.store.FSDirectory;
public
class
TextFileIndexer
implements
IFileIndexer
{
public
class
TextFileIndexer
implements
IFileIndexer
{
private
final
IndexWriter
writer
;
private
final
IndexWriter
writer
;
private
final
IFileFilter
filter
;
public
TextFileIndexer
(
String
indexDirectoryPath
)
throws
IOException
{
public
TextFileIndexer
(
String
indexDirectoryPath
,
IFileFilter
filter
)
throws
IOException
{
this
.
filter
=
filter
;
//this directory will contain the indexes
//this directory will contain the indexes
Directory
indexDirectory
=
Directory
indexDirectory
=
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
...
@@ -36,12 +39,12 @@ public class TextFileIndexer implements IFileIndexer {
...
@@ -36,12 +39,12 @@ public class TextFileIndexer implements IFileIndexer {
private
Document
getDocument
(
File
file
)
throws
IOException
{
private
Document
getDocument
(
File
file
)
throws
IOException
{
Document
document
=
new
Document
();
Document
document
=
new
Document
();
TextField
contentField
=
new
TextField
(
Lucene
Constants
.
CONTENTS
,
new
FileReader
(
file
));
TextField
contentField
=
new
TextField
(
Constants
.
CONTENTS
,
new
FileReader
(
file
));
TextField
fileNameField
=
new
TextField
(
Lucene
Constants
.
FILE_NAME
,
TextField
fileNameField
=
new
TextField
(
Constants
.
FILE_NAME
,
file
.
getName
(),
TextField
.
Store
.
YES
);
file
.
getName
(),
TextField
.
Store
.
YES
);
TextField
filePathField
=
new
TextField
(
Lucene
Constants
.
FILE_PATH
,
TextField
filePathField
=
new
TextField
(
Constants
.
FILE_PATH
,
file
.
getCanonicalPath
(),
TextField
.
Store
.
YES
);
file
.
getCanonicalPath
(),
TextField
.
Store
.
YES
);
document
.
add
(
contentField
);
document
.
add
(
contentField
);
...
@@ -58,7 +61,7 @@ public class TextFileIndexer implements IFileIndexer {
...
@@ -58,7 +61,7 @@ public class TextFileIndexer implements IFileIndexer {
}
}
@Override
@Override
public
int
createIndex
(
String
dataDirectoryPath
,
FileFilter
filter
)
public
int
createIndex
(
String
dataDirectoryPath
)
throws
IOException
{
throws
IOException
{
File
[]
files
=
new
File
(
dataDirectoryPath
).
listFiles
();
File
[]
files
=
new
File
(
dataDirectoryPath
).
listFiles
();
...
...
src/main/java/com/search/lucene/searchers/CSVFileSearcher.java
→
src/main/java/com/search/lucene/searchers/
implementations/
CSVFileSearcher.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
searchers
;
package
com
.
search
.
lucene
.
searchers
.
implementations
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.index.CorruptIndexException
;
import
org.apache.lucene.index.CorruptIndexException
;
...
@@ -31,7 +31,7 @@ public class CSVFileSearcher implements ISearcher {
...
@@ -31,7 +31,7 @@ public class CSVFileSearcher implements ISearcher {
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
IndexReader
reader
=
DirectoryReader
.
open
(
indexDirectory
);
IndexReader
reader
=
DirectoryReader
.
open
(
indexDirectory
);
indexSearcher
=
new
IndexSearcher
(
reader
);
indexSearcher
=
new
IndexSearcher
(
reader
);
queryParser
=
new
QueryParser
(
Lucene
Constants
.
CONTENTS
,
queryParser
=
new
QueryParser
(
Constants
.
CONTENTS
,
new
StandardAnalyzer
());
new
StandardAnalyzer
());
}
}
...
@@ -39,7 +39,7 @@ public class CSVFileSearcher implements ISearcher {
...
@@ -39,7 +39,7 @@ public class CSVFileSearcher implements ISearcher {
public
TopDocs
search
(
String
searchQuery
)
public
TopDocs
search
(
String
searchQuery
)
throws
IOException
,
ParseException
{
throws
IOException
,
ParseException
{
query
=
queryParser
.
parse
(
searchQuery
);
query
=
queryParser
.
parse
(
searchQuery
);
return
indexSearcher
.
search
(
query
,
Lucene
Constants
.
MAX_SEARCH
);
return
indexSearcher
.
search
(
query
,
Constants
.
MAX_SEARCH
);
}
}
@Override
@Override
public
Document
getDocument
(
ScoreDoc
scoreDoc
)
public
Document
getDocument
(
ScoreDoc
scoreDoc
)
...
...
src/main/java/com/search/lucene/searchers/PDFFileSearcher.java
→
src/main/java/com/search/lucene/searchers/
implementations/
PDFFileSearcher.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
searchers
;
package
com
.
search
.
lucene
.
searchers
.
implementations
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.index.CorruptIndexException
;
import
org.apache.lucene.index.CorruptIndexException
;
...
@@ -31,15 +31,15 @@ public class PDFFileSearcher implements ISearcher {
...
@@ -31,15 +31,15 @@ public class PDFFileSearcher implements ISearcher {
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
IndexReader
reader
=
DirectoryReader
.
open
(
indexDirectory
);
IndexReader
reader
=
DirectoryReader
.
open
(
indexDirectory
);
indexSearcher
=
new
IndexSearcher
(
reader
);
indexSearcher
=
new
IndexSearcher
(
reader
);
queryParser
=
new
QueryParser
(
Lucene
Constants
.
CONTENTS
,
queryParser
=
new
QueryParser
(
Constants
.
CONTENTS
,
new
StandardAnalyzer
());
new
StandardAnalyzer
());
}
}
@Override
@Override
public
TopDocs
search
(
String
searchQuery
)
public
TopDocs
search
(
String
searchQuery
)
throws
IOException
,
ParseException
{
throws
IOException
,
ParseException
{
query
=
queryParser
.
parse
(
searchQuery
);
query
=
queryParser
.
parse
(
searchQuery
);
return
indexSearcher
.
search
(
query
,
Lucene
Constants
.
MAX_SEARCH
);
return
indexSearcher
.
search
(
query
,
Constants
.
MAX_SEARCH
);
}
}
@Override
@Override
public
Document
getDocument
(
ScoreDoc
scoreDoc
)
public
Document
getDocument
(
ScoreDoc
scoreDoc
)
...
...
src/main/java/com/search/lucene/searchers/TextFileSearcher.java
→
src/main/java/com/search/lucene/searchers/
implementations/
TextFileSearcher.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
searchers
;
package
com
.
search
.
lucene
.
searchers
.
implementations
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.settings.
Lucene
Constants
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.document.Document
;
import
org.apache.lucene.index.CorruptIndexException
;
import
org.apache.lucene.index.CorruptIndexException
;
...
@@ -31,20 +31,19 @@ public class TextFileSearcher implements ISearcher {
...
@@ -31,20 +31,19 @@ public class TextFileSearcher implements ISearcher {
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
IndexReader
reader
=
DirectoryReader
.
open
(
indexDirectory
);
IndexReader
reader
=
DirectoryReader
.
open
(
indexDirectory
);
indexSearcher
=
new
IndexSearcher
(
reader
);
indexSearcher
=
new
IndexSearcher
(
reader
);
queryParser
=
new
QueryParser
(
Lucene
Constants
.
CONTENTS
,
queryParser
=
new
QueryParser
(
Constants
.
CONTENTS
,
new
StandardAnalyzer
());
new
StandardAnalyzer
());
}
}
@Override
@Override
public
TopDocs
search
(
String
searchQuery
)
public
TopDocs
search
(
String
searchQuery
)
throws
IOException
,
ParseException
{
throws
IOException
,
ParseException
{
query
=
queryParser
.
parse
(
searchQuery
);
query
=
queryParser
.
parse
(
searchQuery
);
return
indexSearcher
.
search
(
query
,
Lucene
Constants
.
MAX_SEARCH
);
return
indexSearcher
.
search
(
query
,
Constants
.
MAX_SEARCH
);
}
}
@Override
@Override
public
Document
getDocument
(
ScoreDoc
scoreDoc
)
public
Document
getDocument
(
ScoreDoc
scoreDoc
)
throws
CorruptIndexException
,
IOException
{
throws
CorruptIndexException
,
IOException
{
return
indexSearcher
.
doc
(
scoreDoc
.
doc
);
return
indexSearcher
.
doc
(
scoreDoc
.
doc
);
}
}
}
}
\ No newline at end of file
src/main/java/com/search/lucene/settings/Constants.java
View file @
2dad8d38
package
com
.
search
.
lucene
.
settings
;
package
com
.
search
.
lucene
.
settings
;
public
class
Lucene
Constants
{
public
class
Constants
{
public
static
final
String
CONTENTS
=
"contents"
;
public
static
final
String
CONTENTS
=
"contents"
;
public
static
final
String
INDEXED_FROM_FILE_FORMAT
=
"from_format"
;
public
static
final
String
FILE_NAME
=
"filename"
;
public
static
final
String
FILE_NAME
=
"filename"
;
public
static
final
String
FILE_PATH
=
"filepath"
;
public
static
final
String
FILE_PATH
=
"filepath"
;
public
static
final
String
COLUMN
=
"column"
;
public
static
final
String
COLUMN
=
"column"
;
...
...
src/main/java/com/search/lucene/settings/IndexType.java
0 → 100644
View file @
2dad8d38
package
com
.
search
.
lucene
.
settings
;
public
enum
IndexType
{
CSV
,
PDF
,
TEXT
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment