"
24 | *
25 | */
26 | public abstract class ShortFacetIterator extends FacetIterator
27 | {
28 | public short facet;
29 | public abstract short nextShort();
30 | public abstract short nextShort(int minHits);
31 | public abstract String format(short val);
32 | }
33 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/docidset/BitsetDocSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.docidset;
21 |
22 | import java.io.IOException;
23 | import java.util.BitSet;
24 |
25 | import org.apache.lucene.search.DocIdSet;
26 | import org.apache.lucene.search.DocIdSetIterator;
27 |
28 | public class BitsetDocSet extends DocIdSet {
29 | private final BitSet _bs;
30 | public BitsetDocSet() {
31 | _bs=new BitSet();
32 | }
33 |
34 | public BitsetDocSet(int nbits) {
35 | _bs=new BitSet(nbits);
36 | }
37 |
38 | public void addDoc(int docid) {
39 | _bs.set(docid);
40 | }
41 |
42 | public int size() {
43 | return _bs.cardinality();
44 | }
45 |
46 | @Override
47 | public DocIdSetIterator iterator() {
48 | return new BitsDocIdSetIterator(_bs);
49 | }
50 |
51 | private static class BitsDocIdSetIterator extends DocIdSetIterator
52 | {
53 | private final BitSet _bs;
54 | private int _current;
55 | BitsDocIdSetIterator(BitSet bs)
56 | {
57 | _bs=bs;
58 | _current=-1;
59 | }
60 |
61 | @Override
62 | public int docID() {
63 | return _current;
64 | }
65 |
66 | @Override
67 | public int nextDoc() throws IOException {
68 | return _bs.nextSetBit(_current+1);
69 | }
70 |
71 | @Override
72 | public int advance(int target) throws IOException {
73 | return _bs.nextSetBit(target);
74 | }
75 |
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/docidset/EmptyDocIdSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.docidset;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.search.DocIdSetIterator;
25 |
26 |
27 | public final class EmptyDocIdSet extends RandomAccessDocIdSet
28 | {
29 | private static EmptyDocIdSet SINGLETON=new EmptyDocIdSet();
30 |
31 | private static class EmptyDocIdSetIterator extends DocIdSetIterator
32 | {
33 | @Override
34 | public int docID() { return -1; }
35 |
36 | @Override
37 | public int nextDoc() throws IOException { return DocIdSetIterator.NO_MORE_DOCS; }
38 |
39 | @Override
40 | public int advance(int target) throws IOException {return DocIdSetIterator.NO_MORE_DOCS; }
41 | }
42 |
43 | private static EmptyDocIdSetIterator SINGLETON_ITERATOR = new EmptyDocIdSetIterator();
44 |
45 | private EmptyDocIdSet() { }
46 |
47 | public static EmptyDocIdSet getInstance()
48 | {
49 | return SINGLETON;
50 | }
51 |
52 | @Override
53 | public DocIdSetIterator iterator()
54 | {
55 | return SINGLETON_ITERATOR;
56 | }
57 |
58 | @Override
59 | public boolean get(int docId)
60 | {
61 | return false;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/docidset/FilteredDocSetIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.docidset;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.search.DocIdSetIterator;
25 |
26 |
27 | public abstract class FilteredDocSetIterator extends DocIdSetIterator {
28 | protected DocIdSetIterator _innerIter;
29 | private int _currentDoc;
30 |
31 | public FilteredDocSetIterator(DocIdSetIterator innerIter)
32 | {
33 | if (innerIter == null)
34 | {
35 | throw new IllegalArgumentException("null iterator");
36 | }
37 | _innerIter=innerIter;
38 | _currentDoc=-1;
39 | }
40 |
41 | abstract protected boolean match(int doc);
42 |
43 | public final int docID() {
44 | return _currentDoc;
45 | }
46 |
47 | public final int nextDoc() throws IOException{
48 | int docid = _innerIter.nextDoc();
49 | while(docid!=DocIdSetIterator.NO_MORE_DOCS)
50 | {
51 | if (match(docid))
52 | {
53 | _currentDoc=docid;
54 | return docid;
55 | }
56 | else{
57 | docid = _innerIter.nextDoc();
58 | }
59 | }
60 | return DocIdSetIterator.NO_MORE_DOCS;
61 | }
62 |
63 | public final int advance(int n) throws IOException{
64 | int docid =_innerIter.advance(n);
65 | while (docid!=DocIdSetIterator.NO_MORE_DOCS)
66 | {
67 | if (match(docid))
68 | {
69 | _currentDoc=docid;
70 | return docid;
71 | }
72 | else
73 | {
74 | docid=_innerIter.nextDoc();
75 | }
76 | }
77 | return DocIdSetIterator.NO_MORE_DOCS;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/docidset/RandomAccessDocIdSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.docidset;
21 |
22 | import org.apache.lucene.search.DocIdSet;
23 |
24 | public abstract class RandomAccessDocIdSet extends DocIdSet
25 | {
26 | public abstract boolean get(int docId);
27 | }
28 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/AbstractRuntimeFacetHandlerFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets;
21 |
22 |
23 | public abstract class AbstractRuntimeFacetHandlerFactory> implements
24 | RuntimeFacetHandlerFactory
{
25 | /**
26 | * @return if this facet support empty params or not. By default it returns
27 | * false.
28 | */
29 | @Override
30 | public boolean isLoadLazily()
31 | {
32 | return false;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/FacetCountCollector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets;
21 |
22 | import java.util.LinkedList;
23 | import java.util.List;
24 |
25 | import com.browseengine.bobo.api.BrowseFacet;
26 | import com.browseengine.bobo.api.FacetAccessible;
27 | import com.browseengine.bobo.util.BigSegmentedArray;
28 |
29 | /**
30 | * Collects facet counts for a given browse request
31 | */
32 | public interface FacetCountCollector extends FacetAccessible
33 | {
34 | /**
35 | * Collect a hit. This is called for every hit, thus the implementation needs to be super-optimized.
36 | * @param docid doc
37 | */
38 | void collect(int docid);
39 |
40 | /**
41 | * Collects all hits. This is called once per request by the facet engine in certain scenarios.
42 | */
43 | void collectAll();
44 |
45 | /**
46 | * Gets the name of the facet
47 | * @return facet name
48 | */
49 | String getName();
50 |
51 | /**
52 | * Returns an integer array representing the distribution function of a given facet.
53 | * @return integer array of count values representing distribution of the facet values.
54 | */
55 | BigSegmentedArray getCountDistribution();
56 |
57 | /**
58 | * Empty facet list.
59 | */
60 | public static List EMPTY_FACET_LIST = new LinkedList();
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/FacetCountCollectorSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets;
21 |
22 | import com.browseengine.bobo.api.BoboIndexReader;
23 |
24 | public abstract class FacetCountCollectorSource {
25 | public abstract FacetCountCollector getFacetCountCollector(BoboIndexReader reader,int docBase);
26 | }
27 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/RuntimeFacetHandlerFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets;
21 |
22 |
23 | /**
24 | * This interface is intended for using with RuntimeFacetHandler, which typically
25 | * have local data that make them not only NOT thread safe but also dependent on
26 | * request. So it is necessary to have different instance for different client or
27 | * request. Typically, the new instance need to be initialized before use.
28 | * @author xiaoyang
29 | *
30 | */
31 | public interface RuntimeFacetHandlerFactory>
32 | {
33 | /**
34 | * @return the facet name of the RuntimeFacetHandler it creates.
35 | */
36 | String getName();
37 |
38 | /**
39 | * @return if this facet support empty params or not.
40 | */
41 | boolean isLoadLazily();
42 |
43 | /**
44 | * @param params the data used to initialize the RuntimeFacetHandler.
45 | * @return a new instance of
46 | */
47 | F get(P params);
48 | }
49 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/data/FacetDataFetcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.data;
21 |
22 | import com.browseengine.bobo.api.BoboIndexReader;
23 |
24 | public interface FacetDataFetcher
25 | {
26 | public Object fetch(BoboIndexReader reader, int doc);
27 |
28 | public void cleanup(BoboIndexReader reader);
29 | }
30 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/data/PrimitiveLongArrayWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.data;
21 |
22 | import java.util.Arrays;
23 |
24 | public class PrimitiveLongArrayWrapper
25 | {
26 | public long[] data;
27 |
28 | public PrimitiveLongArrayWrapper(long[] data)
29 | {
30 | this.data = data;
31 | }
32 |
33 | @Override
34 | public boolean equals(Object other)
35 | {
36 | if (other instanceof PrimitiveLongArrayWrapper)
37 | {
38 | return Arrays.equals(data, ((PrimitiveLongArrayWrapper)other).data);
39 | }
40 | return false;
41 | }
42 |
43 | @Override
44 | public int hashCode()
45 | {
46 | return Arrays.hashCode(data);
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermFixedLengthLongArrayListFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.data;
21 |
22 | public class TermFixedLengthLongArrayListFactory implements TermListFactory
23 | {
24 | protected int width;
25 |
26 | public TermFixedLengthLongArrayListFactory(int width)
27 | {
28 | this.width = width;
29 | }
30 |
31 | public TermValueList createTermList(int capacity)
32 | {
33 | return new TermFixedLengthLongArrayList(width, capacity);
34 | }
35 |
36 | public TermValueList createTermList()
37 | {
38 | return createTermList(-1);
39 | }
40 |
41 | public Class> getType()
42 | {
43 | return long[].class;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/data/TermListFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.data;
21 |
22 |
23 | public interface TermListFactory
24 | {
25 | TermValueList createTermList(int capacity);
26 | TermValueList createTermList();
27 | Class> getType();
28 |
29 | public static TermListFactory StringListFactory=new TermListFactory()
30 | {
31 | public TermValueList createTermList(int capacity)
32 | {
33 | return new TermStringList(capacity);
34 | }
35 | public TermValueList createTermList()
36 | {
37 | return createTermList(-1);
38 | }
39 | public Class> getType()
40 | {
41 | return String.class;
42 | }
43 | };
44 | }
45 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/filter/AndFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.filter;
21 |
22 | import java.io.IOException;
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import org.apache.lucene.index.IndexReader;
27 | import org.apache.lucene.search.DocIdSet;
28 | import org.apache.lucene.search.Filter;
29 |
30 | import com.kamikaze.docidset.impl.AndDocIdSet;
31 |
32 | public class AndFilter extends Filter
33 | {
34 |
35 | private static final long serialVersionUID = 1L;
36 |
37 | private final List extends Filter> _filters;
38 |
39 | public AndFilter(List extends Filter> filters)
40 | {
41 | _filters = filters;
42 | }
43 |
44 | @Override
45 | public DocIdSet getDocIdSet(IndexReader reader) throws IOException
46 | {
47 | if (_filters.size() == 1)
48 | {
49 | return _filters.get(0).getDocIdSet(reader);
50 | }
51 | else
52 | {
53 | List list = new ArrayList(_filters.size());
54 | for (Filter f : _filters)
55 | {
56 | list.add(f.getDocIdSet(reader));
57 | }
58 | return new AndDocIdSet(list);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/filter/EmptyFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.filter;
21 |
22 | import java.io.IOException;
23 |
24 | import com.browseengine.bobo.api.BoboIndexReader;
25 | import com.browseengine.bobo.docidset.EmptyDocIdSet;
26 | import com.browseengine.bobo.docidset.RandomAccessDocIdSet;
27 |
28 | public class EmptyFilter extends RandomAccessFilter
29 | {
30 | private static final long serialVersionUID = 1L;
31 |
32 | private static EmptyFilter instance = new EmptyFilter();
33 |
34 | private EmptyFilter()
35 | {
36 |
37 | }
38 |
39 | public double getFacetSelectivity(BoboIndexReader reader)
40 | {
41 | return 0.0;
42 | }
43 |
44 | @Override
45 | public RandomAccessDocIdSet getRandomAccessDocIdSet(BoboIndexReader reader) throws IOException
46 | {
47 | return EmptyDocIdSet.getInstance();
48 | }
49 |
50 | public static EmptyFilter getInstance()
51 | {
52 | return instance;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/filter/FacetValueConverter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.filter;
21 |
22 | import com.browseengine.bobo.facets.data.FacetDataCache;
23 |
24 | public interface FacetValueConverter {
25 | public static FacetValueConverter DEFAULT = new DefaultFacetDataCacheConverter();
26 | int[] convert(FacetDataCache dataCache,String[] vals);
27 |
28 | public static class DefaultFacetDataCacheConverter implements FacetValueConverter{
29 | public DefaultFacetDataCacheConverter(){
30 |
31 | }
32 | public int[] convert(FacetDataCache dataCache,String[] vals){
33 | return FacetDataCache.convert(dataCache, vals);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/filter/NotFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.filter;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.search.DocIdSet;
26 | import org.apache.lucene.search.Filter;
27 |
28 | import com.kamikaze.docidset.impl.NotDocIdSet;
29 |
30 | public class NotFilter extends Filter {
31 |
32 | /**
33 | *
34 | */
35 | private static final long serialVersionUID = 1L;
36 |
37 | private final Filter _innerFilter;
38 |
39 | public NotFilter(Filter innerFilter)
40 | {
41 | _innerFilter = innerFilter;
42 | }
43 | @Override
44 | public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
45 | return new NotDocIdSet(_innerFilter.getDocIdSet(reader),reader.maxDoc());
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/filter/OrFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.filter;
21 |
22 | import java.io.IOException;
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import org.apache.lucene.index.IndexReader;
27 | import org.apache.lucene.search.DocIdSet;
28 | import org.apache.lucene.search.Filter;
29 |
30 | import com.kamikaze.docidset.impl.OrDocIdSet;
31 |
32 | public class OrFilter extends Filter {
33 | /**
34 | *
35 | */
36 | private static final long serialVersionUID = 1L;
37 |
38 | private final List extends Filter> _filters;
39 |
40 | public OrFilter(List extends Filter> filters)
41 | {
42 | _filters = filters;
43 | }
44 |
45 | @Override
46 | public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
47 | if(_filters.size() == 1)
48 | {
49 | return _filters.get(0).getDocIdSet(reader);
50 | }
51 | else
52 | {
53 | List list = new ArrayList(_filters.size());
54 | for (Filter f : _filters)
55 | {
56 | list.add(f.getDocIdSet(reader));
57 | }
58 | return new OrDocIdSet(list);
59 | }
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/filter/RandomAccessFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.filter;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.search.DocIdSet;
26 | import org.apache.lucene.search.Filter;
27 |
28 | import com.browseengine.bobo.api.BoboIndexReader;
29 | import com.browseengine.bobo.docidset.RandomAccessDocIdSet;
30 |
31 | public abstract class RandomAccessFilter extends Filter
32 | {
33 | private static final long serialVersionUID = 1L;
34 |
35 | @Override
36 | public DocIdSet getDocIdSet(IndexReader reader) throws IOException
37 | {
38 | if (reader instanceof BoboIndexReader){
39 | return getRandomAccessDocIdSet((BoboIndexReader)reader);
40 | }
41 | else{
42 | throw new IllegalStateException("reader not instance of "+BoboIndexReader.class);
43 | }
44 | }
45 |
46 | public abstract RandomAccessDocIdSet getRandomAccessDocIdSet(BoboIndexReader reader) throws IOException;
47 | public double getFacetSelectivity(BoboIndexReader reader) { return 0.50; }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/impl/FacetHandlerLoader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.impl;
21 |
22 | import java.io.IOException;
23 | import java.util.Collection;
24 | import java.util.HashMap;
25 | import java.util.Iterator;
26 | import java.util.Map;
27 | import java.util.Set;
28 |
29 | import com.browseengine.bobo.api.BoboIndexReader;
30 | import com.browseengine.bobo.facets.FacetHandler;
31 |
32 | public class FacetHandlerLoader {
33 |
34 | private FacetHandlerLoader()
35 | {
36 |
37 | }
38 | public static void load(Collection tobeLoaded)
39 | {
40 | load(tobeLoaded,null);
41 | }
42 |
43 | public static void load(Collection tobeLoaded,Map preloaded)
44 | {
45 |
46 | }
47 |
48 | private static void load(BoboIndexReader reader,Collection tobeLoaded,Map preloaded,Set visited) throws IOException
49 | {
50 | Map loaded = new HashMap();
51 | if (preloaded!=null)
52 | {
53 | loaded.putAll(preloaded);
54 | }
55 |
56 | Iterator iter = tobeLoaded.iterator();
57 |
58 | while(iter.hasNext())
59 | {
60 | FacetHandler handler = iter.next();
61 | if (!loaded.containsKey(handler.getName()))
62 | {
63 | Set depends = handler.getDependsOn();
64 | if (depends.size() > 0)
65 | {
66 | }
67 | handler.load(reader);
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/impl/FacetValueComparatorFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.impl;
21 |
22 | import java.util.Comparator;
23 |
24 | import com.browseengine.bobo.api.BrowseFacet;
25 | import com.browseengine.bobo.api.ComparatorFactory;
26 | import com.browseengine.bobo.api.FieldValueAccessor;
27 | import com.browseengine.bobo.util.BigSegmentedArray;
28 | import com.browseengine.bobo.util.IntBoundedPriorityQueue.IntComparator;
29 |
30 | public class FacetValueComparatorFactory implements ComparatorFactory {
31 |
32 | public IntComparator newComparator(
33 | FieldValueAccessor fieldValueAccessor, BigSegmentedArray counts) {
34 | return new IntComparator(){
35 | public int compare(Integer o1, Integer o2) {
36 | return o2-o1;
37 | }
38 |
39 | @SuppressWarnings("unused")
40 | // use polymorphism to avoid auto-boxing
41 | public int compare(int o1, int o2) {
42 | return o2-o1;
43 | }
44 | };
45 | }
46 |
47 | public Comparator newComparator() {
48 | return new Comparator(){
49 | public int compare(BrowseFacet o1, BrowseFacet o2) {
50 | return o1.getValue().compareTo(o2.getValue());
51 | }
52 | };
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/impl/GroupByFacetCountCollector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.impl;
21 |
22 | import com.browseengine.bobo.api.BrowseSelection;
23 | import com.browseengine.bobo.api.FacetSpec;
24 | import com.browseengine.bobo.facets.data.FacetDataCache;
25 |
26 | public abstract class GroupByFacetCountCollector extends DefaultFacetCountCollector
27 | {
28 | private int _totalGroups;
29 |
30 | public GroupByFacetCountCollector(String name,
31 | FacetDataCache dataCache,
32 | int docBase,
33 | BrowseSelection sel,
34 | FacetSpec ospec)
35 | {
36 | super(name, dataCache, docBase, sel, ospec);
37 | }
38 |
39 | abstract public int getTotalGroups();
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/impl/MultiValuedPathFacetCountCollector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.impl;
21 |
22 | import com.browseengine.bobo.api.BrowseSelection;
23 | import com.browseengine.bobo.api.FacetSpec;
24 | import com.browseengine.bobo.facets.data.FacetDataCache;
25 | import com.browseengine.bobo.facets.data.MultiValueFacetDataCache;
26 | import com.browseengine.bobo.util.BigIntArray;
27 | import com.browseengine.bobo.util.BigNestedIntArray;
28 |
29 | public class MultiValuedPathFacetCountCollector extends PathFacetCountCollector {
30 |
31 | private final BigNestedIntArray _array;
32 |
33 | public MultiValuedPathFacetCountCollector(String name, String sep,
34 | BrowseSelection sel, FacetSpec ospec, FacetDataCache dataCache) {
35 | super(name, sep, sel, ospec, dataCache);
36 | _array = ((MultiValueFacetDataCache)(dataCache))._nestedArray;
37 | }
38 |
39 | @Override
40 | public final void collect(int docid)
41 | {
42 | _array.countNoReturn(docid, _count);
43 | }
44 |
45 | @Override
46 | public final void collectAll()
47 | {
48 | _count = BigIntArray.fromArray(_dataCache.freqs);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/range/BitSetBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.range;
21 |
22 | import org.apache.lucene.util.OpenBitSet;
23 |
24 | import com.browseengine.bobo.facets.data.FacetDataCache;
25 |
26 | public interface BitSetBuilder {
27 | OpenBitSet bitSet(FacetDataCache dataCache);
28 | }
29 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/range/MultiDataCacheBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.range;
21 |
22 | import com.browseengine.bobo.api.BoboIndexReader;
23 | import com.browseengine.bobo.facets.data.MultiValueFacetDataCache;
24 | import com.browseengine.bobo.facets.filter.AdaptiveFacetFilter.FacetDataCacheBuilder;
25 |
26 | public class MultiDataCacheBuilder implements FacetDataCacheBuilder{
27 | private String name;
28 | private String indexFieldName;
29 |
30 | public MultiDataCacheBuilder(String name, String indexFieldName) {
31 | this.name = name;
32 | this.indexFieldName = indexFieldName;
33 | }
34 |
35 | public MultiValueFacetDataCache build(BoboIndexReader reader) {
36 | return (MultiValueFacetDataCache) reader.getFacetData(name);
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public String getIndexFieldName() {
44 | return indexFieldName;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/range/SimpleDataCacheBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.range;
21 |
22 | import com.browseengine.bobo.api.BoboIndexReader;
23 | import com.browseengine.bobo.facets.data.FacetDataCache;
24 | import com.browseengine.bobo.facets.filter.AdaptiveFacetFilter.FacetDataCacheBuilder;
25 |
26 | public class SimpleDataCacheBuilder implements FacetDataCacheBuilder{
27 | private String name;
28 | private String indexFieldName;
29 |
30 | public SimpleDataCacheBuilder(String name, String indexFieldName) {
31 | this.name = name;
32 | this.indexFieldName = indexFieldName;
33 | }
34 |
35 | public FacetDataCache build(BoboIndexReader reader) {
36 | return (FacetDataCache) reader.getFacetData(name);
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public String getIndexFieldName() {
44 | return indexFieldName;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/range/ValueConverterBitSetBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.range;
21 |
22 | import org.apache.lucene.util.OpenBitSet;
23 |
24 | import com.browseengine.bobo.facets.data.FacetDataCache;
25 | import com.browseengine.bobo.facets.filter.FacetValueConverter;
26 |
27 | public class ValueConverterBitSetBuilder implements BitSetBuilder {
28 | private final FacetValueConverter facetValueConverter;
29 | private final String[] vals;
30 | private final boolean takeCompliment;
31 |
32 | public ValueConverterBitSetBuilder(FacetValueConverter facetValueConverter, String[] vals,boolean takeCompliment) {
33 | this.facetValueConverter = facetValueConverter;
34 | this.vals = vals;
35 | this.takeCompliment = takeCompliment;
36 | }
37 |
38 | @Override
39 | public OpenBitSet bitSet(FacetDataCache dataCache) {
40 | int[] index = facetValueConverter.convert(dataCache, vals);
41 |
42 | OpenBitSet bitset = new OpenBitSet(dataCache.valArray.size());
43 | for (int i : index) {
44 | bitset.fastSet(i);
45 | }
46 | if (takeCompliment)
47 | {
48 | // flip the bits
49 | for (int i=0; i < index.length; ++i){
50 | bitset.fastFlip(i);
51 | }
52 | }
53 | return bitset;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/facets/statistics/ChiSquaredFacetCountStatisticsGenerator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.facets.statistics;
21 |
22 |
23 |
24 | public class ChiSquaredFacetCountStatisticsGenerator extends FacetCountStatisicsGenerator
25 | {
26 |
27 | @Override
28 | public double calculateDistributionScore(int[] distribution,
29 | int collectedSampleCount,
30 | int numSamplesCollected,
31 | int totalSamplesCount)
32 | {
33 | double expected = (double)collectedSampleCount / (double)numSamplesCollected;
34 |
35 | double sum = 0.0;
36 | for (int count : distribution)
37 | {
38 | double v = (double)count - expected;
39 | sum += (v * v);
40 | }
41 |
42 | return sum/expected;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/index/digest/FileDigester.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Bobo Browse Engine - High performance faceted/parametric search implementation
3 | * that handles various types of semi-structured data. Written in Java.
4 | *
5 | * Copyright (C) 2005-2006 John Wang
6 | *
7 | * This library is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * This library is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this library; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | *
21 | * To contact the project administrators for the bobo-browse project,
22 | * please go to https://sourceforge.net/projects/bobo-browse/, or
23 | * send mail to owner@browseengine.com.
24 | */
25 |
26 | package com.browseengine.bobo.index.digest;
27 |
28 | import java.io.File;
29 | import java.io.IOException;
30 | import java.nio.charset.Charset;
31 |
32 | public abstract class FileDigester extends DataDigester {
33 | private File _file;
34 | private Charset _charset;
35 | private int maxDocs;
36 |
37 | public int getMaxDocs() {
38 | return maxDocs;
39 | }
40 |
41 | public void setMaxDocs(int maxDocs) {
42 | this.maxDocs = maxDocs;
43 | }
44 |
45 | public FileDigester(File file) {
46 | super();
47 | _file=file;
48 | }
49 |
50 | public void setCharset(Charset charset){
51 | _charset=charset;
52 | }
53 |
54 | public File getDataFile(){
55 | return _file;
56 | }
57 |
58 | public Charset getCharset(){
59 | return _charset;
60 | }
61 |
62 | abstract public void digest(DataHandler handler) throws IOException;
63 | }
64 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/jmx/JMXUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.jmx;
21 |
22 | public class JMXUtil {
23 | public static final String JMX_DOMAIN = "bobo";
24 | }
25 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/mapred/BoboMapFunctionWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.mapred;
21 |
22 | import java.util.List;
23 |
24 | import com.browseengine.bobo.api.BoboIndexReader;
25 | import com.browseengine.bobo.facets.FacetCountCollector;
26 |
27 | /**
28 | * Is the part of the bobo request, that maintains the map result intermediate state
29 | *
30 | */
31 | public interface BoboMapFunctionWrapper {
32 | /**
33 | * When there is no filter, map reduce will try to map the entire segment
34 | * @param reader
35 | */
36 | public void mapFullIndexReader(BoboIndexReader reader, FacetCountCollector[] facetCountCollectors);
37 | /**
38 | * The basic callback method for a single doc
39 | * @param docId
40 | * @param reader
41 | */
42 | public void mapSingleDocument(int docId, BoboIndexReader reader);
43 | /**
44 | * The callback method, after the segment was processed
45 | * @param reader
46 | */
47 | public void finalizeSegment(BoboIndexReader reader, FacetCountCollector[] facetCountCollectors);
48 | /**
49 | * The callback method, after the partition was processed
50 | *
51 | */
52 | public void finalizePartition();
53 | public MapReduceResult getResult();
54 | }
55 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/mapred/MapReduceResult.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.mapred;
21 |
22 | import java.io.Serializable;
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | /**
27 | * Keeps the map reduce results
28 | *
29 | */
30 | public class MapReduceResult implements Serializable {
31 | protected List mapResults = new ArrayList(200);
32 | protected Serializable reduceResult;
33 | public List getMapResults() {
34 | return mapResults;
35 | }
36 | public MapReduceResult setMapResults(List mapResults) {
37 | this.mapResults = mapResults;
38 | return this;
39 | }
40 | public Serializable getReduceResult() {
41 | return reduceResult;
42 | }
43 | public MapReduceResult setReduceResult(Serializable reduceResult) {
44 | this.reduceResult = reduceResult;
45 | return this;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/MatchAllDocIdSetIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.index.TermDocs;
26 | import org.apache.lucene.search.DocIdSetIterator;
27 |
28 | public class MatchAllDocIdSetIterator extends DocIdSetIterator {
29 | private final TermDocs _termDocs;
30 | private int _docid;
31 | public MatchAllDocIdSetIterator(IndexReader reader) throws IOException {
32 | _termDocs = reader.termDocs(null);
33 | _docid = -1;
34 | }
35 | @Override
36 | public int advance(int target) throws IOException {
37 | return _docid = _termDocs.skipTo(target) ? _termDocs.doc() : NO_MORE_DOCS;
38 | }
39 |
40 | @Override
41 | public int docID() {
42 | return _docid;
43 | }
44 |
45 | @Override
46 | public int nextDoc() throws IOException {
47 | return _docid = _termDocs.next() ? _termDocs.doc() : NO_MORE_DOCS;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/ScorerBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.search.Explanation;
26 | import org.apache.lucene.search.Scorer;
27 |
28 | public interface ScorerBuilder {
29 | Scorer createScorer(Scorer innerScorer, IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException;
30 | Explanation explain(IndexReader reader,int doc,Explanation innerExplaination) throws IOException;
31 | }
32 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/BoboDocScorer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | import java.util.Arrays;
23 | import java.util.Iterator;
24 | import java.util.List;
25 | import java.util.Map;
26 | import java.util.Map.Entry;
27 |
28 | import org.apache.lucene.search.Explanation;
29 |
30 | public abstract class BoboDocScorer {
31 | protected final FacetTermScoringFunction _function;
32 | protected final float[] _boostList;
33 |
34 | public BoboDocScorer(FacetTermScoringFunction scoreFunction,float[] boostList){
35 | _function = scoreFunction;
36 | _boostList = boostList;
37 | }
38 |
39 | public abstract float score(int docid);
40 |
41 | abstract public Explanation explain(int docid);
42 |
43 | public static float[] buildBoostList(List valArray,Map boostMap){
44 | float[] boostList = new float[valArray.size()];
45 | Arrays.fill(boostList, 0.0f);
46 | if (boostMap!=null && boostMap.size()>0){
47 | Iterator> iter = boostMap.entrySet().iterator();
48 | while(iter.hasNext()){
49 | Entry entry = iter.next();
50 | int index = valArray.indexOf(entry.getKey());
51 | if (index>=0){
52 | Float fval = entry.getValue();
53 | if (fval!=null){
54 | boostList[index] = fval.floatValue();
55 | }
56 | }
57 | }
58 | }
59 | return boostList;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/DefaultFacetTermScoringFunction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | import java.util.Arrays;
23 |
24 | import org.apache.lucene.search.Explanation;
25 |
26 | public class DefaultFacetTermScoringFunction implements FacetTermScoringFunction {
27 | private float _sum=0.0f;
28 |
29 | public final void clearScores(){
30 | _sum = 0.0f;
31 | }
32 |
33 | public final float score(int df, float boost) {
34 | return boost;
35 | }
36 |
37 | public final void scoreAndCollect(int df,float boost){
38 | _sum+=boost;
39 | }
40 |
41 | public final float getCurrentScore() {
42 | return _sum;
43 | }
44 |
45 | public Explanation explain(int df, float boost) {
46 | Explanation expl = new Explanation();
47 | expl.setValue(score(df,boost));
48 | expl.setDescription("facet boost value of: "+boost);
49 | return expl;
50 | }
51 |
52 | public Explanation explain(float... scores) {
53 | Explanation expl = new Explanation();
54 | float sum = 0.0f;
55 | for (float score : scores){
56 | sum+=score;
57 | }
58 | expl.setValue(sum);
59 | expl.setDescription("sum of: "+Arrays.toString(scores));
60 | return expl;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/DefaultFacetTermScoringFunctionFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | public class DefaultFacetTermScoringFunctionFactory implements
23 | FacetTermScoringFunctionFactory {
24 |
25 | public FacetTermScoringFunction getFacetTermScoringFunction(int termCount,
26 | int docCount) {
27 | return new DefaultFacetTermScoringFunction();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/FacetScoreable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | import java.util.Map;
23 |
24 | import com.browseengine.bobo.api.BoboIndexReader;
25 |
26 | public interface FacetScoreable {
27 | BoboDocScorer getDocScorer(BoboIndexReader reader,
28 | FacetTermScoringFunctionFactory scoringFunctionFactory,
29 | Map boostMap);
30 | }
31 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/FacetTermScoringFunction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | import org.apache.lucene.search.Explanation;
23 |
24 | public interface FacetTermScoringFunction {
25 | public void clearScores();
26 | public float score(int df,float boost);
27 | public void scoreAndCollect(int df,float boost);
28 | public Explanation explain(int df,float boost);
29 | public float getCurrentScore();
30 | public Explanation explain(float...scores);
31 | }
32 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/FacetTermScoringFunctionFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | public interface FacetTermScoringFunctionFactory {
23 | FacetTermScoringFunction getFacetTermScoringFunction(int termCount,int docCount);
24 | }
25 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/MultiplicativeFacetTermScoringFunction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | import java.util.Arrays;
23 |
24 | import org.apache.lucene.search.Explanation;
25 |
26 | public class MultiplicativeFacetTermScoringFunction implements FacetTermScoringFunction
27 | {
28 | private float _boost = 1.0f;
29 |
30 | public final void clearScores()
31 | {
32 | _boost = 1.0f;
33 | }
34 |
35 | public final float score(int df, float boost)
36 | {
37 | return boost;
38 | }
39 |
40 | public final void scoreAndCollect(int df,float boost)
41 | {
42 | if (boost>0){
43 | _boost *= boost;
44 | }
45 | }
46 |
47 | public final float getCurrentScore()
48 | {
49 | return _boost;
50 | }
51 |
52 | public Explanation explain(int df, float boost)
53 | {
54 | Explanation expl = new Explanation();
55 | expl.setValue(score(df,boost));
56 | expl.setDescription("boost value of: "+boost);
57 | return expl;
58 | }
59 |
60 | public Explanation explain(float... scores) {
61 | Explanation expl = new Explanation();
62 | float boost = 1.0f;
63 | for (float score : scores){
64 | boost *=score;
65 | }
66 | expl.setValue(boost);
67 | expl.setDescription("product of: "+Arrays.toString(scores));
68 | return expl;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/query/scoring/MultiplicativeFacetTermScoringFunctionFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.query.scoring;
21 |
22 | public class MultiplicativeFacetTermScoringFunctionFactory implements FacetTermScoringFunctionFactory
23 | {
24 | public FacetTermScoringFunction getFacetTermScoringFunction(int termCount, int docCount)
25 | {
26 | return new MultiplicativeFacetTermScoringFunction();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/search/section/AbstractTerminalNode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.search.section;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.index.Term;
26 | import org.apache.lucene.index.TermPositions;
27 | import org.apache.lucene.search.DocIdSetIterator;
28 |
29 | /**
30 | * An abstract class for terminal nodes of SectionSearchQueryPlan
31 | */
32 | public abstract class AbstractTerminalNode extends SectionSearchQueryPlan
33 | {
34 | protected TermPositions _tp;
35 | protected int _posLeft;
36 | protected int _curPos;
37 |
38 | public AbstractTerminalNode(Term term, IndexReader reader) throws IOException
39 | {
40 | super();
41 | _tp = reader.termPositions();
42 | _tp.seek(term);
43 | _posLeft = 0;
44 | }
45 |
46 | @Override
47 | public int fetchDoc(int targetDoc) throws IOException
48 | {
49 | if(targetDoc <= _curDoc) targetDoc = _curDoc + 1;
50 |
51 | if(_tp.skipTo(targetDoc))
52 | {
53 | _curDoc = _tp.doc();
54 | _posLeft = _tp.freq();
55 | _curSec = -1;
56 | _curPos = -1;
57 | return _curDoc;
58 | }
59 | else
60 | {
61 | _curDoc = DocIdSetIterator.NO_MORE_DOCS;
62 | _tp.close();
63 | return _curDoc;
64 | }
65 | }
66 |
67 | abstract public int fetchSec(int targetSec) throws IOException;
68 | }
69 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/search/section/MetaDataCache.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.search.section;
21 |
22 | public interface MetaDataCache {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/search/section/MetaDataCacheProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.search.section;
21 |
22 | import org.apache.lucene.index.Term;
23 |
24 | public interface MetaDataCacheProvider {
25 | public MetaDataCache get(Term term);
26 | }
27 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/search/section/MetaDataQuery.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.search.section;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.index.Term;
26 | import org.apache.lucene.search.Query;
27 |
28 | public abstract class MetaDataQuery extends Query
29 | {
30 | private static final long serialVersionUID = 1L;
31 |
32 | protected Term _term;
33 |
34 | public MetaDataQuery(Term term)
35 | {
36 | _term = term;
37 | }
38 |
39 | public Term getTerm()
40 | {
41 | return _term;
42 | }
43 |
44 | public abstract SectionSearchQueryPlan getPlan(IndexReader reader) throws IOException;
45 | public abstract SectionSearchQueryPlan getPlan(MetaDataCache cache) throws IOException;
46 | }
47 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/search/section/UnaryNotNode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.search.section;
21 |
22 | import java.io.IOException;
23 |
24 | /**
25 | * UNARY-NOT operator node
26 | * (this node is not supported by SectionSearchQueryPlan)
27 | */
28 | public class UnaryNotNode extends SectionSearchQueryPlan
29 | {
30 | private SectionSearchQueryPlan _subquery;
31 |
32 | public UnaryNotNode(SectionSearchQueryPlan subquery)
33 | {
34 | super();
35 | _subquery = subquery;
36 | }
37 |
38 | public SectionSearchQueryPlan getSubquery()
39 | {
40 | return _subquery;
41 | }
42 |
43 | @Override
44 | public int fetchDoc(int targetDoc) throws IOException
45 | {
46 | throw new UnsupportedOperationException("UnaryNotNode does not support fetchDoc");
47 | }
48 |
49 | @Override
50 | public int fetchSec(int targetSec) throws IOException
51 | {
52 | throw new UnsupportedOperationException("UnaryNotNode does not support fetchSec");
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/server/qlog/QueryLog.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.server.qlog;
21 |
22 | import org.apache.log4j.Logger;
23 |
24 |
25 | public class QueryLog {
26 | private static Logger logger=Logger.getLogger(QueryLog.class);
27 |
28 | public static class LogLine{
29 | String protocol;
30 | String method;
31 | String request;
32 |
33 | private LogLine(){
34 |
35 | }
36 | public String getMethod() {
37 | return method;
38 | }
39 |
40 | public String getProtocol() {
41 | return protocol;
42 | }
43 |
44 | public String getRequest() {
45 | return request;
46 | }
47 |
48 |
49 | }
50 |
51 | public static void logQuery(String request){
52 | logger.info(request);
53 | }
54 |
55 | public static LogLine readLog(String line){
56 |
57 | LogLine log=new LogLine();
58 | int index=line.indexOf('#');
59 | if (index!=-1){
60 | String header=line.substring(0, index);
61 | log.request=line.substring(index+1,line.length());
62 |
63 | String[] parts=header.split("/");
64 | log.protocol=parts[0];
65 | log.method=parts[1];
66 |
67 | }
68 | return log;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/service/BrowseQueryParser.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.service;
21 |
22 | import org.apache.lucene.search.DocIdSet;
23 |
24 | /**
25 | * Builds a DocSet from an array of SelectioNodes
26 | */
27 | public interface BrowseQueryParser {
28 | public static class SelectionNode
29 | {
30 | private String fieldName;
31 | private DocIdSet docSet;
32 |
33 | public SelectionNode()
34 | {
35 | }
36 |
37 | public SelectionNode(String fieldName,DocIdSet docSet)
38 | {
39 | this.fieldName=fieldName;
40 | this.docSet=docSet;
41 | }
42 |
43 | public String getFieldName() {
44 | return fieldName;
45 | }
46 | public void setFieldName(String fieldName) {
47 | this.fieldName = fieldName;
48 | }
49 | public DocIdSet getDocSet() {
50 | return docSet;
51 | }
52 | public void setDocSet(DocIdSet docSet) {
53 | this.docSet = docSet;
54 | }
55 | }
56 |
57 | DocIdSet parse(SelectionNode[] selectionNodes,SelectionNode[] notSelectionNodes,int maxDoc);
58 | }
59 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/service/BrowseService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Bobo Browse Engine - High performance faceted/parametric search implementation
3 | * that handles various types of semi-structured data. Written in Java.
4 | *
5 | * Copyright (C) 2005-2006 John Wang
6 | *
7 | * This library is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * This library is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this library; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | *
21 | * To contact the project administrators for the bobo-browse project,
22 | * please go to https://sourceforge.net/projects/bobo-browse/.
23 | *
24 | */
25 | package com.browseengine.bobo.service;
26 |
27 | import com.browseengine.bobo.api.BrowseException;
28 | import com.browseengine.bobo.api.BrowseRequest;
29 | import com.browseengine.bobo.api.BrowseResult;
30 |
31 | public interface BrowseService {
32 | BrowseResult browse(BrowseRequest req) throws BrowseException;
33 | void close() throws BrowseException;
34 | static final BrowseResult EMPTY_RESULT=new BrowseResult();
35 | }
36 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/service/HitCompareMulti.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.service;
21 |
22 | import java.util.Comparator;
23 |
24 | import com.browseengine.bobo.api.BrowseHit;
25 |
26 | public class HitCompareMulti implements Comparator
27 | {
28 | protected Comparator[] m_hcmp;
29 |
30 | public HitCompareMulti(Comparator[] hcmp)
31 | {
32 | m_hcmp = hcmp;
33 | }
34 |
35 | // HitCompare
36 | public int compare(BrowseHit h1, BrowseHit h2)
37 | {
38 | int retVal=0;
39 | for (int i=0;i _luceneComparator;
31 | private final String _fieldname;
32 | public LuceneCustomDocComparatorSource(String fieldname,FieldComparator luceneComparator){
33 | _fieldname = fieldname;
34 | _luceneComparator = luceneComparator;
35 | }
36 |
37 | @Override
38 | public DocComparator getComparator(IndexReader reader, int docbase)
39 | throws IOException {
40 | _luceneComparator.setNextReader(reader, docbase);
41 | return new DocComparator() {
42 |
43 | @Override
44 | public Comparable value(ScoreDoc doc) {
45 | return _luceneComparator.value(doc.doc);
46 | }
47 |
48 | @Override
49 | public int compare(ScoreDoc doc1, ScoreDoc doc2) {
50 | return _luceneComparator.compare(doc1.doc, doc2.doc);
51 | }
52 |
53 | @Override
54 | public DocComparator setScorer(Scorer scorer) {
55 | _luceneComparator.setScorer(scorer);
56 | return this;
57 | }
58 | };
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/sort/MultiDocIdComparatorSource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.sort;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.index.IndexReader;
25 |
26 | /**
27 | * @author ymatsuda
28 | *
29 | */
30 | public class MultiDocIdComparatorSource extends DocComparatorSource
31 | {
32 | private DocComparatorSource[] _compSources;
33 |
34 | public MultiDocIdComparatorSource(DocComparatorSource[] compSources)
35 | {
36 | _compSources = compSources;
37 | }
38 |
39 | @Override
40 | public DocComparator getComparator(IndexReader reader, int docBase) throws IOException
41 | {
42 | DocComparator[] comparators = new DocComparator[_compSources.length];
43 | for (int i=0; i<_compSources.length; ++i)
44 | {
45 | comparators[i] = _compSources[i].getComparator(reader,docBase);
46 | }
47 | return new MultiDocIdComparator(comparators);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/BigIntBuffer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util;
21 |
22 | import java.util.ArrayList;
23 |
24 | /**
25 | * @author ymatsuda
26 | *
27 | */
28 | public class BigIntBuffer
29 | {
30 | private static final int PAGESIZE = 1024;
31 | private static final int MASK = 0x3FF;
32 | private static final int SHIFT = 10;
33 |
34 | private ArrayList _buffer;
35 | private int _allocSize;
36 | private int _mark;
37 |
38 | public BigIntBuffer()
39 | {
40 | _buffer = new ArrayList();
41 | _allocSize = 0;
42 | _mark = 0;
43 | }
44 |
45 | public int alloc(int size)
46 | {
47 | if(size > PAGESIZE) throw new IllegalArgumentException("size too big");
48 |
49 | if((_mark + size) > _allocSize)
50 | {
51 | int[] page = new int[PAGESIZE];
52 | _buffer.add(page);
53 | _allocSize += PAGESIZE;
54 | }
55 | int ptr = _mark;
56 | _mark += size;
57 |
58 | return ptr;
59 | }
60 |
61 | public void reset()
62 | {
63 | _mark = 0;
64 | }
65 |
66 | public void set(int ptr, int val)
67 | {
68 | int[] page = _buffer.get(ptr >> SHIFT);
69 | page[ptr & MASK] = val;
70 | }
71 |
72 | public int get(int ptr)
73 | {
74 | int[] page = _buffer.get(ptr >> SHIFT);
75 | return page[ptr & MASK];
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/BitMath.java:
--------------------------------------------------------------------------------
1 | package com.browseengine.bobo.util;
2 |
3 | public class BitMath {
4 | private static final int[] mask = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
5 | private static final int[] shift = {1, 2, 4, 8, 16};
6 |
7 | public static int log2Ceiling(int x) {
8 | int result = 0;
9 |
10 | boolean isPowerOfTwo = (x & (x - 1)) == 0;
11 |
12 | for (int i = 4; i >= 0; i--) // unroll for speed...
13 | {
14 | if ((x & mask[i]) != 0)
15 | {
16 | x >>= shift[i];
17 | result |= shift[i];
18 | }
19 | }
20 |
21 | return isPowerOfTwo ? result : result + 1;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/BoundedPriorityQueue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util;
21 |
22 | import java.util.Comparator;
23 | import java.util.PriorityQueue;
24 |
25 | public class BoundedPriorityQueue extends PriorityQueue
26 | {
27 | /**
28 | *
29 | */
30 | private static final long serialVersionUID = 1L;
31 |
32 | private final int _maxSize;
33 | public BoundedPriorityQueue(int maxSize)
34 | {
35 | super();
36 | _maxSize=maxSize;
37 | }
38 |
39 | public BoundedPriorityQueue(Comparator super E> comparator,int maxSize)
40 | {
41 | super(maxSize, comparator);
42 | _maxSize=maxSize;
43 | }
44 |
45 | @Override
46 | public boolean offer(E o)
47 | {
48 | int size=size();
49 | if (size<_maxSize)
50 | {
51 | return super.offer(o);
52 | }
53 | else
54 | {
55 | E smallest=super.peek();
56 | Comparator super E> comparator = super.comparator();
57 | boolean madeIt=false;
58 | if (comparator == null)
59 | {
60 | if (((Comparable)smallest).compareTo(o) < 0)
61 | {
62 | madeIt=true;
63 | }
64 | }
65 | else
66 | {
67 | if (comparator.compare(smallest, o) < 0)
68 | {
69 | madeIt=true;
70 | }
71 | }
72 |
73 | if (madeIt)
74 | {
75 | super.poll();
76 | return super.offer(o);
77 | }
78 | else
79 | {
80 | return false;
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/DocIdSetUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.search.DocIdSet;
25 | import org.apache.lucene.search.DocIdSetIterator;
26 |
27 | public class DocIdSetUtil
28 | {
29 | private DocIdSetUtil(){}
30 |
31 | public static String toString(DocIdSet docIdSet) throws IOException
32 | {
33 | DocIdSetIterator iter = docIdSet.iterator();
34 | StringBuffer buf = new StringBuffer();
35 | boolean firstTime = true;
36 | buf.append("[");
37 | int docid;
38 | while((docid=iter.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
39 | {
40 | if (firstTime)
41 | {
42 | firstTime = false;
43 | }
44 | else
45 | {
46 | buf.append(",");
47 | }
48 | buf.append(docid);
49 | }
50 | buf.append("]");
51 | return buf.toString();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/FloatMatrix.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Bobo Browse Engine - High performance faceted/parametric search implementation
3 | * that handles various types of semi-structured data. Written in Java.
4 | *
5 | * Copyright (C) 2005-2006 John Wang
6 | *
7 | * This library is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * This library is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this library; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | *
21 | * To contact the project administrators for the bobo-browse project,
22 | * please go to https://sourceforge.net/projects/bobo-browse/, or
23 | * send mail to owner@browseengine.com.
24 | */
25 |
26 | package com.browseengine.bobo.util;
27 |
28 | import java.lang.reflect.Array;
29 |
30 | public class FloatMatrix extends PrimitiveMatrix {
31 |
32 | /**
33 | *
34 | */
35 | private static final long serialVersionUID = 1L;
36 |
37 | public FloatMatrix(int[] sizes) {
38 | super(float.class, sizes);
39 | }
40 |
41 | public FloatMatrix() {
42 | super(float.class);
43 | }
44 |
45 | public synchronized void set(int x,int y,float n){
46 | ensureCapacity(x,y);
47 | // get the row
48 | Object row=Array.get(_matrix, x);
49 | if (row==null){
50 | throw new ArrayIndexOutOfBoundsException("index out of bounds: "+x);
51 | }
52 | Array.setFloat(row, y, n);
53 | _rowCount=Math.max(x, _rowCount);
54 | _colCount=Math.max(y, _colCount);
55 | }
56 |
57 | public float get(int r,int c){
58 | Object row=Array.get(_matrix, r);
59 | if (row==null){
60 | throw new ArrayIndexOutOfBoundsException("index out of bounds: "+r);
61 | }
62 | return Array.getFloat(row, c);
63 | }
64 |
65 | public synchronized float[][] toArray(){
66 | float[][] ret=new float[_rowCount][_colCount];
67 | for (int i=0;i<_rowCount;++i){
68 | Object row=Array.get(_matrix, i);
69 | System.arraycopy(row,0,ret[i],0,_colCount);
70 | }
71 | return ret;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/MemoryManagerAdminMBean.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util;
21 |
22 | public interface MemoryManagerAdminMBean {
23 | long getNumCacheHits();
24 | long getNumCacheMisses();
25 | double getHitRate();
26 | }
27 |
--------------------------------------------------------------------------------
/bobo-browse/src/main/java/com/browseengine/bobo/util/StringArrayComparator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util;
21 |
22 | import java.util.Arrays;
23 |
24 |
25 | public class StringArrayComparator implements Comparable {
26 | private String[] vals;
27 | public StringArrayComparator(String[] vals){
28 | this.vals = vals;
29 | }
30 | public int compareTo(StringArrayComparator node) {
31 | String[] o = node.vals;
32 | if (vals==o){
33 | return 0;
34 | }
35 | if (vals == null){
36 | return -1;
37 | }
38 | if (o == null){
39 | return 1;
40 | }
41 | for (int i = 0;i < vals.length; ++i){
42 | if (i>=o.length){
43 | return 1;
44 | }
45 | int compVal = vals[i].compareTo(o[i]);
46 | if (vals[i].startsWith("-") && o[i].startsWith("-") ) {
47 | compVal *= -1;
48 | }
49 | if (compVal!=0) return compVal;
50 | }
51 | if (vals.length == o.length) return 0;
52 | return -1;
53 | }
54 |
55 | @Override
56 | public String toString(){
57 | return Arrays.toString(vals);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/bobo-browse/src/test/java/com/browseengine/bobo/test/StressTestSuite.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Bobo Browse Engine - High performance faceted/parametric search implementation
3 | * that handles various types of semi-structured data. Written in Java.
4 | *
5 | * Copyright (C) 2005-2007 spackle
6 | *
7 | * This library is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * This library is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this library; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | *
21 | * To contact the project administrators for the bobo-browse project,
22 | * please go to https://sourceforge.net/projects/bobo-browse/, or
23 | * contact owner@browseengine.com.
24 | */
25 |
26 | package com.browseengine.bobo.test;
27 |
28 | import junit.framework.Test;
29 | import junit.framework.TestSuite;
30 | import junit.textui.TestRunner;
31 |
32 | import com.browseengine.bobo.util.test.SparseFloatArrayTest;
33 |
34 | /**
35 | * For tests which take a while.
36 | *
37 | * @author spackle
38 | *
39 | */
40 | public class StressTestSuite {
41 | public static Test suite(){
42 | TestSuite suite=new TestSuite();
43 |
44 | suite.addTestSuite(SparseFloatArrayTest.class); // 91.9 seconds
45 | return suite;
46 | }
47 |
48 | /**
49 | * @param args
50 | */
51 | public static void main(String[] args) {
52 | TestRunner.run(suite());
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/bobo-browse/src/test/java/com/browseengine/bobo/test/UnitTestSuite.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Bobo Browse Engine - High performance faceted/parametric search implementation
3 | * that handles various types of semi-structured data. Written in Java.
4 | *
5 | * Copyright (C) 2005-2006 John Wang
6 | *
7 | * This library is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * This library is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this library; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | *
21 | * To contact the project administrators for the bobo-browse project,
22 | * please go to https://sourceforge.net/projects/bobo-browse/, or
23 | * send mail to owner@browseengine.com.
24 | */
25 |
26 | package com.browseengine.bobo.test;
27 |
28 | import junit.framework.Test;
29 | import junit.framework.TestSuite;
30 | import junit.textui.TestRunner;
31 |
32 | import com.browseengine.bobo.test.section.TestSectionSearch;
33 |
34 |
35 | public class UnitTestSuite {
36 |
37 | public static Test suite(){
38 | TestSuite suite=new TestSuite();
39 | suite.addTestSuite(BoboTestCase.class);
40 | suite.addTestSuite(FacetHandlerTest.class);
41 | suite.addTestSuite(TestSectionSearch.class);
42 | suite.addTestSuite(BoboFacetIteratorTest.class);
43 | suite.addTestSuite(FacetNotValuesTest.class);
44 | suite.addTestSuite(FacetNameTest.class);
45 | return suite;
46 | }
47 |
48 | /**
49 | * @param args
50 | */
51 | public static void main(String[] args) {
52 | TestRunner.run(suite());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/bobo-browse/src/test/java/com/browseengine/bobo/util/test/BigIntArrayTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util.test;
21 |
22 | import com.browseengine.bobo.util.BigIntArray;
23 |
24 | import junit.framework.TestCase;
25 |
26 | public class BigIntArrayTest extends TestCase
27 | {
28 | public static void testBigIntArray()
29 | {
30 | int count = 5000000;
31 | BigIntArray test = new BigIntArray(count);
32 | int[] test2 = new int[count];
33 | for (int i = 0; i < count; i++)
34 | {
35 | test.add(i, i);
36 | test2[i]=i;
37 | }
38 |
39 | for (int i = 0; i< count; i++)
40 | {
41 | assertEquals(0, test.get(0));
42 | }
43 |
44 | int k = 0;
45 | long start = System.currentTimeMillis();
46 | for (int i = 0; i < count; i++)
47 | {
48 | k = test.get(i);
49 | }
50 | long end = System.currentTimeMillis();
51 | System.out.println("Big array took: "+(end-start));
52 |
53 | start = System.currentTimeMillis();
54 | for (int i = 0; i < count; i++)
55 | {
56 | k = test2[i];
57 | }
58 | end=System.currentTimeMillis();
59 | System.out.println("int[] took: "+(end-start));
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/bobo-browse/src/test/java/com/browseengine/bobo/util/test/IndexReaderWithMetaDataCache.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.util.test;
21 |
22 | import java.util.HashMap;
23 |
24 | import org.apache.lucene.index.FilterIndexReader;
25 | import org.apache.lucene.index.IndexReader;
26 | import org.apache.lucene.index.Term;
27 |
28 | import com.browseengine.bobo.search.section.IntMetaDataCache;
29 | import com.browseengine.bobo.search.section.MetaDataCache;
30 | import com.browseengine.bobo.search.section.MetaDataCacheProvider;
31 |
32 | public class IndexReaderWithMetaDataCache extends FilterIndexReader implements MetaDataCacheProvider
33 | {
34 |
35 | private final static Term intMetaTerm = new Term("metafield", "intmeta");
36 | private HashMap map = new HashMap();
37 |
38 | public IndexReaderWithMetaDataCache(IndexReader in) throws Exception
39 | {
40 | super(in);
41 |
42 | map.put(intMetaTerm, new IntMetaDataCache(intMetaTerm, in));
43 | }
44 |
45 | public MetaDataCache get(Term term)
46 | {
47 | return map.get(term);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/bobo-contrib/README.TXT:
--------------------------------------------------------------------------------
1 | This directory contains a contrib-area for bobo extensions and enhancements, separate from the core.
2 |
3 | Current functionality list
4 | BTree-Bitwise-Interlace-Geosearch
5 |
6 | To build, do:
7 |
8 | cd ..
9 | ant
10 | cd bobo-contrib
11 | ant
12 |
13 | To test, do:
14 |
15 | cd ..
16 | ant
17 | cd bobo-contrib
18 | ant clean test
19 |
20 | You have to put lucene-patch-0.1.jar ahead of lucene-core-3.5*.jar in your classpath. bobo-contrib-0.1.jar contains the rest of the BTree-Bitwise-Interlace-Geosearch.
21 |
22 | The bobo-contrib area is a lucene-3.5* derivative, that is not yet reconciled with bobo-browse's use of lucene-3.0*.
23 |
24 |
25 |
--------------------------------------------------------------------------------
/bobo-contrib/TODO.TXT:
--------------------------------------------------------------------------------
1 | bobo-contrib todo
2 | - resolve lucene 3.0.x/"3.5 + LUCENE-3627" difference between bobo and bobo-contrib.
3 |
4 | btree-bitwise-interlace-geosearch todo
5 | - add locality of reference to preserve triangle-tree overlay, helps
6 | if not in-memory
7 | - add refinement step for values in range, for the case where geosearch
8 | distance is the dominant score component, including narrowing the
9 | range from block to block of docids. this will hit answers even faster
10 | at the expense of an imprecise hitcount, which is often tolerable
11 | particularly for large indexes
12 | - add refinement step from the paper, for narrowing the boundaries on
13 | dense hits sorted by distance
14 | - fix merge out-of-order condition
15 | - provide cleaner geo index merge and deletion support. Either via
16 | lucene 4.x flexible indexing(when released) or a patch to lucene 3.x
17 | that provides the appropriate extension points
18 |
19 |
20 |
--------------------------------------------------------------------------------
/bobo-contrib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 |
4 | sourceCompatibility = 1.6
5 |
6 | repositories {
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | compile "commons-io:commons-io:1.4"
12 | compile "org.hamcrest:hamcrest-library:1.1"
13 | compile "commons-lang:commons-lang:2.6"
14 | compile "cglib:cglib-nodep:2.2"
15 | compile "log4j:log4j:1.2.16"
16 | compile "org.apache.lucene:lucene-core:3.5.0"
17 | compile "org.objenesis:objenesis:1.0"
18 | compile "org.springframework:spring-context:3.0.3.RELEASE"
19 |
20 | testCompile "org.jmock:jmock:2.5.1"
21 | testCompile "org.jmock:jmock-junit4:2.5.1"
22 | testCompile "org.jmock:jmock-legacy:2.5.1"
23 | testCompile "org.springframework:spring-test:3.0.3.RELEASE"
24 | testCompile "junit:junit:4.5"
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/CartesianCoordinateDocId.java:
--------------------------------------------------------------------------------
1 | package com.browseengine.bobo.geosearch;
2 |
3 |
4 | public class CartesianCoordinateDocId {
5 | public int x;
6 | public int y;
7 | public int z;
8 |
9 | public int docid;
10 |
11 | public CartesianCoordinateDocId(int x, int y, int z, int docid) {
12 | this.x = x;
13 | this.y = y;
14 | this.z = z;
15 |
16 | this.docid = docid;
17 | }
18 |
19 | @Override
20 | public int hashCode() {
21 | final int prime = 31;
22 | int result = 1;
23 | result = prime * result + x;
24 | result = prime * result + y;
25 | result = prime * result + z;
26 | result = prime * result + docid;
27 | return result;
28 | }
29 |
30 | @Override
31 | public boolean equals(Object obj) {
32 | if (this == obj)
33 | return true;
34 | if (obj == null)
35 | return false;
36 | if (getClass() != obj.getClass())
37 | return false;
38 | CartesianCoordinateDocId other = (CartesianCoordinateDocId) obj;
39 | if (x != other.x)
40 | return false;
41 | if (y != other.y)
42 | return false;
43 | if (z != other.z)
44 | return false;
45 | if (docid != other.docid)
46 | return false;
47 | return true;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return "[(x=" + x + ", y=" + y + ", z=" + z + "), docid=" + docid + "]";
53 | }
54 |
55 | /**
56 | * {@inheritDoc}
57 | */
58 | @Override
59 | public CartesianCoordinateDocId clone() {
60 | CartesianCoordinateDocId clone = new CartesianCoordinateDocId(
61 | x,
62 | y,
63 | z,
64 | docid);
65 | return clone;
66 | }
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/GeoRecordUtil.java:
--------------------------------------------------------------------------------
1 | package com.browseengine.bobo.geosearch;
2 |
3 | /**
4 | *
5 | * @author gcooney
6 | *
7 | */
8 | public class GeoRecordUtil {
9 | public static final int MAX_DIGITS_INT = ndigits(Integer.MAX_VALUE);
10 | public static final int MAX_DIGITS_LONG = ndigits(Long.MAX_VALUE);
11 |
12 | public static String lpad(int maxDigits, long val) {
13 | int ndigits = ndigits(val);
14 | int pad = maxDigits - ndigits;
15 | StringBuilder buf = new StringBuilder();
16 | while (pad > 0) {
17 | buf.append('0');
18 | pad--;
19 | }
20 | buf.append(val);
21 | return buf.toString();
22 | }
23 |
24 | private static int ndigits(long val) {
25 | val = Long.highestOneBit(val);
26 | int i = 0;
27 | while (val > 0) {
28 | i++;
29 | val /= 10;
30 | }
31 | return i;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/GeoVersion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch;
21 |
22 | public class GeoVersion {
23 | public static final int CURRENT_VERSION = 1;
24 | public static final int CURRENT_GEOONLY_VERSION = 1;
25 |
26 | public static final int VERSION_0 = 0;
27 | public static final int VERSION_1 = 1;
28 | }
29 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/IDeletedDocs.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch;
21 |
22 | /**
23 | * @author Ken McCracken
24 | *
25 | */
26 | public interface IDeletedDocs {
27 |
28 | boolean isDeleted(int docid);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/IFieldNameFilterConverter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch;
21 |
22 | import java.io.IOException;
23 | import java.util.List;
24 |
25 | import org.apache.lucene.store.DataInput;
26 | import org.apache.lucene.store.DataOutput;
27 |
28 | public interface IFieldNameFilterConverter {
29 | byte getFilterValue(String[] fieldNames);
30 | List getFields(byte filterValue);
31 | boolean fieldIsInFilter(String fieldName, byte filterValue);
32 |
33 | void writeToOutput(DataOutput output) throws IOException;
34 | void loadFromInput(DataInput input) throws IOException;
35 | }
36 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/IGeoRecordIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch;
21 |
22 | import java.io.IOException;
23 | import java.util.Iterator;
24 |
25 | import com.browseengine.bobo.geosearch.bo.CartesianGeoRecord;
26 |
27 | /**
28 | * The method to use on the GeoRecord tree/index.
29 | *
30 | * @author Ken McCracken
31 | *
32 | */
33 | public interface IGeoRecordIterator {
34 |
35 | /**
36 | * Returns an iterator on the matching records on
37 | * [minValue, maxValue].
38 | *
39 | * @param minValue
40 | * @param maxValue
41 | * @return
42 | */
43 | Iterator getIterator(CartesianGeoRecord minValue, CartesianGeoRecord maxValue) throws IOException;
44 | }
45 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/IGeoRecordSerializer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch;
21 |
22 | import java.io.IOException;
23 |
24 | import org.apache.lucene.store.IndexInput;
25 | import org.apache.lucene.store.IndexOutput;
26 |
27 | import com.browseengine.bobo.geosearch.bo.IGeoRecord;
28 |
29 | /**
30 | *
31 | * @author gcooney
32 | *
33 | */
34 | public interface IGeoRecordSerializer {
35 | public void writeGeoRecord(IndexOutput output, G record, int recordByteCount) throws IOException;
36 | public G readGeoRecord(IndexInput input, int recordByteCount) throws IOException;
37 | }
38 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/IGeoUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch;
21 | import java.util.Iterator;
22 | import java.util.TreeSet;
23 |
24 | import com.browseengine.bobo.geosearch.bo.CartesianGeoRecord;
25 | import com.browseengine.bobo.geosearch.bo.LatitudeLongitudeDocId;
26 |
27 | public interface IGeoUtil {
28 | Iterator getGeoRecordIterator(Iterator lldidIter);
29 | TreeSet getBinaryTreeOrderedByBitMag(Iterator grIter);
30 | TreeSet getBinaryTreeOrderedByBitMag();
31 | TreeSet getBinaryTreeOrderedByDocId(Iterator grIter);
32 | Iterator getGeoRecordRangeIterator(TreeSet tree, CartesianGeoRecord minRange, CartesianGeoRecord maxRange);
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/bo/GeRecordAndCartesianDocId.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.browseengine.bobo.geosearch.bo;
5 |
6 | import com.browseengine.bobo.geosearch.CartesianCoordinateDocId;
7 |
8 | /**
9 | * We have got to find a shorter name for this class.
10 | *
11 | * @author Ken McCracken
12 | * @author shandets
13 | *
14 | */
15 | public class GeRecordAndCartesianDocId {
16 | public IGeoRecord geoRecord;
17 | public CartesianCoordinateDocId cartesianCoordinateDocId;
18 |
19 | public GeRecordAndCartesianDocId(IGeoRecord geoRecord,
20 | CartesianCoordinateDocId cartesianCoordinateDocId) {
21 | this.geoRecord = geoRecord;
22 | this.cartesianCoordinateDocId = cartesianCoordinateDocId;
23 | }
24 |
25 | /**
26 | * {@inheritDoc}
27 | */
28 | @Override
29 | public String toString() {
30 | return "GeRecordAndCartesianDocId [geoRecord=" + geoRecord + ", cartesianCoordinateDocId="
31 | + cartesianCoordinateDocId + "]";
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/bo/IGeoRecord.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This software is licensed to you under the Apache License, Version 2.0 (the
3 | * "Apache License").
4 | *
5 | * LinkedIn's contributions are made under the Apache License. If you contribute
6 | * to the Software, the contributions will be deemed to have been made under the
7 | * Apache License, unless you expressly indicate otherwise. Please do not make any
8 | * contributions that would be inconsistent with the Apache License.
9 | *
10 | * You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0
11 | * Unless required by applicable law or agreed to in writing, this software
12 | * distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache
14 | * License for the specific language governing permissions and limitations for the
15 | * software governed under the Apache License.
16 | *
17 | * © 2012 LinkedIn Corp. All Rights Reserved.
18 | */
19 |
20 | package com.browseengine.bobo.geosearch.bo;
21 |
22 | /**
23 | *
24 | * @author gcooney
25 | *
26 | */
27 | public interface IGeoRecord {
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/impl/CartesianGeoRecordComparator.java:
--------------------------------------------------------------------------------
1 | package com.browseengine.bobo.geosearch.impl;
2 |
3 | import java.util.Comparator;
4 |
5 | import com.browseengine.bobo.geosearch.bo.CartesianGeoRecord;
6 |
7 | /**
8 | *
9 | * Basic comparator for CartesianGeoRecords
10 | *
11 | * @author gcooney
12 | *
13 | */
14 | public class CartesianGeoRecordComparator implements Comparator {
15 | @Override
16 | public int compare(CartesianGeoRecord recordFirst, CartesianGeoRecord recordSecond) {
17 | long highdiff = recordFirst.highOrder - recordSecond.highOrder;
18 | if(highdiff > 0) {
19 | return 1;
20 | }
21 | if (highdiff < 0) {
22 | return -1;
23 | }
24 | long lowdiff = recordFirst.lowOrder - recordSecond.lowOrder;
25 | if(lowdiff > 0) {
26 | return 1;
27 | }
28 | if (lowdiff < 0) {
29 | return -1;
30 | }
31 |
32 | if (recordFirst.filterByte > recordSecond.filterByte) {
33 | return 1;
34 | } else if (recordFirst.filterByte < recordSecond.filterByte) {
35 | return -1;
36 | }
37 |
38 | return 0;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/impl/CartesianGeoRecordCompareByDocId.java:
--------------------------------------------------------------------------------
1 | package com.browseengine.bobo.geosearch.impl;
2 | import java.util.Comparator;
3 |
4 | import com.browseengine.bobo.geosearch.CartesianCoordinateDocId;
5 | import com.browseengine.bobo.geosearch.bo.CartesianGeoRecord;
6 | public class CartesianGeoRecordCompareByDocId implements Comparator