Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
digibib
ls.ext
Commits
cdddb73a
Commit
cdddb73a
authored
May 24, 2018
by
Veronika Heimsbakk
Committed by
Magnus Westergaard
Sep 10, 2018
Browse files
removed indexing to a and b
parent
c3ca2932
Changes
1
Hide whitespace changes
Inline
Side-by-side
redef/services/src/main/java/no/deichman/services/search/SearchServiceImpl.java
View file @
cdddb73a
...
...
@@ -95,6 +95,8 @@ public class SearchServiceImpl implements SearchService {
SIXTY
,
TimeUnit
.
SECONDS
,
INDEX_QUEUE
);
private
static
final
String
INDEX_NAME
=
"search"
;
private
static
Map
<
EntityType
,
NameIndexer
>
nameIndexers
=
new
HashMap
<
EntityType
,
NameIndexer
>();
public
SearchServiceImpl
(
String
elasticSearchBaseUrl
,
EntityService
entityService
)
{
...
...
@@ -198,9 +200,7 @@ public class SearchServiceImpl implements SearchService {
@Override
public
final
Response
clearIndex
()
{
clearIndex
(
"a"
);
clearIndex
(
"b"
);
toggleActiveIndex
(
"a"
);
clearIndex
(
INDEX_NAME
);
return
Response
.
status
(
Response
.
Status
.
OK
).
build
();
}
...
...
@@ -340,31 +340,6 @@ public class SearchServiceImpl implements SearchService {
}
}
private
String
getActiveIndex
()
{
// Check if index A is aliased to 'search'
try
(
CloseableHttpClient
httpclient
=
createDefault
())
{
URI
uri
=
getIndexUriBuilder
().
setPath
(
"/a/_alias/search"
).
build
();
try
(
CloseableHttpResponse
res
=
httpclient
.
execute
(
new
HttpGet
(
uri
)))
{
if
(
EntityUtils
.
toString
(
res
.
getEntity
()).
contains
(
"search"
))
{
return
"a"
;
}
}
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
throw
new
ServerErrorException
(
e
.
getMessage
(),
INTERNAL_SERVER_ERROR
);
}
// Index A is not aliased to 'search', so it must be index B
return
"b"
;
}
private
String
getInactiveIndex
()
{
if
(
getActiveIndex
().
equals
(
"a"
))
{
return
"b"
;
}
else
{
return
"a"
;
}
}
private
Response
searchWithJson
(
String
body
,
URIBuilder
searchUriBuilder
,
Function
<
String
,
String
>...
jsonTranformer
)
{
try
{
HttpPost
httpPost
=
new
HttpPost
(
searchUriBuilder
.
build
());
...
...
@@ -625,45 +600,42 @@ public class SearchServiceImpl implements SearchService {
@Override
public
final
void
enqueueIndexingAllResources
()
{
THREADPOOL
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
String
newIndex
=
getInactiveIndex
();
clearIndex
(
newIndex
);
for
(
EntityType
type
:
EntityType
.
values
())
{
if
(
type
.
equals
(
EntityType
.
PUBLICATION
))
{
// Publications are indexed when the work they belong to are indexed
continue
;
}
entityService
.
retrieveAllWorkUris
(
type
.
getPath
(),
uri
->
EXECUTOR_SERVICE
.
execute
(()
->
{
try
{
XURI
resource
=
new
XURI
(
uri
);
if
(
resource
.
getTypeAsEntityType
().
equals
(
EntityType
.
WORK
))
{
indexWorkAndPublications
(
newIndex
,
resource
);
}
else
{
indexOnly
(
newIndex
,
resource
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}));
THREADPOOL
.
execute
(()
->
{
String
newIndex
=
INDEX_NAME
;
clearIndex
();
for
(
EntityType
type
:
EntityType
.
values
())
{
if
(
type
.
equals
(
EntityType
.
PUBLICATION
))
{
// Publications are indexed when the work they belong to are indexed
continue
;
}
while
(
true
)
{
entityService
.
retrieveAllWorkUris
(
type
.
getPath
(),
uri
->
EXECUTOR_SERVICE
.
execute
(()
->
{
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
// no-op
}
if
(
INDEX_QUEUE
.
size
()
==
0
)
{
break
;
XURI
resource
=
new
XURI
(
uri
);
if
(
resource
.
getTypeAsEntityType
().
equals
(
EntityType
.
WORK
))
{
indexWorkAndPublications
(
newIndex
,
resource
);
}
else
{
indexOnly
(
newIndex
,
resource
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}));
}
LOG
.
info
(
"Done indexing all resources - setting active index: "
+
newIndex
);
toggleActiveIndex
(
newIndex
);
while
(
true
)
{
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
// no-op
}
if
(
INDEX_QUEUE
.
size
()
==
0
)
{
break
;
}
}
LOG
.
info
(
"Done indexing all resources - setting active index: "
+
newIndex
);
toggleActiveIndex
(
newIndex
);
});
}
...
...
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