Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Fess Search engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
Fess Search engine
Commits
c811b54c
Commit
c811b54c
authored
Aug 17, 2017
by
Shinsuke Sugaya
Browse files
Options
Downloads
Patches
Plain Diff
fix #1230 related content supports java regex
parent
a2a144b7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/codelibs/fess/helper/RelatedContentHelper.java
+43
-10
43 additions, 10 deletions
...n/java/org/codelibs/fess/helper/RelatedContentHelper.java
with
43 additions
and
10 deletions
src/main/java/org/codelibs/fess/helper/RelatedContentHelper.java
+
43
−
10
View file @
c811b54c
...
@@ -15,23 +15,34 @@
...
@@ -15,23 +15,34 @@
*/
*/
package
org.codelibs.fess.helper
;
package
org.codelibs.fess.helper
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
org.codelibs.core.lang.StringUtil
;
import
org.codelibs.core.lang.StringUtil
;
import
org.codelibs.core.misc.Pair
;
import
org.codelibs.fess.es.config.exbhv.RelatedContentBhv
;
import
org.codelibs.fess.es.config.exbhv.RelatedContentBhv
;
import
org.codelibs.fess.es.config.exentity.RelatedContent
;
import
org.codelibs.fess.es.config.exentity.RelatedContent
;
import
org.codelibs.fess.mylasta.direction.FessConfig
;
import
org.codelibs.fess.mylasta.direction.FessConfig
;
import
org.codelibs.fess.util.ComponentUtil
;
import
org.codelibs.fess.util.ComponentUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
RelatedContentHelper
{
public
class
RelatedContentHelper
{
protected
volatile
Map
<
String
,
Map
<
String
,
String
>>
relatedContentMap
=
Collections
.
emptyMap
();
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RelatedContentHelper
.
class
);
protected
volatile
Map
<
String
,
Pair
<
Map
<
String
,
String
>,
List
<
Pair
<
Pattern
,
String
>>>>
relatedContentMap
=
Collections
.
emptyMap
();
protected
String
regexPrefix
=
"regex:"
;
protected
String
queryPlaceHolder
=
"__QUERY__"
;
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
...
@@ -52,15 +63,24 @@ public class RelatedContentHelper {
...
@@ -52,15 +63,24 @@ public class RelatedContentHelper {
}
}
protected
void
reload
()
{
protected
void
reload
()
{
final
Map
<
String
,
Map
<
String
,
String
>>
relatedContentMap
=
new
HashMap
<>();
final
Map
<
String
,
Pair
<
Map
<
String
,
String
>
,
List
<
Pair
<
Pattern
,
String
>>>
>
relatedContentMap
=
new
HashMap
<>();
getAvailableRelatedContentList
().
stream
().
forEach
(
entity
->
{
getAvailableRelatedContentList
().
stream
().
forEach
(
entity
->
{
final
String
key
=
getHostKey
(
entity
);
final
String
key
=
getHostKey
(
entity
);
Map
<
String
,
String
>
map
=
relatedContentMap
.
get
(
key
);
Pair
<
Map
<
String
,
String
>,
List
<
Pair
<
Pattern
,
String
>>>
pair
=
relatedContentMap
.
get
(
key
);
if
(
map
==
null
)
{
if
(
pair
==
null
)
{
map
=
new
HashMap
<>();
pair
=
new
Pair
<>(
new
HashMap
<>(),
new
ArrayList
<>());
relatedContentMap
.
put
(
key
,
map
);
relatedContentMap
.
put
(
key
,
pair
);
}
if
(
entity
.
getTerm
().
startsWith
(
regexPrefix
))
{
String
regex
=
entity
.
getTerm
().
substring
(
regexPrefix
.
length
());
if
(
StringUtil
.
isBlank
(
regex
))
{
logger
.
warn
(
"Unknown regex pattern: "
+
entity
.
getTerm
());
}
else
{
pair
.
getSecond
().
add
(
new
Pair
<>(
Pattern
.
compile
(
regex
),
entity
.
getContent
()));
}
}
else
{
pair
.
getFirst
().
put
(
toLowerCase
(
entity
.
getTerm
()),
entity
.
getContent
());
}
}
map
.
put
(
toLowerCase
(
entity
.
getTerm
()),
entity
.
getContent
());
});
});
this
.
relatedContentMap
=
relatedContentMap
;
this
.
relatedContentMap
=
relatedContentMap
;
}
}
...
@@ -73,12 +93,17 @@ public class RelatedContentHelper {
...
@@ -73,12 +93,17 @@ public class RelatedContentHelper {
public
String
getRelatedContent
(
final
String
query
)
{
public
String
getRelatedContent
(
final
String
query
)
{
final
FessConfig
fessConfig
=
ComponentUtil
.
getFessConfig
();
final
FessConfig
fessConfig
=
ComponentUtil
.
getFessConfig
();
final
String
key
=
fessConfig
.
getVirtualHostKey
();
final
String
key
=
fessConfig
.
getVirtualHostKey
();
final
Map
<
String
,
String
>
map
=
relatedContentMap
.
get
(
key
);
final
Pair
<
Map
<
String
,
String
>
,
List
<
Pair
<
Pattern
,
String
>>>
pair
=
relatedContentMap
.
get
(
key
);
if
(
map
!=
null
)
{
if
(
pair
!=
null
)
{
final
String
content
=
map
.
get
(
toLowerCase
(
query
));
final
String
content
=
pair
.
getFirst
()
.
get
(
toLowerCase
(
query
));
if
(
StringUtil
.
isNotBlank
(
content
))
{
if
(
StringUtil
.
isNotBlank
(
content
))
{
return
content
;
return
content
;
}
}
for
(
final
Pair
<
Pattern
,
String
>
regexData
:
pair
.
getSecond
())
{
if
(
regexData
.
getFirst
().
matcher
(
query
).
matches
())
{
return
regexData
.
getSecond
().
replace
(
queryPlaceHolder
,
query
);
}
}
}
}
return
StringUtil
.
EMPTY
;
return
StringUtil
.
EMPTY
;
}
}
...
@@ -87,4 +112,12 @@ public class RelatedContentHelper {
...
@@ -87,4 +112,12 @@ public class RelatedContentHelper {
return
term
!=
null
?
term
.
toLowerCase
(
Locale
.
ROOT
)
:
term
;
return
term
!=
null
?
term
.
toLowerCase
(
Locale
.
ROOT
)
:
term
;
}
}
public
void
setRegexPrefix
(
String
regexPrefix
)
{
this
.
regexPrefix
=
regexPrefix
;
}
public
void
setQueryPlaceHolder
(
String
queryPlaceHolder
)
{
this
.
queryPlaceHolder
=
queryPlaceHolder
;
}
}
}
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