1 |
|
---|
2 | package org.nzdl.gsdl.service;
|
---|
3 |
|
---|
4 | import java.util.*;
|
---|
5 |
|
---|
6 | public class NzdlResultSet extends java.lang.Object {
|
---|
7 |
|
---|
8 | private List m_resultSet = null;
|
---|
9 | private int m_numDocs = -1;
|
---|
10 | private int m_resultType = -1;
|
---|
11 | private List m_queryTerms = null;
|
---|
12 | private List m_docIDs = null;
|
---|
13 | /** the key is the query term, the value its frequency */
|
---|
14 | private Map m_frequencies = null;
|
---|
15 | /**
|
---|
16 | * the key is the docID, the value is the doc corresponding
|
---|
17 | * meta data which is also a Map where the key is the meta tag
|
---|
18 | * and the value is a set of values for that tag
|
---|
19 | */
|
---|
20 | private Map m_docToMetaDataMap = null;
|
---|
21 |
|
---|
22 | /** */
|
---|
23 |
|
---|
24 | public NzdlResultSet() {
|
---|
25 | m_resultSet = new ArrayList();
|
---|
26 | m_docToMetaDataMap = new HashMap();
|
---|
27 | m_docIDs = new ArrayList();
|
---|
28 | }
|
---|
29 |
|
---|
30 | /** */
|
---|
31 |
|
---|
32 | public void add( NzdlQueryHit _hit ) {
|
---|
33 | m_resultSet.add( _hit ) ;
|
---|
34 | String id = _hit.getDocumentID();
|
---|
35 | m_docIDs.add( id );
|
---|
36 | m_docToMetaDataMap.put( id, _hit.getMetaData() );
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void setNumOfDocs( int _num ) {
|
---|
40 | m_numDocs = _num;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void setResultType( int _type ) {
|
---|
44 | m_resultType = _type;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void setQueryTerms( List _terms ) {
|
---|
48 | m_queryTerms = _terms;
|
---|
49 | }
|
---|
50 |
|
---|
51 | // public void setTermFrequency( String _term, int _freq ) {
|
---|
52 | // m_frequencies.put( _term, new Integer(_freq) );
|
---|
53 | // }
|
---|
54 |
|
---|
55 | public void setTermFrequencies( Map _freqs ) {
|
---|
56 | m_frequencies = _freqs;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /** */
|
---|
60 |
|
---|
61 | public int getNumOfDocs() {
|
---|
62 | return m_numDocs;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public int getResultType() {
|
---|
66 | return m_resultType;
|
---|
67 | }
|
---|
68 |
|
---|
69 | public List getQueryTerms() {
|
---|
70 | return m_queryTerms;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public Map getTermFrequencies() {
|
---|
74 | return m_frequencies;
|
---|
75 | }
|
---|
76 |
|
---|
77 | // public int getTermFrequency( String _term ) {
|
---|
78 | // return ((Integer)m_frequencies.get(_term)).intValue();
|
---|
79 | // }
|
---|
80 |
|
---|
81 | // public List getDocumentIDs() {
|
---|
82 | // NzdlQueryHit hit = null;
|
---|
83 | // //Set docIDs = new HashSet();
|
---|
84 | // List docIDs = new ArrayList();
|
---|
85 | // for (ListIterator itr = m_resultSet.listIterator(); itr.hasNext(); ) {
|
---|
86 | // hit = (NzdlQueryHit) itr.next();
|
---|
87 | // docIDs.add( hit.getDocumentID() );
|
---|
88 | // }
|
---|
89 | // return docIDs;
|
---|
90 | // }
|
---|
91 |
|
---|
92 | public List getDocumentIDs() {
|
---|
93 | return m_docIDs;
|
---|
94 | }
|
---|
95 |
|
---|
96 | // public Set getMetaData( String _docID, String _metaTag ) {
|
---|
97 | // NzdlQueryHit hit = null;
|
---|
98 | // for (ListIterator itr = m_resultSet.listIterator(); itr.hasNext(); ) {
|
---|
99 | // hit = (NzdlQueryHit) itr.next();
|
---|
100 | // if ( _docID.equals( hit.getDocumentID() ) ) {
|
---|
101 | // return hit.getMetaDataValues( _metaTag );
|
---|
102 | // }
|
---|
103 | // }
|
---|
104 | // return null;
|
---|
105 | // }
|
---|
106 |
|
---|
107 | public Set getMetaData( String _docID, String _metaTag ) {
|
---|
108 | Map metaData = (Map) m_docToMetaDataMap.get( _docID );
|
---|
109 | return (Set) metaData.get( _metaTag );
|
---|
110 | }
|
---|
111 |
|
---|
112 | public Map getMetaData( String _metaTag ) {
|
---|
113 | Map metaData = new HashMap();
|
---|
114 | for (ListIterator itr = m_resultSet.listIterator(); itr.hasNext(); ) {
|
---|
115 | NzdlQueryHit hit = (NzdlQueryHit) itr.next();
|
---|
116 | metaData.put( hit.getDocumentID(), hit.getMetaDataValues(_metaTag) );
|
---|
117 | }
|
---|
118 | return metaData;
|
---|
119 | }
|
---|
120 |
|
---|
121 | public Map getAllMetaData( ) {
|
---|
122 | return m_docToMetaDataMap;
|
---|
123 | }
|
---|
124 |
|
---|
125 | }
|
---|