- /**
- * {@inheritDoc}
- *
- * @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.dal.bo.som.KnowledgeElement.Properties[])
- */
- @Deprecated
- public List<Proxy> selectKnowledgeElementsWhere(
- final KnowledgeElement.Properties... kprop) {
- List<Proxy> result = new ArrayList<Proxy>();
- int hitsize = 20;
- try {
-
- // Creation of the Lucene query
- File indir = getRepositoryService().getRepositoryIndexDirectory();
- Directory index = FSDirectory.open(indir);
- IndexSearcher searcher = new IndexSearcher(index, true);
- BooleanQuery fulquery = new BooleanQuery();
-
- for (int i = 0; i < kprop.length; i++) {
- BooleanQuery query = new BooleanQuery();
- Term input; // Supposed initialized below at least by the visibility
-
- Visibility area = kprop[i].getVisibility(); // Visibility
- if (area != null) {
- input = new Term("area");
- query.add(new TermQuery(input.createTerm(area.toString())),
- BooleanClause.Occur.MUST);
- }
- ProgressState state = kprop[i].getProgressState(); // State
- if (state != null) {
- input = new Term("state");
- query.add(
- new TermQuery(input.createTerm(state.toString())),
- BooleanClause.Occur.MUST);
- }
- String refid = kprop[i].getReference(); // Reference
- if (refid != null) {
- input = new Term("ref");
- query.add(new TermQuery(input.createTerm(refid)),
- BooleanClause.Occur.MUST);
- }
- KnowledgeElementType type = kprop[i].getType(); // Type
- if (type != null) {
- input = new Term("type");
- query.add(new TermQuery(input.createTerm(type.getName())),
- BooleanClause.Occur.MUST);
- }
- User manager = kprop[i].getAuthor(); // Author
- if (manager != null) {
- input = new Term("author");
- query.add(new TermQuery(input
- .createTerm(manager.toString())),
- BooleanClause.Occur.MUST);
- }
- User actor = kprop[i].getActor(); // Contributor, Reviewer or Approver of the owner study
- if (actor != null) {
- input = new Term("actor");
- query.add(
- new TermQuery(input.createTerm(actor.toString())),
- BooleanClause.Occur.MUST);
- }
- String title = kprop[i].getTitle(); // Title
- if (title != null) {
- input = new Term("contents");
- BooleanQuery critext = new BooleanQuery();
- String operator = "AND"; // Future user input
- BooleanClause.Occur clause = BooleanClause.Occur.MUST;
- if (operator.equals("OR")) {
- clause = BooleanClause.Occur.SHOULD;
- }
- String[] word = title.split(" ");
- for (int j = 0; j < word.length; j++) {
- critext.add(new TermQuery(input.createTerm(word[j])),
- clause);
- }
- query.add(critext, BooleanClause.Occur.MUST);
- }
- List<SimulationContext> context = kprop[i]
- .getSimulationContexts();
- if (context != null && context.size() > 0) {
- BooleanQuery critext = new BooleanQuery();
- for (Iterator<SimulationContext> j = context.iterator(); j
- .hasNext();) {
- SimulationContext seltext = j.next();
- input = new Term(String.valueOf(seltext.getType()
- .getIndex()));
- critext.add(new TermQuery(input.createTerm(seltext
- .getValue())), BooleanClause.Occur.MUST);
- }
- query.add(critext, BooleanClause.Occur.MUST);
- }
- fulquery.add(query, BooleanClause.Occur.SHOULD);
- }
- if (LOG.isInfoEnabled()) {
- LOG.info("Searching knowledges by Lucene query \""
- + fulquery.toString());
- }
- // Creation of the knowledge filter
- BooleanFilter filter = new BooleanFilter();
- TermsFilter select = new TermsFilter();
- Term mytype = new Term("class");
- select.addTerm(mytype.createTerm("KnowledgeElement"));
- filter.add(new FilterClause(select, BooleanClause.Occur.SHOULD));
-
- // Creation of the sort criteria
- Sort sort = new Sort(new SortField("title", SortField.STRING));
-
- // Search
- TopFieldDocs found = searcher.search(fulquery, filter, hitsize,
- sort);
-
- if (found.totalHits < 1) {
- return result; // No study found
- }
-
- // Construction of the result list
- ScoreDoc[] hits = found.scoreDocs;
- for (int i = 0; i < hits.length; i++) {
- result.add(new IndexServiceImpl.ObjectProxy(searcher
- .doc(hits[i].doc)));
- }
- searcher.close();
- } catch (Exception error) {
- LOG.error("Error during Lucene search, reason:", error);
- }
- return result;
- }
-