01: /**
02: * LibreSource
03: * Copyright (C) 2004-2008 Artenum SARL / INRIA
04: * http://www.libresource.org - contact@artenum.com
05: *
06: * This file is part of the LibreSource software,
07: * which can be used and distributed under license conditions.
08: * The license conditions are provided in the LICENSE.TXT file
09: * at the root path of the packaging that enclose this file.
10: * More information can be found at
11: * - http://dev.libresource.org/home/license
12: *
13: * Initial authors :
14: *
15: * Guillaume Bort / INRIA
16: * Francois Charoy / Universite Nancy 2
17: * Julien Forest / Artenum
18: * Claude Godart / Universite Henry Poincare
19: * Florent Jouille / INRIA
20: * Sebastien Jourdain / INRIA / Artenum
21: * Yves Lerumeur / Artenum
22: * Pascal Molli / Universite Henry Poincare
23: * Gerald Oster / INRIA
24: * Mariarosa Penzi / Artenum
25: * Gerard Sookahet / Artenum
26: * Raphael Tani / INRIA
27: *
28: * Contributors :
29: *
30: * Stephane Bagnier / Artenum
31: * Amadou Dia / Artenum-IUP Blois
32: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33: */package org.libresource.search;
34:
35: import org.apache.lucene.document.Document;
36: import org.apache.lucene.index.IndexReader;
37: import org.apache.lucene.search.Filter;
38:
39: import java.io.IOException;
40:
41: import java.util.BitSet;
42:
43: public class LibresourceQueryFilter extends Filter {
44: private String uriPattern;
45: private String resourceType;
46: private String serviceName;
47:
48: public LibresourceQueryFilter(String uriPattern,
49: String resourceType, String serviceName) {
50: this .uriPattern = uriPattern.replaceAll("\\*", ".*");
51: this .resourceType = resourceType;
52: this .serviceName = serviceName;
53: }
54:
55: public BitSet bits(IndexReader reader) throws IOException {
56: BitSet bits = new BitSet(reader.maxDoc());
57:
58: for (int i = 0; i < reader.maxDoc(); i++) {
59: Document doc = reader.document(i);
60: boolean uriMatch = true;
61: boolean typeMatch = true;
62: boolean serviceMatch = true;
63:
64: if (uriPattern != null) {
65: if (!doc.getValues("URI")[0].matches(uriPattern)) {
66: uriMatch = false;
67: }
68: }
69:
70: if (resourceType != null) {
71: if (!doc.getValues("TYPE")[0].equals(resourceType)) {
72: typeMatch = false;
73: }
74: }
75:
76: if (uriMatch && typeMatch && serviceMatch) {
77: bits.set(i);
78: }
79: }
80:
81: return bits;
82: }
83:
84: public String toString() {
85: return "LibresourceQueryFilter";
86: }
87: }
|