-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated beans to try to fix circular dep issue. Fixed a couple conversion issues.. because oops.
- Loading branch information
Bill Smith
committed
Aug 23, 2018
1 parent
b6105f8
commit 77b208b
Showing
5 changed files
with
66 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../main/java/edu/internet2/tier/shibboleth/admin/ui/service/EntityIdsSearchServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityIdsSearchResultRepresentation; | ||
import edu.internet2.tier.shibboleth.admin.util.LuceneUtility; | ||
import org.apache.lucene.analysis.Analyzer; | ||
import org.apache.lucene.document.Document; | ||
import org.apache.lucene.index.IndexReader; | ||
import org.apache.lucene.queryparser.classic.ParseException; | ||
import org.apache.lucene.queryparser.classic.QueryParser; | ||
import org.apache.lucene.search.IndexSearcher; | ||
import org.apache.lucene.search.ScoreDoc; | ||
import org.apache.lucene.search.TopDocs; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
public class EntityIdsSearchServiceImpl implements EntityIdsSearchService { | ||
private static final Logger logger = LoggerFactory.getLogger(EntityIdsSearchServiceImpl.class); | ||
private Analyzer fullTokenAnalyzer; | ||
private LuceneUtility luceneUtility; | ||
|
||
public EntityIdsSearchServiceImpl(LuceneUtility luceneUtility, Analyzer fullTokenAnalyzer) { | ||
this.luceneUtility = luceneUtility; | ||
this.fullTokenAnalyzer = fullTokenAnalyzer; | ||
} | ||
|
||
@Override | ||
public EntityIdsSearchResultRepresentation findBySearchTermAndOptionalLimit(String resourceId, | ||
String searchTerm, | ||
int limit) { | ||
List<String> entityIds = new ArrayList<>(); | ||
try { | ||
IndexReader indexReader = luceneUtility.getIndexReader(resourceId); | ||
IndexSearcher searcher = new IndexSearcher(indexReader); | ||
QueryParser parser = new QueryParser("content", fullTokenAnalyzer); | ||
TopDocs topDocs = searcher.search(parser.parse(searchTerm.trim()), limit); | ||
for (ScoreDoc scoreDoc : topDocs.scoreDocs) { | ||
Document document = searcher.doc(scoreDoc.doc); | ||
entityIds.add(document.get("id")); | ||
} | ||
} catch (IOException | ParseException e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
return new EntityIdsSearchResultRepresentation(entityIds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters