├── .classpath ├── .gitignore ├── .project ├── LICENSE.TXT ├── README.md ├── bobo-browse ├── .gitignore ├── build.gradle ├── pom.xml ├── resource │ └── log4j.properties └── src │ ├── main │ └── java │ │ └── com │ │ └── browseengine │ │ └── bobo │ │ ├── analysis │ │ └── section │ │ │ ├── IntMetaDataTokenStream.java │ │ │ └── SectionTokenStream.java │ │ ├── api │ │ ├── BoboBrowser.java │ │ ├── BoboCustomSortField.java │ │ ├── BoboIndexReader.java │ │ ├── BoboSubBrowser.java │ │ ├── Browsable.java │ │ ├── BrowseException.java │ │ ├── BrowseFacet.java │ │ ├── BrowseHit.java │ │ ├── BrowseRequest.java │ │ ├── BrowseResult.java │ │ ├── BrowseSelection.java │ │ ├── ComparatorFactory.java │ │ ├── DoubleFacetIterator.java │ │ ├── FacetAccessible.java │ │ ├── FacetIterator.java │ │ ├── FacetSpec.java │ │ ├── FieldValueAccessor.java │ │ ├── FloatFacetIterator.java │ │ ├── IntFacetIterator.java │ │ ├── LongFacetIterator.java │ │ ├── MappedFacetAccessible.java │ │ ├── MultiBoboBrowser.java │ │ ├── QueriesSupport.java │ │ └── ShortFacetIterator.java │ │ ├── client │ │ ├── BoboCmdlineApp.java │ │ ├── BrowseRequestBuilder.java │ │ └── BrowseResultFormatter.java │ │ ├── docidset │ │ ├── BitsetDocSet.java │ │ ├── EmptyDocIdSet.java │ │ ├── FilteredDocSetIterator.java │ │ └── RandomAccessDocIdSet.java │ │ ├── facets │ │ ├── AbstractRuntimeFacetHandlerFactory.java │ │ ├── CombinedFacetAccessible.java │ │ ├── DefaultFacetHandlerInitializerParam.java │ │ ├── FacetCountCollector.java │ │ ├── FacetCountCollectorSource.java │ │ ├── FacetHandler.java │ │ ├── FacetHandlerInitializerParam.java │ │ ├── RuntimeFacetHandler.java │ │ ├── RuntimeFacetHandlerFactory.java │ │ ├── attribute │ │ │ ├── AttributesFacetCountCollector.java │ │ │ ├── AttributesFacetHandler.java │ │ │ └── AttributesFacetIterator.java │ │ ├── data │ │ │ ├── FacetDataCache.java │ │ │ ├── FacetDataFetcher.java │ │ │ ├── MultiValueFacetDataCache.java │ │ │ ├── MultiValueWithWeightFacetDataCache.java │ │ │ ├── PredefinedTermListFactory.java │ │ │ ├── PrimitiveLongArrayWrapper.java │ │ │ ├── TermCharList.java │ │ │ ├── TermDateList.java │ │ │ ├── TermDoubleList.java │ │ │ ├── TermFixedLengthLongArrayList.java │ │ │ ├── TermFixedLengthLongArrayListFactory.java │ │ │ ├── TermFloatList.java │ │ │ ├── TermIntList.java │ │ │ ├── TermListFactory.java │ │ │ ├── TermLongList.java │ │ │ ├── TermNumberList.java │ │ │ ├── TermShortList.java │ │ │ ├── TermStringList.java │ │ │ └── TermValueList.java │ │ ├── filter │ │ │ ├── AdaptiveFacetFilter.java │ │ │ ├── AndFilter.java │ │ │ ├── BitSetFilter.java │ │ │ ├── CompactMultiValueFacetFilter.java │ │ │ ├── EmptyFilter.java │ │ │ ├── FacetFilter.java │ │ │ ├── FacetOrFilter.java │ │ │ ├── FacetRangeFilter.java │ │ │ ├── FacetValueConverter.java │ │ │ ├── GeoFacetFilter.java │ │ │ ├── GeoSimpleFacetFilter.java │ │ │ ├── MultiValueFacetFilter.java │ │ │ ├── MultiValueORFacetFilter.java │ │ │ ├── NotFilter.java │ │ │ ├── OrFilter.java │ │ │ ├── RandomAccessAndFilter.java │ │ │ ├── RandomAccessFilter.java │ │ │ ├── RandomAccessNotFilter.java │ │ │ └── RandomAccessOrFilter.java │ │ ├── impl │ │ │ ├── BucketFacetCountCollector.java │ │ │ ├── BucketFacetHandler.java │ │ │ ├── CombinedDoubleFacetIterator.java │ │ │ ├── CombinedFacetIterator.java │ │ │ ├── CombinedFloatFacetIterator.java │ │ │ ├── CombinedIntFacetIterator.java │ │ │ ├── CombinedLongFacetIterator.java │ │ │ ├── CombinedShortFacetIterator.java │ │ │ ├── ComboFacetHandler.java │ │ │ ├── CompactMultiValueFacetHandler.java │ │ │ ├── DefaultDoubleFacetIterator.java │ │ │ ├── DefaultFacetCountCollector.java │ │ │ ├── DefaultFacetIterator.java │ │ │ ├── DefaultFloatFacetIterator.java │ │ │ ├── DefaultIntFacetIterator.java │ │ │ ├── DefaultLongFacetIterator.java │ │ │ ├── DefaultShortFacetIterator.java │ │ │ ├── DynamicRangeFacetHandler.java │ │ │ ├── DynamicTimeRangeFacetHandler.java │ │ │ ├── FacetHandlerLoader.java │ │ │ ├── FacetHitcountComparatorFactory.java │ │ │ ├── FacetValueComparatorFactory.java │ │ │ ├── FilteredRangeFacetHandler.java │ │ │ ├── GeoFacetCountCollector.java │ │ │ ├── GeoFacetHandler.java │ │ │ ├── GeoSimpleFacetCountCollector.java │ │ │ ├── GeoSimpleFacetHandler.java │ │ │ ├── GroupByFacetCountCollector.java │ │ │ ├── HistogramFacetHandler.java │ │ │ ├── MultiValueFacetHandler.java │ │ │ ├── MultiValueWithWeightFacetHandler.java │ │ │ ├── MultiValuedPathFacetCountCollector.java │ │ │ ├── PathFacetCountCollector.java │ │ │ ├── PathFacetHandler.java │ │ │ ├── PathFacetIterator.java │ │ │ ├── RangeFacetCountCollector.java │ │ │ ├── RangeFacetHandler.java │ │ │ ├── SimpleFacetHandler.java │ │ │ ├── SimpleGroupbyFacetHandler.java │ │ │ └── VirtualSimpleFacetHandler.java │ │ ├── range │ │ │ ├── BitSetBuilder.java │ │ │ ├── MultiDataCacheBuilder.java │ │ │ ├── MultiRangeFacetHandler.java │ │ │ ├── SimpleDataCacheBuilder.java │ │ │ └── ValueConverterBitSetBuilder.java │ │ └── statistics │ │ │ ├── ChiSquaredFacetCountStatisticsGenerator.java │ │ │ ├── FacetCountStatisicsGenerator.java │ │ │ └── FacetCountStatistics.java │ │ ├── impl │ │ ├── BrowseServiceImpl.java │ │ ├── DefaultBrowseServiceImpl.java │ │ └── QueryProducer.java │ │ ├── index │ │ ├── BoboIndexer.java │ │ ├── MakeBobo.java │ │ └── digest │ │ │ ├── DataDigester.java │ │ │ └── FileDigester.java │ │ ├── jmx │ │ └── JMXUtil.java │ │ ├── mapred │ │ ├── BoboMapFunctionWrapper.java │ │ └── MapReduceResult.java │ │ ├── query │ │ ├── FacetBasedBoostScorerBuilder.java │ │ ├── MatchAllDocIdSetIterator.java │ │ ├── RecencyBoostScorerBuilder.java │ │ ├── ScoreAdjusterQuery.java │ │ ├── ScorerBuilder.java │ │ └── scoring │ │ │ ├── BoboDocScorer.java │ │ │ ├── DefaultFacetTermScoringFunction.java │ │ │ ├── DefaultFacetTermScoringFunctionFactory.java │ │ │ ├── FacetScoreable.java │ │ │ ├── FacetTermQuery.java │ │ │ ├── FacetTermScoringFunction.java │ │ │ ├── FacetTermScoringFunctionFactory.java │ │ │ ├── MultiplicativeFacetTermScoringFunction.java │ │ │ └── MultiplicativeFacetTermScoringFunctionFactory.java │ │ ├── search │ │ ├── BoboSearcher2.java │ │ ├── FacetHitCollector.java │ │ └── section │ │ │ ├── AbstractTerminalNode.java │ │ │ ├── AndNode.java │ │ │ ├── AndNotNode.java │ │ │ ├── IntMetaDataCache.java │ │ │ ├── IntMetaDataQuery.java │ │ │ ├── MetaDataCache.java │ │ │ ├── MetaDataCacheProvider.java │ │ │ ├── MetaDataQuery.java │ │ │ ├── OrNode.java │ │ │ ├── PhraseNode.java │ │ │ ├── SectionSearchQuery.java │ │ │ ├── SectionSearchQueryPlan.java │ │ │ ├── SectionSearchQueryPlanBuilder.java │ │ │ ├── TermNode.java │ │ │ └── UnaryNotNode.java │ │ ├── server │ │ └── qlog │ │ │ └── QueryLog.java │ │ ├── service │ │ ├── BoboService.java │ │ ├── BrowseQueryParser.java │ │ ├── BrowseService.java │ │ ├── BrowseServiceFactory.java │ │ ├── DefaultBrowseQueryParser.java │ │ └── HitCompareMulti.java │ │ ├── sort │ │ ├── DocComparator.java │ │ ├── DocComparatorSource.java │ │ ├── DocIDPriorityQueue.java │ │ ├── LuceneCustomDocComparatorSource.java │ │ ├── MultiDocIdComparator.java │ │ ├── MultiDocIdComparatorSource.java │ │ ├── ReverseDocComparatorSource.java │ │ ├── SortCollector.java │ │ └── SortCollectorImpl.java │ │ └── util │ │ ├── BigByteArray.java │ │ ├── BigFloatArray.java │ │ ├── BigIntArray.java │ │ ├── BigIntBuffer.java │ │ ├── BigNestedIntArray.java │ │ ├── BigSegmentedArray.java │ │ ├── BigShortArray.java │ │ ├── BitMath.java │ │ ├── BoundedPriorityQueue.java │ │ ├── DocIdSetUtil.java │ │ ├── FloatMatrix.java │ │ ├── GeoMatchUtil.java │ │ ├── IntBoundedPriorityQueue.java │ │ ├── IntMatrix.java │ │ ├── LazyBigIntArray.java │ │ ├── ListMerger.java │ │ ├── MemoryManager.java │ │ ├── MemoryManagerAdminMBean.java │ │ ├── MutableSparseFloatArray.java │ │ ├── PrimitiveMatrix.java │ │ ├── ResultMerger.java │ │ ├── SearchResultMerger.java │ │ ├── SparseFloatArray.java │ │ └── StringArrayComparator.java │ └── test │ └── java │ └── com │ └── browseengine │ └── bobo │ ├── facets │ ├── attribute │ │ └── AttributesFacetHandlerTest.java │ └── data │ │ └── TermLongListTest.java │ ├── test │ ├── BoboFacetIteratorTest.java │ ├── BoboTestCase.java │ ├── FacetHandlerTest.java │ ├── FacetMergePerf.java │ ├── FacetNameTest.java │ ├── FacetNotValuesTest.java │ ├── LucenePerf.java │ ├── MemoryUtil.java │ ├── StressTestSuite.java │ ├── TestPathMultiVal.java │ ├── UnitTestSuite.java │ └── section │ │ └── TestSectionSearch.java │ └── util │ └── test │ ├── BigIntArrayTest.java │ ├── BigNestedIntArrayTest.java │ ├── BigSegmentedArrayTest.java │ ├── FilterTest.java │ ├── IndexReaderWithMetaDataCache.java │ ├── MutableSparseFloatArrayTest.java │ └── SparseFloatArrayTest.java ├── bobo-contrib ├── README.TXT ├── TODO.TXT ├── build.gradle ├── pom.xml └── src │ ├── main │ └── java │ │ ├── com │ │ └── browseengine │ │ │ └── bobo │ │ │ └── geosearch │ │ │ ├── CartesianCoordinateDocId.java │ │ │ ├── GeoRecordUtil.java │ │ │ ├── GeoVersion.java │ │ │ ├── IDeletedDocs.java │ │ │ ├── IFieldNameFilterConverter.java │ │ │ ├── IGeoBlockOfHitsProvider.java │ │ │ ├── IGeoConverter.java │ │ │ ├── IGeoRecordIterator.java │ │ │ ├── IGeoRecordSerializer.java │ │ │ ├── IGeoUtil.java │ │ │ ├── bo │ │ │ ├── CartesianCoordinateUUID.java │ │ │ ├── CartesianGeoRecord.java │ │ │ ├── DocsSortedByDocId.java │ │ │ ├── GeRecordAndCartesianDocId.java │ │ │ ├── GeoSearchConfig.java │ │ │ ├── GeoSegmentInfo.java │ │ │ ├── IGeoRecord.java │ │ │ └── LatitudeLongitudeDocId.java │ │ │ ├── impl │ │ │ ├── BTree.java │ │ │ ├── CartesianGeoRecordComparator.java │ │ │ ├── CartesianGeoRecordCompareByDocId.java │ │ │ ├── CartesianGeoRecordSerializer.java │ │ │ ├── CostOfBTree.java │ │ │ ├── DeletedDocs.java │ │ │ ├── GeoBlockOfHitsProvider.java │ │ │ ├── GeoConverter.java │ │ │ ├── GeoRecordBTree.java │ │ │ ├── GeoUtil.java │ │ │ ├── IndexReaderDeletedDocs.java │ │ │ ├── IntBTree.java │ │ │ ├── MappedFieldNameFilterConverter.java │ │ │ ├── NoHitsIterator.java │ │ │ └── TreeIterator.java │ │ │ ├── index │ │ │ ├── IGeoIndexer.java │ │ │ ├── bo │ │ │ │ ├── GeoCoordinate.java │ │ │ │ └── GeoCoordinateField.java │ │ │ └── impl │ │ │ │ ├── DeletePairedExtensionDirectory.java │ │ │ │ ├── GeoIndexReader.java │ │ │ │ ├── GeoIndexer.java │ │ │ │ ├── GeoSegmentReader.java │ │ │ │ └── GeoSegmentWriter.java │ │ │ ├── merge │ │ │ ├── IGeoMergeInfo.java │ │ │ ├── IGeoMerger.java │ │ │ └── impl │ │ │ │ ├── BufferedGeoMerger.java │ │ │ │ ├── BufferedOrderedIterator.java │ │ │ │ ├── ChainedConvertedGeoRecordIterator.java │ │ │ │ ├── ConvertedGeoRecordIterator.java │ │ │ │ ├── OrderedIteratorChain.java │ │ │ │ └── PeekingIterator.java │ │ │ ├── query │ │ │ ├── GeoQuery.java │ │ │ ├── GeoScorer.java │ │ │ └── GeoWeight.java │ │ │ ├── score │ │ │ ├── IComputeDistance.java │ │ │ └── impl │ │ │ │ ├── CartesianComputeDistance.java │ │ │ │ ├── Conversions.java │ │ │ │ ├── HaversineComputeDistance.java │ │ │ │ └── HaversineFormula.java │ │ │ └── solo │ │ │ ├── bo │ │ │ ├── IDGeoRecord.java │ │ │ └── IndexTooLargeException.java │ │ │ ├── impl │ │ │ ├── IDGeoRecordComparator.java │ │ │ └── IDGeoRecordSerializer.java │ │ │ ├── index │ │ │ └── impl │ │ │ │ └── GeoOnlyIndexer.java │ │ │ └── search │ │ │ └── impl │ │ │ ├── GeoOnlyHit.java │ │ │ ├── GeoOnlyHitQueue.java │ │ │ ├── GeoOnlyHits.java │ │ │ └── GeoOnlySearcher.java │ │ └── org │ │ └── apache │ │ └── lucene │ │ └── index │ │ ├── GeoDocConsumer.java │ │ ├── GeoDocConsumerPerThread.java │ │ ├── GeoIndexWriter.java │ │ ├── GeoIndexingChain.java │ │ ├── GeoMergeInfo.java │ │ └── IndexWriter.java │ └── test │ ├── java │ ├── com │ │ └── browseengine │ │ │ └── bobo │ │ │ └── geosearch │ │ │ ├── impl │ │ │ ├── CartesianGeoRecordInterlaceTest.java │ │ │ ├── GeoConverterTest.java │ │ │ ├── GeoRecordBTreeTest.java │ │ │ ├── IDGeoRecordInterlaceTest.java │ │ │ ├── IGeoRecordSerializerTezt.java │ │ │ ├── IntBTreeTest.java │ │ │ ├── InterlaceTezt.java │ │ │ └── UserCaseTest.java │ │ │ ├── index │ │ │ └── impl │ │ │ │ ├── CartesianGeoRecordSerializerTest.java │ │ │ │ ├── GeoIndexerTest.java │ │ │ │ ├── GeoQueryTest.java │ │ │ │ ├── GeoSegmentReaderTest.java │ │ │ │ └── GeoSegmentWriterTest.java │ │ │ ├── merge │ │ │ └── impl │ │ │ │ ├── BufferedGeoMergerTest.java │ │ │ │ ├── MergeGeoRecordsTest.java │ │ │ │ └── Pair.java │ │ │ ├── query │ │ │ └── GeoScorerTest.java │ │ │ ├── score │ │ │ └── impl │ │ │ │ ├── CartesianComputeDistanceTest.java │ │ │ │ └── HaversineComputeDistanceTest.java │ │ │ └── solo │ │ │ ├── impl │ │ │ ├── IDGeoRecordComparatorTest.java │ │ │ └── IDGeoRecordSerializerTest.java │ │ │ ├── index │ │ │ └── impl │ │ │ │ └── GeoOnlyIndexerTest.java │ │ │ └── search │ │ │ └── impl │ │ │ ├── GeoOnlyHitQueueTest.java │ │ │ └── GeoOnlySearcherTest.java │ └── org │ │ └── apache │ │ └── lucene │ │ └── index │ │ ├── GeoDocConsumerPerThreadTest.java │ │ ├── GeoDocConsumerTest.java │ │ ├── GeoIndexingChainTest.java │ │ ├── GeoSearchFunctionalTezt.java │ │ ├── GeoSearchIndexingFunctionalTest.java │ │ ├── GeoSearchMergingFunctionalTest.java │ │ └── LuceneUtils.java │ └── resources │ └── TEST-servlet.xml ├── bobo-parent └── pom.xml ├── build.gradle ├── cardata ├── cartag │ ├── _cuy.cfs │ ├── bobo.spring │ ├── deletable │ └── segments ├── data │ └── dataout.txt └── facetvals.txt ├── cardemo ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── browseengine │ │ └── bobo │ │ ├── serialize │ │ ├── JSONExternalizable.java │ │ ├── JSONSerializable.java │ │ └── JSONSerializer.java │ │ ├── server │ │ └── protocol │ │ │ ├── BoboHttpRequestParam.java │ │ │ ├── BoboParams.java │ │ │ ├── BrowseJSONHandler.java │ │ │ ├── BrowseJSONSerializer.java │ │ │ ├── JSONHandler.java │ │ │ └── ProtocolHandler.java │ │ └── servlet │ │ └── BrowseServlet.java │ └── webapp │ ├── WEB-INF │ └── web.xml │ ├── application.js │ ├── bobobase.js │ ├── browse.js │ ├── demo-car.html │ ├── json.js │ ├── remote.js │ ├── style.css │ └── widgets.js ├── defaultEnvironment.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── pom.xml ├── resource └── log4j.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | bobo-browse/build/ 2 | bobo-browse/src/main/resources/ 3 | bobo-browse/target/ 4 | bobo-gwt/build/ 5 | bobo-service/build/ 6 | bobo-solr/build/ 7 | bobo-solr/target/ 8 | bobo-solr/src/main/resources/ 9 | build-test/ 10 | cardemo/target/ 11 | dist/ 12 | ivy/ 13 | doc 14 | output 15 | lib/gui/ 16 | lib/jetty/ 17 | lib/master 18 | lib/solr/ 19 | lib/test/ 20 | bobo-browse/MANIFEST.MF 21 | .settings 22 | TAGS 23 | *~ 24 | cscope.* 25 | bobo-contrib/target/ 26 | bobo-contrib/MANIFEST.MF 27 | .gradle 28 | build 29 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | bobo-perf-improvement 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | This software is licensed to you under the Apache License, Version 2.0 (the "Apache License") and certain other files provided with the software are licensed under the GNU Lesser General Public License v. 2.1 (the "LGPLv.2") and this notice does not apply to those separate files. LinkedIn's contributions are made under the Apache License. If you contribute to the software, the contributions will be deemed to have been made under the Apache License, unless you expressly indicate otherwise. Please do not make any contributions that would be inconsistent with the Apache License. You may obtain a copy of the Apache License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, this software distributed under the Apache License and is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for the specific language governing permissions and limitations for the software governed under the Apache License. 2 | 3 | © 2012 LinkedIn Corp. (and others as noted in the software). All Rights Reserved. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | What is Bobo 2 | =============== 3 | 4 | Bobo is a faceted search engine written in java. 5 | 6 | ------------------------------------ 7 | 8 | ### Wiki 9 | 10 | Wiki is available at: 11 | 12 | http://data.linkedin.com/opensource/bobo 13 | 14 | ### Issues 15 | 16 | Issues are tracked at: 17 | 18 | http://data.linkedin.com/opensource/bobo 19 | 20 | TO BUILD: 21 | ./gradlew build 22 | -------------------------------------------------------------------------------- /bobo-browse/.gitignore: -------------------------------------------------------------------------------- 1 | /.classpath 2 | /.project 3 | -------------------------------------------------------------------------------- /bobo-browse/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 externalDependency.luceneCore 12 | compile externalDependency.commonsCollections 13 | compile externalDependency.kamikaze 14 | compile externalDependency.springContext 15 | compile externalDependency.log4j 16 | compile externalDependency.commonsCli 17 | compile externalDependency.fastutil 18 | 19 | testCompile externalDependency.junit 20 | } 21 | 22 | -------------------------------------------------------------------------------- /bobo-browse/resource/log4j.properties: -------------------------------------------------------------------------------- 1 | log.home=./ 2 | log4j.rootLogger=info, console1 3 | 4 | log4j.appender.console1=org.apache.log4j.ConsoleAppender 5 | log4j.appender.console1.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.console1.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %p 7 | [%c] [%x] %m%n 8 | 9 | 10 | log4j.appender.server=org.apache.log4j.DailyRollingFileAppender 11 | log4j.appender.server.encoding=UTF-8 12 | 13 | log4j.appender.server.File=${log.home}/bobo-root.log 14 | 15 | log4j.appender.server.DatePattern='.'yyyy-MM-dd 16 | 17 | log4j.appender.server.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.server.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %p [%c{1}] [%x] %m%n 19 | 20 | log4j.appender.bobo=org.apache.log4j.DailyRollingFileAppender 21 | log4j.appender.bobo.encoding=UTF-8 22 | log4j.appender.bobo.File=${log.home}/bobo-browse.log 23 | 24 | log4j.appender.bobo.DatePattern='.'yyyy-MM-dd 25 | 26 | 27 | log4j.appender.bobo.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.bobo.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %p [%c] [%x] %m%n 29 | 30 | log4j.logger.com.browseengine.bobo=info, bobo 31 | 32 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/BoboCustomSortField.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.api; 21 | 22 | import org.apache.lucene.search.SortField; 23 | 24 | import com.browseengine.bobo.sort.DocComparatorSource; 25 | 26 | public class BoboCustomSortField extends SortField { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | private final DocComparatorSource _factory; 31 | 32 | public BoboCustomSortField(String field,boolean reverse,DocComparatorSource factory) { 33 | super(field, SortField.CUSTOM, reverse); 34 | _factory = factory; 35 | } 36 | 37 | public DocComparatorSource getCustomComparatorSource(){ 38 | return _factory; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/BrowseException.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.api; 21 | 22 | public class BrowseException extends Exception{ 23 | /** 24 | * 25 | */ 26 | private static final long serialVersionUID = 1L; 27 | 28 | public BrowseException(String msg){ 29 | this(msg,null); 30 | } 31 | 32 | public BrowseException(String msg,Throwable cause){ 33 | super(msg,cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/ComparatorFactory.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.api; 21 | 22 | import java.util.Comparator; 23 | 24 | import com.browseengine.bobo.util.BigSegmentedArray; 25 | import com.browseengine.bobo.util.IntBoundedPriorityQueue.IntComparator; 26 | 27 | /** 28 | * Comparator for custom sorting a facet value 29 | * @author jwang 30 | */ 31 | public interface ComparatorFactory{ 32 | /** 33 | * Providers a Comparator from field values and counts. This is called within a browse. 34 | * @param fieldValueAccessor accessor for field values 35 | * @param counts hit counts 36 | * @return Comparator instance 37 | */ 38 | IntComparator newComparator(FieldValueAccessor fieldValueAccessor,BigSegmentedArray counts); 39 | 40 | /** 41 | * Providers a Comparator. This is called when doing a merge across browses. 42 | * @return Comparator instance 43 | */ 44 | Comparator newComparator(); 45 | } 46 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/DoubleFacetIterator.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.api; 21 | 22 | /** 23 | * @author "Xiaoyang Gu" 24 | * 25 | */ 26 | public abstract class DoubleFacetIterator extends FacetIterator 27 | { 28 | public double facet; 29 | public abstract double nextDouble(); 30 | public abstract double nextDouble(int minHits); 31 | public abstract String format(double val); 32 | } 33 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/FacetAccessible.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.api; 21 | 22 | import java.util.List; 23 | 24 | public interface FacetAccessible 25 | { 26 | /** 27 | * Gets gathered top facets 28 | * @return list of facets 29 | */ 30 | List getFacets(); 31 | 32 | /** 33 | * Gets the facet given a value. This is a way for random accessing 34 | * into the facet data structure. 35 | * @param value Facet value 36 | * @return a facet with count filled in 37 | */ 38 | BrowseFacet getFacet(String value); 39 | 40 | /** 41 | * Gets the facet count given a value. This is a way for random 42 | * accessing the facet count. 43 | * @param value Facet value 44 | * @return a facet with count filled in 45 | */ 46 | int getFacetHitsCount(Object value); 47 | 48 | /** 49 | * Responsible for release resources used. If the implementing class 50 | * does not use a lot of resources, 51 | * it does not have to do anything. 52 | */ 53 | public void close(); 54 | 55 | /** 56 | * Returns an iterator to visit all the facets 57 | * @return Returns a FacetIterator to iterate over all the facets 58 | */ 59 | FacetIterator iterator(); 60 | } 61 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/FacetIterator.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.api; 21 | 22 | import java.util.Iterator; 23 | 24 | /** 25 | * Iterator to iterate over facets 26 | * @author nnarkhed 27 | */ 28 | public abstract class FacetIterator implements Iterator{ 29 | 30 | public int count; 31 | public Comparable facet; 32 | 33 | /** 34 | * Moves the iteration to the next facet 35 | * @return the next facet value 36 | */ 37 | public abstract Comparable next(); 38 | 39 | /** 40 | * Moves the iteration to the next facet whose hitcount >= minHits. returns null if there is no facet whose hitcount >= minHits. 41 | * Hence while using this method, it is useless to use hasNext() with it. 42 | * After the next() method returns null, calling it repeatedly would result in undefined behavior 43 | * @return The next facet value. It returns null if there is no facet whose hitcount >= minHits. 44 | */ 45 | public abstract Comparable next(int minHits); 46 | public abstract String format(Object val); 47 | } 48 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/FieldValueAccessor.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.api; 21 | 22 | public interface FieldValueAccessor { 23 | String getFormatedValue(int index); 24 | Object getRawValue(int index); 25 | } 26 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/FloatFacetIterator.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.api; 21 | 22 | /** 23 | * @author "Xiaoyang Gu" 24 | * 25 | */ 26 | public abstract class FloatFacetIterator extends FacetIterator 27 | { 28 | public float facet; 29 | public abstract float nextFloat(); 30 | public abstract float nextFloat(int minHits); 31 | public abstract String format(float val); 32 | } 33 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/IntFacetIterator.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.api; 21 | 22 | public abstract class IntFacetIterator extends FacetIterator 23 | { 24 | public int facet; 25 | public abstract int nextInt(); 26 | public abstract int nextInt(int minHits); 27 | public abstract String format(int val); 28 | } 29 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/LongFacetIterator.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.api; 21 | 22 | /** 23 | * @author "Xiaoyang Gu" 24 | * 25 | */ 26 | public abstract class LongFacetIterator extends FacetIterator 27 | { 28 | public long facet; 29 | public abstract long nextLong(); 30 | public abstract long nextLong(int minHits); 31 | public abstract String format(long val); 32 | } 33 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/MappedFacetAccessible.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.api; 21 | 22 | import java.io.Serializable; 23 | import java.util.Arrays; 24 | import java.util.HashMap; 25 | import java.util.Iterator; 26 | import java.util.List; 27 | 28 | import com.browseengine.bobo.facets.impl.PathFacetIterator; 29 | 30 | public class MappedFacetAccessible implements FacetAccessible, Serializable { 31 | 32 | /** 33 | * 34 | */ 35 | private static final long serialVersionUID = 1L; 36 | 37 | private final HashMap _facetMap; 38 | private final BrowseFacet[] _facets; 39 | 40 | public MappedFacetAccessible(BrowseFacet[] facets){ 41 | _facetMap = new HashMap(); 42 | for (BrowseFacet facet : facets){ 43 | _facetMap.put(facet.getValue(), facet); 44 | } 45 | _facets = facets; 46 | } 47 | 48 | public BrowseFacet getFacet(String value) { 49 | return _facetMap.get(value); 50 | } 51 | 52 | public int getFacetHitsCount(Object value) 53 | { 54 | BrowseFacet facet = _facetMap.get(value); 55 | if (facet != null) 56 | return facet.getHitCount(); 57 | return 0; 58 | } 59 | 60 | public List getFacets() { 61 | return Arrays.asList(_facets); 62 | } 63 | 64 | public void close() 65 | { 66 | // TODO Auto-generated method stub 67 | 68 | } 69 | 70 | public FacetIterator iterator() { 71 | return new PathFacetIterator(Arrays.asList(_facets)); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /bobo-browse/src/main/java/com/browseengine/bobo/api/ShortFacetIterator.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.api; 21 | 22 | /** 23 | * @author "Xiaoyang Gu" 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 _filters; 38 | 39 | public AndFilter(List 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 _filters; 39 | 40 | public OrFilter(List 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 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 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 7 | { 8 | 9 | @Override 10 | public int compare(Object o1, Object o2) { 11 | GeoConverter gc = new GeoConverter(); 12 | CartesianCoordinateDocId ccdid1 = gc.toCartesianCoordinateDocId((CartesianGeoRecord)o1); 13 | CartesianCoordinateDocId ccdid2 = gc.toCartesianCoordinateDocId((CartesianGeoRecord)o2); 14 | int diff = ccdid1.docid - ccdid2.docid; 15 | if(diff < 0) { 16 | return 1; 17 | } else if (diff > 0) { 18 | return -1; 19 | } 20 | return 0; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/impl/CartesianGeoRecordSerializer.java: -------------------------------------------------------------------------------- 1 | package com.browseengine.bobo.geosearch.impl; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.lucene.store.IndexInput; 6 | import org.apache.lucene.store.IndexOutput; 7 | 8 | import com.browseengine.bobo.geosearch.IGeoRecordSerializer; 9 | import com.browseengine.bobo.geosearch.bo.CartesianGeoRecord; 10 | 11 | /** 12 | * Basic Serializer for CartesianGeoRecords 13 | * 14 | * @author gcooney 15 | * 16 | */ 17 | public class CartesianGeoRecordSerializer implements IGeoRecordSerializer { 18 | 19 | @Override 20 | public void writeGeoRecord(IndexOutput output, CartesianGeoRecord record, int recordByteCount) throws IOException { 21 | output.writeLong(record.highOrder); 22 | output.writeLong(record.lowOrder); 23 | output.writeByte(record.filterByte); 24 | } 25 | 26 | @Override 27 | public CartesianGeoRecord readGeoRecord(IndexInput input, int recordByteCount) throws IOException { 28 | return new CartesianGeoRecord(input.readLong(), 29 | input.readLong(), 30 | input.readByte()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/impl/DeletedDocs.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.impl; 21 | 22 | import com.browseengine.bobo.geosearch.IDeletedDocs; 23 | 24 | /** 25 | * Retrieves isDeleted for relative space. 26 | * Retrieves isDeleted for relative docidWithinSegments by using the 27 | * global wholeIndexDeletedDocs and firstDocIdInSegment 28 | * offsets. 29 | * 30 | * @author Ken McCracken 31 | * 32 | */ 33 | public class DeletedDocs implements IDeletedDocs { 34 | 35 | private IDeletedDocs wholeIndexDeletedDocs; 36 | 37 | private int firstDocIdInSegment; 38 | 39 | public DeletedDocs(IDeletedDocs wholeIndexDeletedDocs, int firstDocIdInSegment) { 40 | this.wholeIndexDeletedDocs = wholeIndexDeletedDocs; 41 | this.firstDocIdInSegment = firstDocIdInSegment; 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public boolean isDeleted(int docidWithinSegment) { 49 | int globalDocId = docidWithinSegment + firstDocIdInSegment; 50 | return wholeIndexDeletedDocs.isDeleted(globalDocId); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/impl/IndexReaderDeletedDocs.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.impl; 21 | 22 | import org.apache.lucene.index.IndexReader; 23 | 24 | import com.browseengine.bobo.geosearch.IDeletedDocs; 25 | 26 | /** 27 | * @author Ken McCracken 28 | * 29 | */ 30 | public class IndexReaderDeletedDocs implements IDeletedDocs { 31 | 32 | private IndexReader indexReader; 33 | 34 | public IndexReaderDeletedDocs(IndexReader indexReader) { 35 | this. indexReader = indexReader; 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public boolean isDeleted(int docid) { 43 | return indexReader.isDeleted(docid); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/impl/NoHitsIterator.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.impl; 21 | 22 | import java.util.Iterator; 23 | import java.util.NoSuchElementException; 24 | 25 | public class NoHitsIterator implements Iterator { 26 | 27 | /** 28 | * {@inheritDoc} 29 | */ 30 | @Override 31 | public boolean hasNext() { 32 | return false; 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public T next() { 40 | throw new NoSuchElementException(); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public void remove() { 48 | throw new UnsupportedOperationException(); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/index/IGeoIndexer.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.index; 21 | 22 | import java.io.IOException; 23 | 24 | import org.apache.lucene.store.Directory; 25 | 26 | import com.browseengine.bobo.geosearch.index.bo.GeoCoordinateField; 27 | 28 | public interface IGeoIndexer { 29 | void index(int docID, GeoCoordinateField field); 30 | 31 | void abort(); 32 | 33 | void flush(Directory directory, String segmentName) throws IOException; 34 | } 35 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/merge/IGeoMergeInfo.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.merge; 21 | 22 | import java.util.List; 23 | 24 | import org.apache.lucene.index.MergePolicy.MergeAbortedException; 25 | import org.apache.lucene.index.SegmentInfo; 26 | import org.apache.lucene.index.SegmentReader; 27 | import org.apache.lucene.store.Directory; 28 | 29 | public interface IGeoMergeInfo { 30 | 31 | void checkAborted(Directory dir) throws MergeAbortedException; 32 | 33 | List getReaders(); 34 | 35 | List getSegmentsToMerge(); 36 | 37 | Directory getDirectory(); 38 | 39 | SegmentInfo getNewSegment(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/merge/IGeoMerger.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.merge; 21 | 22 | import java.io.IOException; 23 | 24 | 25 | import com.browseengine.bobo.geosearch.bo.GeoSearchConfig; 26 | 27 | public interface IGeoMerger { 28 | void merge(IGeoMergeInfo geoMergeInfo, GeoSearchConfig config) throws IOException; 29 | } 30 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/merge/impl/PeekingIterator.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.merge.impl; 21 | 22 | import java.util.Iterator; 23 | import java.util.NoSuchElementException; 24 | 25 | public class PeekingIterator implements Iterator { 26 | private T next; 27 | private Iterator iterator; 28 | 29 | public PeekingIterator(Iterator iterator) { 30 | this.iterator = iterator; 31 | advance(); 32 | } 33 | 34 | private void advance() { 35 | this.next = iterator.hasNext() ? iterator.next() : null; 36 | } 37 | 38 | public T peek() { 39 | return next; 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public boolean hasNext() { 47 | return next != null; 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | @Override 54 | public T next() { 55 | T localNext = next; 56 | if (localNext == null) { 57 | throw new NoSuchElementException(); 58 | } 59 | advance(); 60 | return localNext; 61 | } 62 | 63 | /** 64 | * {@inheritDoc} 65 | */ 66 | @Override 67 | public void remove() { 68 | throw new UnsupportedOperationException(); 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/score/impl/CartesianComputeDistance.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.score.impl; 21 | 22 | /** 23 | * 24 | * @author gcooney 25 | * @author shandets 26 | * 27 | */ 28 | public class CartesianComputeDistance { 29 | 30 | public static float computeDistanceSquared(int x1, int y1, int z1, 31 | int x2, int y2, int z2) { 32 | float xDiff = ((float)x1 - (float)x2); 33 | float yDiff = ((float)y1 - (float)y2); 34 | float zDiff = ((float)z1 - (float)z2); 35 | 36 | return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff; 37 | } 38 | 39 | public static float computeDistance(int x1, int y1, int z1, 40 | int x2, int y2, int z2) { 41 | return (float) Math.sqrt(computeDistanceSquared(x1, y1, z1, x2, y2, z2)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/solo/bo/IndexTooLargeException.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.solo.bo; 21 | 22 | public class IndexTooLargeException extends Exception { 23 | private static final long serialVersionUID = 1L; 24 | 25 | public IndexTooLargeException(String indexName, int indexSize, int maxSize) { 26 | super("This index is larger than the maximum allowed index size and will not be flushed to disk" + 27 | ". IndexName:" + indexName + "; Actual index size: " + indexSize 28 | + "; Max index size: " + maxSize); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/solo/impl/IDGeoRecordComparator.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.solo.impl; 21 | 22 | import java.util.Comparator; 23 | 24 | import com.browseengine.bobo.geosearch.solo.bo.IDGeoRecord; 25 | 26 | /** 27 | * 28 | * @author gcooney 29 | * 30 | */ 31 | public class IDGeoRecordComparator implements Comparator { 32 | 33 | @Override 34 | public int compare(IDGeoRecord idGeoRecord1, IDGeoRecord idGeoRecord2) { 35 | long diff = idGeoRecord1.highOrder - idGeoRecord2.highOrder; 36 | if (diff > 0) { 37 | return 1; 38 | } 39 | if (diff < 0) { 40 | return -1; 41 | } 42 | int idiff = idGeoRecord1.lowOrder - idGeoRecord2.lowOrder; 43 | if(idiff > 0) { 44 | return 1; 45 | } 46 | if (idiff < 0) { 47 | return -1; 48 | } 49 | 50 | for (int i = 0; i < idGeoRecord1.id.length && i < idGeoRecord2.id.length; i++) { 51 | if (idGeoRecord1.id[i] > idGeoRecord2.id[i]) { 52 | return 1; 53 | } else if (idGeoRecord1.id[i] < idGeoRecord2.id[i]) { 54 | return -1; 55 | } 56 | } 57 | 58 | if (idGeoRecord1.id.length > idGeoRecord2.id.length) { 59 | return 1; 60 | } else if (idGeoRecord1.id.length < idGeoRecord2.id.length) { 61 | return -1; 62 | } 63 | 64 | return 0; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/solo/search/impl/GeoOnlyHit.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.solo.search.impl; 21 | 22 | /** 23 | * 24 | * @author gcooney 25 | * 26 | */ 27 | public class GeoOnlyHit { 28 | 29 | public final float score; 30 | public final byte[] uuid; 31 | 32 | public GeoOnlyHit(float score, byte[] uuid) { 33 | this.score = score; 34 | this.uuid = uuid; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/solo/search/impl/GeoOnlyHitQueue.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.solo.search.impl; 21 | 22 | import org.apache.lucene.util.PriorityQueue; 23 | 24 | /** 25 | * 26 | * @author gcooney 27 | * 28 | */ 29 | public class GeoOnlyHitQueue extends PriorityQueue { 30 | 31 | public GeoOnlyHitQueue(int size) { 32 | initialize(size); 33 | } 34 | 35 | @Override 36 | protected boolean lessThan(GeoOnlyHit hitA, GeoOnlyHit hitB) { 37 | return hitA.score > hitB.score; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/com/browseengine/bobo/geosearch/solo/search/impl/GeoOnlyHits.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.solo.search.impl; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | /** 27 | * 28 | * @author gcooney 29 | * 30 | */ 31 | public final class GeoOnlyHits { 32 | private final int totalHits; 33 | private final List hits; 34 | 35 | public GeoOnlyHits(int totalHits, GeoOnlyHit[] hits) { 36 | this.totalHits = totalHits; 37 | this.hits = new ArrayList(hits.length); 38 | Collections.addAll(this.hits, hits); 39 | } 40 | 41 | public int totalHits() { 42 | return totalHits; 43 | } 44 | 45 | public List getHits() { 46 | return hits; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /bobo-contrib/src/main/java/org/apache/lucene/index/GeoIndexingChain.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 org.apache.lucene.index; 21 | 22 | import org.apache.lucene.index.DocumentsWriter.IndexingChain; 23 | 24 | import com.browseengine.bobo.geosearch.bo.GeoSearchConfig; 25 | 26 | 27 | /** 28 | * Implementation of lucene IndexingChain class. The GeoIndexingChain class 29 | * takes another indexing chain in the constructor. It adds a custom GeoDocConsumer 30 | * which wraps the default indexing chain's consumer to pull out geo components 31 | * from the document and index them independently, before returning control to the 32 | * default Consumer. 33 | * 34 | * @author Geoff Cooney 35 | * 36 | */ 37 | public class GeoIndexingChain extends IndexingChain { 38 | 39 | IndexingChain defaultIndexingChain; 40 | GeoSearchConfig config; 41 | 42 | public GeoIndexingChain(GeoSearchConfig config, IndexingChain defaultIndexingChain) { 43 | this.defaultIndexingChain = defaultIndexingChain; 44 | this.config = config; 45 | } 46 | 47 | @Override 48 | DocConsumer getChain(DocumentsWriter documentsWriter) { 49 | DocConsumer defaultDocConsumer = defaultIndexingChain.getChain(documentsWriter); 50 | return new GeoDocConsumer(config, defaultDocConsumer); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /bobo-contrib/src/test/java/com/browseengine/bobo/geosearch/merge/impl/Pair.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.merge.impl; 21 | 22 | /** 23 | * @author Ken McCracken 24 | * 25 | */ 26 | public class Pair { 27 | T one; 28 | U two; 29 | 30 | Pair(T one, U two) { 31 | this.one = one; 32 | this.two = two; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /bobo-contrib/src/test/java/org/apache/lucene/index/LuceneUtils.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 org.apache.lucene.index; 21 | 22 | import org.apache.lucene.store.Directory; 23 | 24 | public class LuceneUtils { 25 | 26 | public static SegmentInfo buildSegmentInfo(String name, int docCount, int delCount, Directory dir) { 27 | boolean isCompoundFile = true; 28 | boolean hasSingleNormFile = true; 29 | boolean hasProx = true; 30 | boolean hasVectors = true; 31 | SegmentInfo segment = new SegmentInfo(name, docCount, dir, isCompoundFile, hasSingleNormFile, hasProx, hasVectors); 32 | segment.setDelCount(delCount); 33 | 34 | return segment; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /bobo-contrib/src/test/resources/TEST-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | ext.isDefaultEnvironment = !project.hasProperty('overrideBuildEnvironment') 2 | 3 | File getEnvironmentScript() 4 | { 5 | final File env = file(isDefaultEnvironment ? 'defaultEnvironment.gradle' : project.overrideBuildEnvironment) 6 | assert env.isFile() : "The environment script [$env] does not exists or is not a file." 7 | return env 8 | } 9 | 10 | apply from: environmentScript 11 | 12 | ext.externalDependency = [ 13 | 'luceneCore': 'org.apache.lucene:lucene-core:3.5.0', 14 | 'commonsCollections': 'commons-collections:commons-collections:3.2', 15 | 'kamikaze': 'com.linkedin.kamikaze:kamikaze:3.0.6', 16 | 'springContext': 'org.springframework:spring-context:3.0.7.RELEASE', 17 | 'log4j':'log4j:log4j:1.2.13', 18 | 'commonsCli': 'commons-cli:commons-cli:1.2', 19 | 'fastutil': 'fastutil:fastutil:5.0.5', 20 | 'junit': 'junit:junit:4.5' 21 | ]; 22 | 23 | subprojects { 24 | } 25 | 26 | -------------------------------------------------------------------------------- /cardata/cartag/_cuy.cfs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInAttic/bobo/f90e48b0c90f72e8611a8a2af239c1993897b75e/cardata/cartag/_cuy.cfs -------------------------------------------------------------------------------- /cardata/cartag/deletable: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cardata/cartag/segments: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInAttic/bobo/f90e48b0c90f72e8611a8a2af239c1993897b75e/cardata/cartag/segments -------------------------------------------------------------------------------- /cardemo/src/main/java/com/browseengine/bobo/serialize/JSONExternalizable.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.serialize; 21 | 22 | import org.json.JSONException; 23 | import org.json.JSONObject; 24 | 25 | public interface JSONExternalizable extends JSONSerializable { 26 | JSONObject toJSON() throws JSONSerializationException,JSONException; 27 | void fromJSON(JSONObject obj) throws JSONSerializationException,JSONException; 28 | } 29 | -------------------------------------------------------------------------------- /cardemo/src/main/java/com/browseengine/bobo/serialize/JSONSerializable.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.serialize; 27 | 28 | /** 29 | * Marker interface 30 | */ 31 | public interface JSONSerializable { 32 | public static class JSONSerializationException extends Exception{ 33 | /** 34 | * 35 | */ 36 | private static final long serialVersionUID = 1L; 37 | 38 | public JSONSerializationException(String msg,Throwable cause){ 39 | super(msg,cause); 40 | } 41 | 42 | public JSONSerializationException(String msg){ 43 | super(msg); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cardemo/src/main/java/com/browseengine/bobo/server/protocol/BoboHttpRequestParam.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.protocol; 21 | 22 | import java.util.Iterator; 23 | 24 | import javax.servlet.http.HttpServletRequest; 25 | 26 | import org.apache.solr.common.params.SolrParams; 27 | 28 | public class BoboHttpRequestParam extends SolrParams { 29 | private HttpServletRequest _req; 30 | public BoboHttpRequestParam(HttpServletRequest req) { 31 | _req=req; 32 | } 33 | 34 | @Override 35 | public String get(String name) { 36 | return _req.getParameter(name); 37 | } 38 | 39 | @Override 40 | public Iterator getParameterNamesIterator() { 41 | return _req.getParameterMap().keySet().iterator(); 42 | } 43 | 44 | @Override 45 | public String[] getParams(String param) { 46 | return _req.getParameterValues(param); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /cardemo/src/main/java/com/browseengine/bobo/server/protocol/BoboParams.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.protocol; 21 | 22 | import java.util.Iterator; 23 | 24 | public abstract class BoboParams { 25 | abstract public String get(String name); 26 | abstract public String[] getStrings(String name); 27 | abstract public Iterator getParamNames(); 28 | 29 | public String getString(String name,boolean required){ 30 | String retVal=get(name); 31 | if (retVal==null && required){ 32 | throw new IllegalArgumentException("parameter "+name+" does not exist"); 33 | } 34 | return retVal; 35 | } 36 | public boolean getBool(String name,boolean defaultVal){ 37 | String retVal=getString(name,false); 38 | if (retVal!=null){ 39 | return Boolean.parseBoolean(retVal); 40 | } 41 | else{ 42 | return defaultVal; 43 | } 44 | } 45 | 46 | public String getString(String name){ 47 | return getString(name,false); 48 | } 49 | 50 | public String getString(String name,String defaultVal){ 51 | String retVal=get(name); 52 | if (retVal==null) return defaultVal; 53 | return retVal; 54 | } 55 | 56 | public int getInt(String name,boolean required){ 57 | String retVal=getString(name,required); 58 | return Integer.parseInt(retVal); 59 | } 60 | 61 | public int getInt(String name,int defaultVal){ 62 | String retVal=getString(name,false); 63 | try{ 64 | return Integer.parseInt(retVal); 65 | } 66 | catch(Exception e){ 67 | return defaultVal; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /cardemo/src/main/java/com/browseengine/bobo/server/protocol/ProtocolHandler.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.protocol; 21 | 22 | import java.io.IOException; 23 | import java.util.HashMap; 24 | 25 | import javax.servlet.http.HttpServletRequest; 26 | 27 | public abstract class ProtocolHandler { 28 | abstract public Object deserializeRequest(Class reqClass,HttpServletRequest req) throws IOException; 29 | 30 | abstract public Object deserializeRequest(Class reqClass,byte[] req) throws IOException; 31 | abstract public byte[] serializeResult(Object result) throws IOException; 32 | 33 | abstract public String getSupportedProtocol(); 34 | 35 | private static final HashMap Registry=new HashMap(); 36 | 37 | static{ 38 | //JSONProtocolHandler handler=new JSONProtocolHandler(); 39 | //Registry.put(handler.getSupportedProtocol(), handler); 40 | } 41 | 42 | public static void registerProtocolHandler(ProtocolHandler handler){ 43 | synchronized(Registry){ 44 | Registry.put(handler.getSupportedProtocol(), handler); 45 | } 46 | } 47 | 48 | public static ProtocolHandler getProtocolHandler(String protocol){ 49 | return Registry.get(protocol); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cardemo/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | index.dir 9 | ../cardata/cartag 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Cardemo 19 | com.browseengine.bobo.servlet.BrowseServlet 20 | 21 | debug 22 | true 23 | 24 | 2 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Cardemo 33 | /browse/* 34 | 35 | 36 | -------------------------------------------------------------------------------- /cardemo/src/main/webapp/demo-car.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 32 | 33 | 34 | 37 | 38 |
26 | Cars Found: 27 | 29 | e.g. red AND ferrari 30 | 31 |
35 | reset all 36 |
39 | 40 | 41 | 42 | 45 | 48 | 49 |
43 |
44 |
46 |
47 |
50 | 51 |
52 | 53 | 54 | 55 | 58 | 61 | 64 | 67 | 70 |
56 |
57 |
59 |
60 |
62 |
63 |
65 |
66 |
68 |
69 |
71 | 72 |
73 | 74 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /cardemo/src/main/webapp/remote.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function createRequestObject(){ 4 | var req; 5 | if (window.XMLHttpRequest) { 6 | req = new XMLHttpRequest(); 7 | 8 | // branch for IE/Windows ActiveX version 9 | } else if (window.ActiveXObject) { 10 | req = new ActiveXObject("Microsoft.XMLHTTP"); 11 | } 12 | return req; 13 | } 14 | 15 | function JSONRPC(url){ 16 | this.url=url; 17 | this.sndReq=function(action,request,callback,isXML) { 18 | var reqser=request.toHttpGetString(); 19 | if (!isXML){ 20 | reqser=reqser+"&output=json"; 21 | } 22 | //var path=url+action+"/"; 23 | 24 | var path=url+reqser; 25 | var http=createRequestObject(); 26 | http.onreadystatechange = function(){ 27 | if(http.readyState == 4){ 28 | var response; 29 | if (isXML){ 30 | response=http.responseXML; 31 | } 32 | else{ 33 | response = http.responseText; 34 | } 35 | callback(response); 36 | } 37 | } 38 | 39 | try{ 40 | http.open("GET", path,true); 41 | //http.send(reqser); 42 | http.send(""); 43 | } 44 | catch(e){ 45 | alert(e); 46 | } 47 | /* 48 | try{ 49 | http.open("POST", path,true); 50 | http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8'); 51 | 52 | var params="proto=browsejson&"+"reqstring="+reqser; 53 | http.send(params); 54 | } 55 | catch(e){ 56 | alert(e); 57 | }*/ 58 | } 59 | } 60 | 61 | function BoboAPI(url){ 62 | this.transport=new JSONRPC(url); 63 | this.browse=function(browsereq,callback){ 64 | this.transport.sndReq("browse",browsereq,callback,false); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cardemo/src/main/webapp/style.css: -------------------------------------------------------------------------------- 1 | 2 | .tag1{ 3 | font-family: Arial; 4 | font-size:12px; 5 | } 6 | 7 | .tag2{ 8 | font-family: Arial; 9 | font-size:14px; 10 | } 11 | 12 | .tag3{ 13 | font-family: Arial; 14 | font-size:16px; 15 | } 16 | .tag4{ 17 | font-family: Arial; 18 | font-size:18px; 19 | } 20 | .tag5{ 21 | font-family: Arial; 22 | font-size:20px; 23 | } 24 | .tag6{ 25 | font-family: Arial; 26 | font-size:22px; 27 | } 28 | .tag7{ 29 | font-family: Arial; 30 | font-size:24px; 31 | } 32 | .tag8{ 33 | font-family: Arial; 34 | font-size:26px; 35 | } 36 | .tag9{ 37 | font-family: Arial; 38 | font-size:28px; 39 | } 40 | .tag10{ 41 | font-family: Arial; 42 | font-size:30px; 43 | } 44 | 45 | 46 | .BREADCRUMB{ 47 | font-weight:normal; 48 | color:blue; 49 | } 50 | 51 | .ROWHEAD{ 52 | background-color:#AAAAEF; 53 | } 54 | 55 | .LINKSELECTED { 56 | font-weight:bold; 57 | color:blue; 58 | font-size:15px; 59 | } 60 | 61 | .hitstat{ 62 | font-family: Arial; 63 | color:#8888ef; 64 | } 65 | 66 | .scroll{ 67 | font-size:12px; 68 | color:black; 69 | } 70 | 71 | .sortable{ 72 | color:black; 73 | text-decoration: underline; 74 | } 75 | 76 | #resultset a{ 77 | text-decoration: underline; 78 | color:blue; 79 | } 80 | 81 | body { 82 | font-family: Arial; 83 | } 84 | 85 | .SELECTELEM{ 86 | text-align:left; 87 | font-size:12px; 88 | } 89 | 90 | .SELECTELEM LI{ 91 | 92 | list-style-type: none; 93 | } 94 | 95 | 96 | .text{ 97 | font-size:12px; 98 | } 99 | -------------------------------------------------------------------------------- /defaultEnvironment.gradle: -------------------------------------------------------------------------------- 1 | subprojects { 2 | repositories { 3 | mavenCentral() 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version = 3.1.18 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInAttic/bobo/f90e48b0c90f72e8611a8a2af239c1993897b75e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 25 11:29:56 PST 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.2-bin.zip 7 | -------------------------------------------------------------------------------- /resource/log4j.properties: -------------------------------------------------------------------------------- 1 | log.home=./ 2 | log4j.rootLogger=info, console1 3 | 4 | log4j.appender.console1=org.apache.log4j.ConsoleAppender 5 | log4j.appender.console1.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.console1.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %p 7 | [%c] [%x] %m%n 8 | 9 | 10 | log4j.appender.server=org.apache.log4j.DailyRollingFileAppender 11 | log4j.appender.server.encoding=UTF-8 12 | 13 | log4j.appender.server.File=${log.home}/bobo-root.log 14 | 15 | log4j.appender.server.DatePattern='.'yyyy-MM-dd 16 | 17 | log4j.appender.server.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.server.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %p [%c{1}] [%x] %m%n 19 | 20 | log4j.appender.bobo=org.apache.log4j.DailyRollingFileAppender 21 | log4j.appender.bobo.encoding=UTF-8 22 | log4j.appender.bobo.File=${log.home}/bobo-browse.log 23 | 24 | log4j.appender.bobo.DatePattern='.'yyyy-MM-dd 25 | 26 | 27 | log4j.appender.bobo.layout=org.apache.log4j.PatternLayout 28 | log4j.appender.bobo.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %p [%c] [%x] %m%n 29 | 30 | log4j.logger.com.browseengine.bobo=info, bobo 31 | 32 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include "bobo-browse" 2 | include "bobo-contrib" 3 | 4 | // only here for the eclipse plugin to generate project files when running mint eclipse 5 | include "bin" 6 | --------------------------------------------------------------------------------