Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
f44f4da2
"git@git.uibk.ac.at:c102348/olat-ci-cd-testing-project.git" did not exist on "c3fe231ebbe6da7aad1357f44ad71f6cafdc2cac"
Commit
f44f4da2
authored
11 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-535: ensure that the spell checker not grow over time
parent
8f3cf2dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/search/service/spell/SearchSpellChecker.java
+16
-11
16 additions, 11 deletions
...ava/org/olat/search/service/spell/SearchSpellChecker.java
with
16 additions
and
11 deletions
src/main/java/org/olat/search/service/spell/SearchSpellChecker.java
+
16
−
11
View file @
f44f4da2
...
...
@@ -47,6 +47,7 @@ import org.apache.lucene.store.Directory;
import
org.apache.lucene.store.FSDirectory
;
import
org.olat.core.logging.OLog
;
import
org.olat.core.logging.Tracing
;
import
org.olat.core.util.FileUtils
;
import
org.olat.search.SearchService
;
import
org.olat.search.model.OlatDocument
;
...
...
@@ -102,13 +103,7 @@ public class SearchSpellChecker {
for
(
String
word
:
words
)
{
filteredList
.
add
(
word
);
}
/*
Set<String> directList = directCheck(query);
System.out.println("Direct: " + directList);
System.out.println("Filter: " + filteredList);
*/
return
filteredList
;
}
...
...
@@ -164,7 +159,7 @@ public class SearchSpellChecker {
indexReader
=
DirectoryReader
.
open
(
indexDir
);
// 1. Create content spellIndex
File
spellDictionaryFile
=
new
File
(
spellDictionaryPath
);
Directory
contentSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
CONTENT_PATH
));
//true
FS
Directory
contentSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
CONTENT_PATH
));
//true
SpellChecker
contentSpellChecker
=
new
SpellChecker
(
contentSpellIndexDirectory
);
Dictionary
contentDictionary
=
new
LuceneDictionary
(
indexReader
,
OlatDocument
.
CONTENT_FIELD_NAME
);
...
...
@@ -173,17 +168,17 @@ public class SearchSpellChecker {
contentSpellChecker
.
indexDictionary
(
contentDictionary
,
indexWriterConfig
,
true
);
// 2. Create title spellIndex
Directory
titleSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
TITLE_PATH
));
//true
FS
Directory
titleSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
TITLE_PATH
));
//true
SpellChecker
titleSpellChecker
=
new
SpellChecker
(
titleSpellIndexDirectory
);
Dictionary
titleDictionary
=
new
LuceneDictionary
(
indexReader
,
OlatDocument
.
TITLE_FIELD_NAME
);
titleSpellChecker
.
indexDictionary
(
titleDictionary
,
indexWriterConfig
,
true
);
// 3. Create description spellIndex
Directory
descriptionSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
DESCRIPTION_PATH
));
//true
FS
Directory
descriptionSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
DESCRIPTION_PATH
));
//true
SpellChecker
descriptionSpellChecker
=
new
SpellChecker
(
descriptionSpellIndexDirectory
);
Dictionary
descriptionDictionary
=
new
LuceneDictionary
(
indexReader
,
OlatDocument
.
DESCRIPTION_FIELD_NAME
);
descriptionSpellChecker
.
indexDictionary
(
descriptionDictionary
,
indexWriterConfig
,
true
);
// 4. Create author spellIndex
Directory
authorSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
AUTHOR_PATH
));
//true
FS
Directory
authorSpellIndexDirectory
=
FSDirectory
.
open
(
new
File
(
spellDictionaryPath
+
AUTHOR_PATH
));
//true
SpellChecker
authorSpellChecker
=
new
SpellChecker
(
authorSpellIndexDirectory
);
Dictionary
authorDictionary
=
new
LuceneDictionary
(
indexReader
,
OlatDocument
.
AUTHOR_FIELD_NAME
);
authorSpellChecker
.
indexDictionary
(
authorDictionary
,
indexWriterConfig
,
true
);
...
...
@@ -191,7 +186,11 @@ public class SearchSpellChecker {
// Merge all part spell indexes (content,title etc.) to one common spell index
Directory
spellIndexDirectory
=
FSDirectory
.
open
(
spellDictionaryFile
);
//true
//clean up the main index
IndexWriter
merger
=
new
IndexWriter
(
spellIndexDirectory
,
indexWriterConfig
);
merger
.
deleteAll
();
merger
.
commit
();
Directory
[]
directories
=
{
contentSpellIndexDirectory
,
titleSpellIndexDirectory
,
descriptionSpellIndexDirectory
,
authorSpellIndexDirectory
};
for
(
Directory
directory:
directories
)
{
merger
.
addIndexes
(
directory
);
...
...
@@ -203,6 +202,12 @@ public class SearchSpellChecker {
descriptionSpellChecker
.
close
();
authorSpellChecker
.
close
();
//remove all files
FileUtils
.
deleteDirsAndFiles
(
contentSpellIndexDirectory
.
getDirectory
(),
true
,
true
);
FileUtils
.
deleteDirsAndFiles
(
titleSpellIndexDirectory
.
getDirectory
(),
true
,
true
);
FileUtils
.
deleteDirsAndFiles
(
descriptionSpellIndexDirectory
.
getDirectory
(),
true
,
true
);
FileUtils
.
deleteDirsAndFiles
(
authorSpellIndexDirectory
.
getDirectory
(),
true
,
true
);
spellChecker
=
new
SpellChecker
(
spellIndexDirectory
);
spellChecker
.
setAccuracy
(
0.7f
);
if
(
log
.
isDebug
())
log
.
debug
(
"SpellIndex created in "
+
(
System
.
currentTimeMillis
()
-
startSpellIndexTime
)
+
"ms"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment