001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.lucefix;
021:
022: import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
023: import org.apache.lucene.analysis.WhitespaceAnalyzer;
024: import org.apache.lucene.analysis.standard.StandardAnalyzer;
025: import org.apache.lucene.document.DateField;
026: import org.apache.lucene.document.Document;
027: import org.apache.lucene.document.Field;
028:
029: public class PreDoc {
030:
031: public static final String ATTRIBVALUES = "attribvalues";
032: public static final String ATTRIBKEYS = "attribkeys";
033: public static final String TAGS = "tags";
034: public static final String COMMENTS = "comments";
035: public static final String CONTENTS = "contents";
036: public static final String LASTTOUCH = "lasttouch";
037: public static final String PATH = "path";
038: public static final String FILENAME = "file";
039: public static final PerFieldAnalyzerWrapper ANALYZER = new PerFieldAnalyzerWrapper(
040: new StandardAnalyzer());
041: static {
042: ANALYZER.addAnalyzer(TAGS, new WhitespaceAnalyzer());
043: ANALYZER.addAnalyzer(COMMENTS, new WhitespaceAnalyzer());
044: ANALYZER.addAnalyzer(ATTRIBKEYS, new WhitespaceAnalyzer());
045: ANALYZER.addAnalyzer(ATTRIBVALUES, new WhitespaceAnalyzer());
046: ANALYZER.addAnalyzer(CONTENTS, new StandardAnalyzer());
047: }
048:
049: public String toString() {
050: return this .getClass() + "\n\tFilename: " + filename
051: + "\n\tPath: " + path + "\n\tLasttouch: " + lasttouch
052: + "\n\tcomments: " + comments + "\n\ttags: " + tags
053: + "\n\tattribKeys: " + attribKeys
054: + "\n\tattribValues: " + attribValues + "\n\tcontent: "
055: + content;
056: }
057:
058: /**
059: * @return
060: */
061: public Document toLuceneDocument() {
062: Document doc = new Document();
063: doc.add(Field.Keyword(PATH, path));
064: doc.add(Field.Keyword(FILENAME, filename));
065: doc.add(Field.Keyword(LASTTOUCH, DateField
066: .timeToString(lasttouch)));
067:
068: doc.add(Field.Text(CONTENTS, content.toString()));
069: doc.add(Field.Text(COMMENTS, comments.toString()));
070: doc.add(Field.Text(TAGS, tags.toString()));
071: doc.add(Field.Text(ATTRIBKEYS, attribKeys.toString()));
072: doc.add(Field.Text(ATTRIBVALUES, attribValues.toString()));
073: return doc;
074: }
075:
076: public PreDoc(String filename, String partname, String productname,
077: long lasttouch) {
078: this .lasttouch = lasttouch;
079: this .filename = filename;
080: this .path = filename + "/" + partname + "/" + productname;
081: }
082:
083: private String path;
084: private String filename;
085: private long lasttouch;
086: private StringBuffer comments = new StringBuffer();
087: private StringBuffer tags = new StringBuffer();
088: private StringBuffer attribKeys = new StringBuffer();
089: private StringBuffer attribValues = new StringBuffer();
090: private StringBuffer content = new StringBuffer();
091:
092: void addComment(String newcomment) {
093: if (comments.length() != 0)
094: comments.append(' ');
095: comments.append(newcomment);
096: }
097:
098: void addComment(char newchar) {
099: comments.append(newchar);
100: }
101:
102: void addTag(String newtag) {
103: if (tags.length() != 0)
104: tags.append(' ');
105: tags.append(newtag);
106: }
107:
108: void addAttribKey(String newattribkey) {
109: if (attribKeys.length() != 0)
110: attribKeys.append(' ');
111: attribKeys.append(newattribkey);
112: }
113:
114: void addAttribValue(String newattribvalue) {
115: if (attribValues.length() != 0)
116: attribValues.append(' ');
117: attribValues.append(newattribvalue);
118: }
119:
120: void addContent(String newcontent) {
121: if (content.length() != 0)
122: content.append(' ');
123: content.append(newcontent);
124: }
125:
126: void addContent(char charc) {
127: content.append(charc);
128: }
129:
130: public StringBuffer getAttribKeys() {
131: return attribKeys;
132: }
133:
134: public void setAttribKeys(StringBuffer attribKeys) {
135: this .attribKeys = attribKeys;
136: }
137:
138: public StringBuffer getAttribValues() {
139: return attribValues;
140: }
141:
142: public void setAttribValues(StringBuffer attribValues) {
143: this .attribValues = attribValues;
144: }
145:
146: public StringBuffer getComments() {
147: return comments;
148: }
149:
150: public void setComments(StringBuffer comments) {
151: this .comments = comments;
152: }
153:
154: public StringBuffer getContent() {
155: return content;
156: }
157:
158: public void setContent(StringBuffer content) {
159: this .content = content;
160: }
161:
162: public StringBuffer getTags() {
163: return tags;
164: }
165:
166: public void setTags(StringBuffer tags) {
167: this.tags = tags;
168: }
169: }
|