1 17 package org.alfresco.repo.search.impl.lucene; 18 19 import java.io.IOException ; 20 21 import org.alfresco.repo.search.AbstractResultSet; 22 import org.alfresco.repo.search.ResultSetRowIterator; 23 import org.alfresco.repo.search.SearcherException; 24 import org.alfresco.repo.search.SimpleResultSetMetaData; 25 import org.alfresco.service.cmr.repository.ChildAssociationRef; 26 import org.alfresco.service.cmr.repository.NodeRef; 27 import org.alfresco.service.cmr.repository.NodeService; 28 import org.alfresco.service.cmr.repository.Path; 29 import org.alfresco.service.cmr.search.LimitBy; 30 import org.alfresco.service.cmr.search.PermissionEvaluationMode; 31 import org.alfresco.service.cmr.search.ResultSetMetaData; 32 import org.alfresco.service.cmr.search.ResultSetRow; 33 import org.alfresco.service.cmr.search.SearchParameters; 34 import org.apache.lucene.document.Document; 35 import org.apache.lucene.search.Hits; 36 import org.apache.lucene.search.Searcher; 37 38 44 public class LuceneResultSet extends AbstractResultSet 45 { 46 49 Hits hits; 50 51 private Searcher searcher; 52 53 private NodeService nodeService; 54 55 SearchParameters searchParameters; 56 57 63 public LuceneResultSet(Hits hits, Searcher searcher, NodeService nodeService, Path[]propertyPaths, SearchParameters searchParameters) 64 { 65 super(propertyPaths); 66 this.hits = hits; 67 this.searcher = searcher; 68 this.nodeService = nodeService; 69 this.searchParameters = searchParameters; 70 } 71 72 75 76 public ResultSetRowIterator iterator() 77 { 78 return new LuceneResultSetRowIterator(this); 79 } 80 81 public int length() 82 { 83 return hits.length(); 84 } 85 86 public NodeRef getNodeRef(int n) 87 { 88 try 89 { 90 Document doc = hits.doc(n); 93 String id = doc.get("ID"); 94 return new NodeRef(id); 95 } 96 catch (IOException e) 97 { 98 throw new SearcherException("IO Error reading reading node ref from the result set", e); 99 } 100 } 101 102 public float getScore(int n) throws SearcherException 103 { 104 try 105 { 106 return hits.score(n); 107 } 108 catch (IOException e) 109 { 110 throw new SearcherException("IO Error reading score from the result set", e); 111 } 112 } 113 114 public Document getDocument(int n) 115 { 116 try 117 { 118 Document doc = hits.doc(n); 119 return doc; 120 } 121 catch (IOException e) 122 { 123 throw new SearcherException("IO Error reading reading document from the result set", e); 124 } 125 } 126 127 public void close() 128 { 129 try 130 { 131 searcher.close(); 132 } 133 catch (IOException e) 134 { 135 throw new SearcherException(e); 136 } 137 } 138 139 public NodeService getNodeService() 140 { 141 return nodeService; 142 } 143 144 public ResultSetRow getRow(int i) 145 { 146 if(i < length()) 147 { 148 return new LuceneResultSetRow(this, i); 149 } 150 else 151 { 152 throw new SearcherException("Invalid row"); 153 } 154 } 155 156 public ChildAssociationRef getChildAssocRef(int n) 157 { 158 return getRow(n).getChildAssocRef(); 159 } 160 161 162 public ResultSetMetaData getResultSetMetaData() 163 { 164 return new SimpleResultSetMetaData(LimitBy.UNLIMITED, PermissionEvaluationMode.EAGER, searchParameters); 165 } 166 } 167 | Popular Tags |