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
b0aea8ef
Commit
b0aea8ef
authored
Mar 24, 2024
by
mohamad.alturky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit sources
parent
d28e1d02
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
108 additions
and
19 deletions
+108
-19
Lucene.java
src/main/java/com/search/lucene/Lucene.java
+1
-1
CSVDocumentStringRepresenter.java
...senters/implementations/CSVDocumentStringRepresenter.java
+13
-1
PDFDocumentStringRepresenter.java
...senters/implementations/PDFDocumentStringRepresenter.java
+9
-1
TextDocumentStringRepresenter.java
...enters/implementations/TextDocumentStringRepresenter.java
+9
-1
IEngineBuilder.java
...ch/lucene/engine/builder/abstractions/IEngineBuilder.java
+9
-0
LuceneEngineBuilder.java
...e/engine/builder/implementations/LuceneEngineBuilder.java
+36
-0
LuceneEngine.java
...om/search/lucene/engine/implementations/LuceneEngine.java
+3
-2
IFileIndexer.java
...com/search/lucene/indexers/abstractions/IFileIndexer.java
+3
-0
CSVFileIndexer.java
...earch/lucene/indexers/implementations/CSVFileIndexer.java
+4
-2
PDFFileIndexer.java
...earch/lucene/indexers/implementations/PDFFileIndexer.java
+5
-4
TextFileIndexer.java
...arch/lucene/indexers/implementations/TextFileIndexer.java
+4
-3
IndexPaths.java
src/main/java/com/search/lucene/settings/IndexPaths.java
+7
-0
IndexType.java
src/main/java/com/search/lucene/settings/IndexType.java
+5
-4
No files found.
src/main/java/com/search/lucene/Lucene.java
View file @
b0aea8ef
...
...
@@ -31,7 +31,7 @@ public class Lucene {
}
private
static
void
createIndex
()
throws
IOException
{
indexer
=
new
TextFileIndexer
(
indexDir
,
new
TextFileFilter
()
);
indexer
=
new
TextFileIndexer
(
indexDir
);
int
numIndexed
;
long
startTime
=
System
.
currentTimeMillis
();
numIndexed
=
indexer
.
createIndex
(
dataDir
);
...
...
src/main/java/com/search/lucene/documents/representers/implementations/CSVDocumentStringRepresenter.java
View file @
b0aea8ef
package
com
.
search
.
lucene
.
documents
.
representers
.
implementations
;
import
com.search.lucene.documents.representers.abstractions.IDocumentRepresenter
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.document.Document
;
public
class
CSVDocumentStringRepresenter
implements
IDocumentRepresenter
<
String
>
{
@Override
public
String
Represent
(
Document
indexedDocument
)
{
return
null
;
return
String
.
format
(
"""
file path = %s\s
file name = %s\s
in row = %s\s
in column = %s\s
with content = %s\s
"""
,
indexedDocument
.
get
(
Constants
.
FILE_PATH
),
indexedDocument
.
get
(
Constants
.
FILE_NAME
),
indexedDocument
.
get
(
Constants
.
ROW
),
indexedDocument
.
get
(
Constants
.
COLUMN
),
indexedDocument
.
get
(
Constants
.
VALUE
));
}
}
src/main/java/com/search/lucene/documents/representers/implementations/PDFDocumentStringRepresenter.java
View file @
b0aea8ef
package
com
.
search
.
lucene
.
documents
.
representers
.
implementations
;
import
com.search.lucene.documents.representers.abstractions.IDocumentRepresenter
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.document.Document
;
public
class
PDFDocumentStringRepresenter
implements
IDocumentRepresenter
<
String
>
{
@Override
public
String
Represent
(
Document
indexedDocument
)
{
return
null
;
return
String
.
format
(
"""
file path = %s\s
file name = %s\s
with content = %s\s
"""
,
indexedDocument
.
get
(
Constants
.
FILE_PATH
),
indexedDocument
.
get
(
Constants
.
FILE_NAME
),
indexedDocument
.
get
(
Constants
.
CONTENTS
));
}
}
src/main/java/com/search/lucene/documents/representers/implementations/TextDocumentStringRepresenter.java
View file @
b0aea8ef
package
com
.
search
.
lucene
.
documents
.
representers
.
implementations
;
import
com.search.lucene.documents.representers.abstractions.IDocumentRepresenter
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.document.Document
;
public
class
TextDocumentStringRepresenter
implements
IDocumentRepresenter
<
String
>
{
@Override
public
String
Represent
(
Document
indexedDocument
)
{
return
null
;
return
String
.
format
(
"""
file path = %s\s
file name = %s\s
with content = %s\s
"""
,
indexedDocument
.
get
(
Constants
.
FILE_PATH
),
indexedDocument
.
get
(
Constants
.
FILE_NAME
),
indexedDocument
.
get
(
Constants
.
CONTENTS
));
}
}
src/main/java/com/search/lucene/engine/builder/abstractions/IEngineBuilder.java
0 → 100644
View file @
b0aea8ef
package
com
.
search
.
lucene
.
engine
.
builder
.
abstractions
;
import
com.search.lucene.engine.abstractions.ISearchEngine
;
import
java.io.IOException
;
public
interface
IEngineBuilder
{
ISearchEngine
build
()
throws
IOException
;
}
src/main/java/com/search/lucene/engine/builder/implementations/LuceneEngineBuilder.java
0 → 100644
View file @
b0aea8ef
package
com
.
search
.
lucene
.
engine
.
builder
.
implementations
;
import
com.search.lucene.engine.abstractions.ISearchEngine
;
import
com.search.lucene.engine.builder.abstractions.IEngineBuilder
;
import
com.search.lucene.engine.implementations.LuceneEngine
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.indexers.implementations.CSVFileIndexer
;
import
com.search.lucene.indexers.implementations.PDFFileIndexer
;
import
com.search.lucene.indexers.implementations.TextFileIndexer
;
import
com.search.lucene.searchers.abstractions.ISearcher
;
import
com.search.lucene.searchers.implementations.CSVFileSearcher
;
import
com.search.lucene.searchers.implementations.PDFFileSearcher
;
import
com.search.lucene.searchers.implementations.TextFileSearcher
;
import
com.search.lucene.settings.IndexPaths
;
import
java.io.IOException
;
import
java.util.ArrayList
;
public
class
LuceneEngineBuilder
implements
IEngineBuilder
{
@Override
public
ISearchEngine
build
()
throws
IOException
{
ArrayList
<
IFileIndexer
>
indexers
=
new
ArrayList
<>();
indexers
.
add
(
new
CSVFileIndexer
(
IndexPaths
.
CSV_INDEX_FOLDER_PATH
));
indexers
.
add
(
new
PDFFileIndexer
(
IndexPaths
.
PDF_INDEX_FOLDER_PATH
));
indexers
.
add
(
new
TextFileIndexer
(
IndexPaths
.
TEXT_INDEX_FOLDER_PATH
));
ArrayList
<
ISearcher
>
searchers
=
new
ArrayList
<>();
searchers
.
add
(
new
CSVFileSearcher
(
IndexPaths
.
CSV_INDEX_FOLDER_PATH
));
searchers
.
add
(
new
PDFFileSearcher
(
IndexPaths
.
PDF_INDEX_FOLDER_PATH
));
searchers
.
add
(
new
TextFileSearcher
(
IndexPaths
.
TEXT_INDEX_FOLDER_PATH
));
return
new
LuceneEngine
(
indexers
,
searchers
);
}
}
src/main/java/com/search/lucene/engine/implementations/LuceneEngine.java
View file @
b0aea8ef
...
...
@@ -20,8 +20,9 @@ public class LuceneEngine implements ISearchEngine {
@Override
public
void
createIndexForDirectory
(
String
directoryPath
)
throws
IOException
{
for
(
var
indexer
:
indexers
){
indexer
.
createIndex
(
directoryPath
);
for
(
IFileIndexer
indexer
:
indexers
)
{
indexer
.
createIndex
(
directoryPath
);
indexer
.
close
();
}
}
...
...
src/main/java/com/search/lucene/indexers/abstractions/IFileIndexer.java
View file @
b0aea8ef
package
com
.
search
.
lucene
.
indexers
.
abstractions
;
import
org.apache.lucene.index.CorruptIndexException
;
import
java.io.FileFilter
;
import
java.io.IOException
;
public
interface
IFileIndexer
{
int
createIndex
(
String
dataDirectoryPath
)
throws
IOException
;
void
close
()
throws
CorruptIndexException
,
IOException
;
}
src/main/java/com/search/lucene/indexers/implementations/CSVFileIndexer.java
View file @
b0aea8ef
...
...
@@ -2,6 +2,7 @@ package com.search.lucene.indexers.implementations;
import
com.opencsv.CSVReader
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.file.filters.implementations.CSVFileFilter
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
...
...
@@ -26,8 +27,8 @@ public class CSVFileIndexer implements IFileIndexer {
private
final
IndexWriter
writer
;
private
final
IFileFilter
filter
;
public
CSVFileIndexer
(
String
indexDirectoryPath
,
IFileFilter
filter
)
throws
IOException
{
this
.
filter
=
filter
;
public
CSVFileIndexer
(
String
indexDirectoryPath
)
throws
IOException
{
this
.
filter
=
new
CSVFileFilter
()
;
//this directory will contain the indexes
Directory
indexDirectory
=
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
...
...
@@ -36,6 +37,7 @@ public class CSVFileIndexer implements IFileIndexer {
writer
=
new
IndexWriter
(
indexDirectory
,
new
IndexWriterConfig
(
new
StandardAnalyzer
()));
}
@Override
public
void
close
()
throws
CorruptIndexException
,
IOException
{
writer
.
close
();
}
...
...
src/main/java/com/search/lucene/indexers/implementations/PDFFileIndexer.java
View file @
b0aea8ef
package
com
.
search
.
lucene
.
indexers
.
implementations
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.file.filters.implementations.PDFFileFilter
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
...
...
@@ -25,15 +26,15 @@ public class PDFFileIndexer implements IFileIndexer {
private
final
IndexWriter
writer
;
private
final
IFileFilter
filter
;
public
PDFFileIndexer
(
String
indexDirectoryPath
,
IFileFilter
fileFilter
)
throws
IOException
{
public
PDFFileIndexer
(
String
indexDirectoryPath
)
throws
IOException
{
//this directory will contain the indexes
Directory
indexDirectory
=
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
this
.
filter
=
fileFilter
;
this
.
filter
=
new
PDFFileFilter
()
;
//create the indexer
writer
=
new
IndexWriter
(
indexDirectory
,
new
IndexWriterConfig
(
new
StandardAnalyzer
()));
}
@Override
public
void
close
()
throws
CorruptIndexException
,
IOException
{
writer
.
close
();
}
...
...
@@ -49,7 +50,7 @@ public class PDFFileIndexer implements IFileIndexer {
writer
.
addDocument
(
document
);
pdDocument
.
close
();
return
document
;
return
document
;
}
private
void
indexFile
(
File
file
)
throws
IOException
{
...
...
src/main/java/com/search/lucene/indexers/implementations/TextFileIndexer.java
View file @
b0aea8ef
...
...
@@ -7,6 +7,7 @@ import java.io.IOException;
import
java.nio.file.Paths
;
import
com.search.lucene.file.filters.abstractions.IFileFilter
;
import
com.search.lucene.file.filters.implementations.TextFileFilter
;
import
com.search.lucene.indexers.abstractions.IFileIndexer
;
import
com.search.lucene.settings.Constants
;
import
org.apache.lucene.analysis.standard.StandardAnalyzer
;
...
...
@@ -22,8 +23,8 @@ public class TextFileIndexer implements IFileIndexer {
private
final
IndexWriter
writer
;
private
final
IFileFilter
filter
;
public
TextFileIndexer
(
String
indexDirectoryPath
,
IFileFilter
filter
)
throws
IOException
{
this
.
filter
=
filter
;
public
TextFileIndexer
(
String
indexDirectoryPath
)
throws
IOException
{
this
.
filter
=
new
TextFileFilter
()
;
//this directory will contain the indexes
Directory
indexDirectory
=
FSDirectory
.
open
(
Paths
.
get
(
indexDirectoryPath
));
...
...
@@ -31,7 +32,7 @@ public class TextFileIndexer implements IFileIndexer {
//create the indexer
writer
=
new
IndexWriter
(
indexDirectory
,
new
IndexWriterConfig
(
new
StandardAnalyzer
()));
}
@Override
public
void
close
()
throws
CorruptIndexException
,
IOException
{
writer
.
close
();
}
...
...
src/main/java/com/search/lucene/settings/IndexPaths.java
0 → 100644
View file @
b0aea8ef
package
com
.
search
.
lucene
.
settings
;
public
final
class
IndexPaths
{
public
static
final
String
CSV_INDEX_FOLDER_PATH
=
"csvIndex"
;
public
static
final
String
TEXT_INDEX_FOLDER_PATH
=
"textIndex"
;
public
static
final
String
PDF_INDEX_FOLDER_PATH
=
"pdfIndex"
;
}
src/main/java/com/search/lucene/settings/IndexType.java
View file @
b0aea8ef
package
com
.
search
.
lucene
.
settings
;
public
enum
IndexType
{
CSV
,
PDF
,
TEXT
public
final
class
IndexType
{
public
static
final
String
CSV
=
"CSV"
;
public
static
final
String
PDF
=
"PDF"
;
public
static
final
String
TEXT
=
"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