├── .gitignore ├── AUP2 ├── chapter1.md ├── chapter10.md ├── chapter11.md ├── chapter3.md ├── chapter4.md ├── chapter5.md ├── chapter7.md ├── chapter8.md ├── images │ ├── chapter3_1.png │ ├── chapter3_2.png │ ├── chapter7_1.png │ ├── chapter7_3.png │ ├── chapter8_1.png │ └── 未命名 1.odp ├── index.md └── 无标题文档 1~ ├── README.md ├── aws_tutorial └── index.md ├── cloud_native_patterns ├── index.md └── 云原生模式.png ├── compute_graphic_guide ├── index.md └── 计算机图形学入门分享.pdf ├── django ├── core_handlers.md ├── core_management.md └── test.py ├── js └── javascript.md ├── linear_algebra ├── 10_four_subspaces │ ├── MIT18_06SCF11_Ses1.10prob.pdf │ └── MIT18_06SCF11_Ses1.10sol.pdf ├── 11_graphs_incidence │ ├── MIT18_06SCF11_Ses1.12prob.pdf │ └── MIT18_06SCF11_Ses1.12sol.pdf ├── 12_orthogonal_vectors │ ├── MIT18_06SCF11_Ses2.1prob.pdf │ └── MIT18_06SCF11_Ses2.1sol.pdf ├── 13_projections_subspaces │ ├── MIT18_06SCF11_Ses2.2prob.pdf │ └── MIT18_06SCF11_Ses2.2sol.pdf ├── 14_projection_and_least_squares │ ├── MIT18_06SCF11_Ses2.3prob.pdf │ └── MIT18_06SCF11_Ses2.3sol.pdf ├── 15_orthogoanl_gram_schmidt │ ├── MIT18_06SCF11_Ses2.4prob.pdf │ └── MIT18_06SCF11_Ses2.4sol.pdf ├── 16_properties_of_determinants │ ├── MIT18_06SCF11_Ses2.5prob.pdf │ └── MIT18_06SCF11_Ses2.5sol.pdf ├── 17_determinant_formulas_cofactors │ ├── MIT18_06SCF11_Ses2.6prob.pdf │ └── MIT18_06SCF11_Ses2.6sol.pdf ├── 18_cramer_inverse_volume │ ├── MIT18_06SCF11_Ses2.7prob.pdf │ └── MIT18_06SCF11_Ses2.7sol.pdf ├── 19_eigenvalues_eigenvectors │ ├── MIT18_06SCF11_Ses2.8prob.pdf │ └── MIT18_06SCF11_Ses2.8sol.pdf ├── 1_the_geometry_of_linear_equations │ ├── MIT18_06SCF11_Ses1.1prob.pdf │ ├── MIT18_06SCF11_Ses1.1sol.pdf │ └── MIT18_06SCF11_Ses1.1sum.pdf ├── 20_powers_of_matrix │ ├── MIT18_06SCF11_Ses2.9prob.pdf │ └── MIT18_06SCF11_Ses2.9sol.pdf ├── 2_elimination_with_matrices │ ├── MIT18_06SCF11_Ses1.2prob.pdf │ ├── MIT18_06SCF11_Ses1.2sol.pdf │ └── MIT18_06SCF11_Ses1.2sum.pdf ├── 3_multiplication_and_inverse_matrices │ ├── MIT18_06SCF11_Ses1.3prob.pdf │ ├── MIT18_06SCF11_Ses1.3sol.pdf │ └── MIT18_06SCF11_Ses1.3sum.pdf ├── 4_factorization_LU │ ├── MIT18_06SCF11_Ses1.4prob.pdf │ ├── MIT18_06SCF11_Ses1.4sol.pdf │ └── MIT18_06SCF11_Ses1.4sum.pdf ├── 5_trans_permu_vector │ ├── MIT18_06SCF11_Ses1.5prob.pdf │ ├── MIT18_06SCF11_Ses1.5sol.pdf │ ├── MIT18_06SCF11_Ses1.5sum.pdf │ └── sol.jpeg ├── 6_column_space │ ├── MIT18_06SCF11_Ses1.6prob.pdf │ ├── MIT18_06SCF11_Ses1.6sol.pdf │ └── MIT18_06SCF11_Ses1.6sum.pdf ├── 7_pivot_variables │ ├── MIT18_06SCF11_Ses1.7prob.pdf │ └── MIT18_06SCF11_Ses1.7sol.pdf ├── 8_rrfr │ ├── MIT18_06SCF11_Ses1.8prob.pdf │ └── MIT18_06SCF11_Ses1.8sol.pdf ├── 9_indepence │ ├── MIT18_06SCF11_Ses1.9prob.pdf │ └── MIT18_06SCF11_Ses1.9sol.pdf └── index.md ├── linux_tuning_practice ├── cpu.md ├── file_system.md ├── images │ ├── file_01.png │ ├── file_global.png │ ├── file_md.png │ ├── file_tuning_1.png │ ├── file_tuning_2.png │ ├── file_tuning_3.png │ ├── linux_tuning_cpu_01.png │ ├── linux_tuning_cpu_02.png │ ├── linux_tuning_cpu_03.png │ ├── linux_tuning_cpu_04.png │ ├── memory_01.png │ ├── memory_02.png │ ├── memory_03.png │ └── memory_04.png ├── index.md ├── memory_01.md └── network.md ├── lucene ├── _index.md ├── analyzer.md ├── blog.graffle │ ├── data.plist │ ├── image1.png │ └── image2.png ├── blog_1.md ├── blog_2.md ├── blog_3.md ├── blog_4.md ├── class_search.jpg ├── d.odg ├── document.md ├── images │ ├── add_doc_seq.jpg │ ├── ana_spec_api.png │ ├── blog1_js_web.png │ ├── blog1_tushuguang.jpg │ ├── blog2_fuzzy.png │ ├── blog2_tree.jpg │ ├── blog2_wildpre.jpg │ ├── blog3_cos.jpg │ ├── blog3_coswiki.jpg │ ├── blog3_idf.png │ ├── blog3_norm.png │ ├── blog3_sim_art.png │ ├── blog3_sim_q_doc.png │ ├── blog3_sim_q_doc1.png │ ├── blog3_tf.jpg │ ├── blog3_zb.jpg │ ├── blog_1.jpg │ ├── blog_2.jpg │ ├── blog_3.png │ ├── blog_4.jpg │ ├── dwpt.png │ ├── fnm.jpg │ ├── search_01.jpg │ ├── search_02.jpg │ ├── segment.jpg │ └── segments.jpg ├── index.md ├── scores.md ├── search.md ├── src │ └── java │ │ ├── org │ │ └── apache │ │ │ └── lucene │ │ │ ├── LucenePackage.java │ │ │ ├── analysis │ │ │ ├── Analyzer.java │ │ │ ├── AnalyzerWrapper.java │ │ │ ├── CachingTokenFilter.java │ │ │ ├── CharFilter.java │ │ │ ├── DelegatingAnalyzerWrapper.java │ │ │ ├── LegacyNumericTokenStream.java │ │ │ ├── ReusableStringReader.java │ │ │ ├── Token.java │ │ │ ├── TokenFilter.java │ │ │ ├── TokenStream.java │ │ │ ├── TokenStreamToAutomaton.java │ │ │ ├── Tokenizer.java │ │ │ ├── package-info.java │ │ │ └── tokenattributes │ │ │ │ ├── BytesTermAttribute.java │ │ │ │ ├── BytesTermAttributeImpl.java │ │ │ │ ├── CharTermAttribute.java │ │ │ │ ├── CharTermAttributeImpl.java │ │ │ │ ├── FlagsAttribute.java │ │ │ │ ├── FlagsAttributeImpl.java │ │ │ │ ├── KeywordAttribute.java │ │ │ │ ├── KeywordAttributeImpl.java │ │ │ │ ├── OffsetAttribute.java │ │ │ │ ├── OffsetAttributeImpl.java │ │ │ │ ├── PackedTokenAttributeImpl.java │ │ │ │ ├── PayloadAttribute.java │ │ │ │ ├── PayloadAttributeImpl.java │ │ │ │ ├── PositionIncrementAttribute.java │ │ │ │ ├── PositionIncrementAttributeImpl.java │ │ │ │ ├── PositionLengthAttribute.java │ │ │ │ ├── PositionLengthAttributeImpl.java │ │ │ │ ├── TermToBytesRefAttribute.java │ │ │ │ ├── TypeAttribute.java │ │ │ │ ├── TypeAttributeImpl.java │ │ │ │ └── package-info.java │ │ │ ├── codecs │ │ │ ├── BlockTermState.java │ │ │ ├── Codec.java │ │ │ ├── CodecUtil.java │ │ │ ├── CompoundFormat.java │ │ │ ├── DocValuesConsumer.java │ │ │ ├── DocValuesFormat.java │ │ │ ├── DocValuesProducer.java │ │ │ ├── FieldInfosFormat.java │ │ │ ├── FieldsConsumer.java │ │ │ ├── FieldsProducer.java │ │ │ ├── FilterCodec.java │ │ │ ├── LiveDocsFormat.java │ │ │ ├── MultiLevelSkipListReader.java │ │ │ ├── MultiLevelSkipListWriter.java │ │ │ ├── NormsConsumer.java │ │ │ ├── NormsFormat.java │ │ │ ├── NormsProducer.java │ │ │ ├── PointsFormat.java │ │ │ ├── PointsReader.java │ │ │ ├── PointsWriter.java │ │ │ ├── PostingsFormat.java │ │ │ ├── PostingsReaderBase.java │ │ │ ├── PostingsWriterBase.java │ │ │ ├── PushPostingsWriterBase.java │ │ │ ├── SegmentInfoFormat.java │ │ │ ├── StoredFieldsFormat.java │ │ │ ├── StoredFieldsReader.java │ │ │ ├── StoredFieldsWriter.java │ │ │ ├── TermStats.java │ │ │ ├── TermVectorsFormat.java │ │ │ ├── TermVectorsReader.java │ │ │ ├── TermVectorsWriter.java │ │ │ ├── blocktree │ │ │ │ ├── AutoPrefixTermsWriter.java │ │ │ │ ├── BitSetPostingsEnum.java │ │ │ │ ├── BitSetTermsEnum.java │ │ │ │ ├── BlockTreeTermsReader.java │ │ │ │ ├── BlockTreeTermsWriter.java │ │ │ │ ├── FieldReader.java │ │ │ │ ├── IntersectTermsEnum.java │ │ │ │ ├── IntersectTermsEnumFrame.java │ │ │ │ ├── SegmentTermsEnum.java │ │ │ │ ├── SegmentTermsEnumFrame.java │ │ │ │ ├── Stats.java │ │ │ │ └── package-info.java │ │ │ ├── compressing │ │ │ │ ├── CompressingStoredFieldsFormat.java │ │ │ │ ├── CompressingStoredFieldsIndexReader.java │ │ │ │ ├── CompressingStoredFieldsIndexWriter.java │ │ │ │ ├── CompressingStoredFieldsReader.java │ │ │ │ ├── CompressingStoredFieldsWriter.java │ │ │ │ ├── CompressingTermVectorsFormat.java │ │ │ │ ├── CompressingTermVectorsReader.java │ │ │ │ ├── CompressingTermVectorsWriter.java │ │ │ │ ├── CompressionMode.java │ │ │ │ ├── Compressor.java │ │ │ │ ├── Decompressor.java │ │ │ │ ├── GrowableByteArrayDataOutput.java │ │ │ │ ├── LZ4.java │ │ │ │ ├── MatchingReaders.java │ │ │ │ └── package-info.java │ │ │ ├── lucene50 │ │ │ │ ├── ForUtil.java │ │ │ │ ├── Lucene50CompoundFormat.java │ │ │ │ ├── Lucene50CompoundReader.java │ │ │ │ ├── Lucene50FieldInfosFormat.java │ │ │ │ ├── Lucene50LiveDocsFormat.java │ │ │ │ ├── Lucene50PostingsFormat.java │ │ │ │ ├── Lucene50PostingsReader.java │ │ │ │ ├── Lucene50PostingsWriter.java │ │ │ │ ├── Lucene50SegmentInfoFormat.java │ │ │ │ ├── Lucene50SkipReader.java │ │ │ │ ├── Lucene50SkipWriter.java │ │ │ │ ├── Lucene50StoredFieldsFormat.java │ │ │ │ ├── Lucene50TermVectorsFormat.java │ │ │ │ └── package-info.java │ │ │ ├── lucene53 │ │ │ │ ├── Lucene53NormsConsumer.java │ │ │ │ ├── Lucene53NormsFormat.java │ │ │ │ ├── Lucene53NormsProducer.java │ │ │ │ └── package-info.java │ │ │ ├── lucene54 │ │ │ │ ├── Lucene54DocValuesConsumer.java │ │ │ │ ├── Lucene54DocValuesFormat.java │ │ │ │ ├── Lucene54DocValuesProducer.java │ │ │ │ └── package-info.java │ │ │ ├── lucene60 │ │ │ │ ├── Lucene60Codec.java │ │ │ │ ├── Lucene60FieldInfosFormat.java │ │ │ │ ├── Lucene60PointsFormat.java │ │ │ │ ├── Lucene60PointsReader.java │ │ │ │ ├── Lucene60PointsWriter.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── perfield │ │ │ │ ├── PerFieldDocValuesFormat.java │ │ │ │ ├── PerFieldPostingsFormat.java │ │ │ │ └── package-info.java │ │ │ ├── document │ │ │ ├── BinaryDocValuesField.java │ │ │ ├── BinaryPoint.java │ │ │ ├── CompressionTools.java │ │ │ ├── DateTools.java │ │ │ ├── Document.java │ │ │ ├── DocumentStoredFieldVisitor.java │ │ │ ├── DoubleDocValuesField.java │ │ │ ├── DoublePoint.java │ │ │ ├── Field.java │ │ │ ├── FieldType.java │ │ │ ├── FloatDocValuesField.java │ │ │ ├── FloatPoint.java │ │ │ ├── IntPoint.java │ │ │ ├── LegacyDoubleField.java │ │ │ ├── LegacyFloatField.java │ │ │ ├── LegacyIntField.java │ │ │ ├── LegacyLongField.java │ │ │ ├── LongPoint.java │ │ │ ├── NumericDocValuesField.java │ │ │ ├── SortedDocValuesField.java │ │ │ ├── SortedNumericDocValuesField.java │ │ │ ├── SortedSetDocValuesField.java │ │ │ ├── StoredField.java │ │ │ ├── StringField.java │ │ │ ├── TextField.java │ │ │ └── package-info.java │ │ │ ├── geo │ │ │ ├── GeoEncodingUtils.java │ │ │ ├── GeoUtils.java │ │ │ ├── Polygon.java │ │ │ ├── Polygon2D.java │ │ │ ├── Rectangle.java │ │ │ └── package-info.java │ │ │ ├── index │ │ │ ├── AbortingException.java │ │ │ ├── AutomatonTermsEnum.java │ │ │ ├── BaseCompositeReader.java │ │ │ ├── BinaryDocValues.java │ │ │ ├── BinaryDocValuesFieldUpdates.java │ │ │ ├── BinaryDocValuesWriter.java │ │ │ ├── BitsSlice.java │ │ │ ├── BufferedUpdates.java │ │ │ ├── BufferedUpdatesStream.java │ │ │ ├── ByteSliceReader.java │ │ │ ├── ByteSliceWriter.java │ │ │ ├── CheckIndex.java │ │ │ ├── CoalescedUpdates.java │ │ │ ├── CodecReader.java │ │ │ ├── CompositeReader.java │ │ │ ├── CompositeReaderContext.java │ │ │ ├── ConcurrentMergeScheduler.java │ │ │ ├── CorruptIndexException.java │ │ │ ├── DefaultIndexingChain.java │ │ │ ├── DirectoryReader.java │ │ │ ├── DocConsumer.java │ │ │ ├── DocValues.java │ │ │ ├── DocValuesFieldUpdates.java │ │ │ ├── DocValuesType.java │ │ │ ├── DocValuesUpdate.java │ │ │ ├── DocValuesWriter.java │ │ │ ├── DocumentsWriter.java │ │ │ ├── DocumentsWriterDeleteQueue.java │ │ │ ├── DocumentsWriterFlushControl.java │ │ │ ├── DocumentsWriterFlushQueue.java │ │ │ ├── DocumentsWriterPerThread.java │ │ │ ├── DocumentsWriterPerThreadPool.java │ │ │ ├── DocumentsWriterStallControl.java │ │ │ ├── ExitableDirectoryReader.java │ │ │ ├── FieldInfo.java │ │ │ ├── FieldInfos.java │ │ │ ├── FieldInvertState.java │ │ │ ├── FieldTermIterator.java │ │ │ ├── Fields.java │ │ │ ├── FilterCodecReader.java │ │ │ ├── FilterDirectoryReader.java │ │ │ ├── FilterLeafReader.java │ │ │ ├── FilteredTermsEnum.java │ │ │ ├── FlushByRamOrCountsPolicy.java │ │ │ ├── FlushPolicy.java │ │ │ ├── FreqProxFields.java │ │ │ ├── FreqProxTermsWriter.java │ │ │ ├── FreqProxTermsWriterPerField.java │ │ │ ├── FrozenBufferedUpdates.java │ │ │ ├── IndexCommit.java │ │ │ ├── IndexDeletionPolicy.java │ │ │ ├── IndexFileDeleter.java │ │ │ ├── IndexFileNames.java │ │ │ ├── IndexFormatTooNewException.java │ │ │ ├── IndexFormatTooOldException.java │ │ │ ├── IndexNotFoundException.java │ │ │ ├── IndexOptions.java │ │ │ ├── IndexReader.java │ │ │ ├── IndexReaderContext.java │ │ │ ├── IndexUpgrader.java │ │ │ ├── IndexWriter.java │ │ │ ├── IndexWriterConfig.java │ │ │ ├── IndexableField.java │ │ │ ├── IndexableFieldType.java │ │ │ ├── KeepOnlyLastCommitDeletionPolicy.java │ │ │ ├── LeafReader.java │ │ │ ├── LeafReaderContext.java │ │ │ ├── LiveIndexWriterConfig.java │ │ │ ├── LogByteSizeMergePolicy.java │ │ │ ├── LogDocMergePolicy.java │ │ │ ├── LogMergePolicy.java │ │ │ ├── MappedMultiFields.java │ │ │ ├── MappingMultiPostingsEnum.java │ │ │ ├── MergePolicy.java │ │ │ ├── MergePolicyWrapper.java │ │ │ ├── MergeRateLimiter.java │ │ │ ├── MergeScheduler.java │ │ │ ├── MergeState.java │ │ │ ├── MergeTrigger.java │ │ │ ├── MergedPrefixCodedTermsIterator.java │ │ │ ├── MultiBits.java │ │ │ ├── MultiDocValues.java │ │ │ ├── MultiFields.java │ │ │ ├── MultiPostingsEnum.java │ │ │ ├── MultiReader.java │ │ │ ├── MultiTerms.java │ │ │ ├── MultiTermsEnum.java │ │ │ ├── NoDeletionPolicy.java │ │ │ ├── NoMergePolicy.java │ │ │ ├── NoMergeScheduler.java │ │ │ ├── NormValuesWriter.java │ │ │ ├── NumericDocValues.java │ │ │ ├── NumericDocValuesFieldUpdates.java │ │ │ ├── NumericDocValuesWriter.java │ │ │ ├── OrdTermState.java │ │ │ ├── ParallelCompositeReader.java │ │ │ ├── ParallelLeafReader.java │ │ │ ├── ParallelPostingsArray.java │ │ │ ├── PersistentSnapshotDeletionPolicy.java │ │ │ ├── PointValues.java │ │ │ ├── PointValuesWriter.java │ │ │ ├── PostingsEnum.java │ │ │ ├── PrefixCodedTerms.java │ │ │ ├── QueryTimeout.java │ │ │ ├── QueryTimeoutImpl.java │ │ │ ├── RandomAccessOrds.java │ │ │ ├── ReaderManager.java │ │ │ ├── ReaderSlice.java │ │ │ ├── ReaderUtil.java │ │ │ ├── ReadersAndUpdates.java │ │ │ ├── SegmentCommitInfo.java │ │ │ ├── SegmentCoreReaders.java │ │ │ ├── SegmentDocValues.java │ │ │ ├── SegmentDocValuesProducer.java │ │ │ ├── SegmentInfo.java │ │ │ ├── SegmentInfos.java │ │ │ ├── SegmentMerger.java │ │ │ ├── SegmentReadState.java │ │ │ ├── SegmentReader.java │ │ │ ├── SegmentWriteState.java │ │ │ ├── SerialMergeScheduler.java │ │ │ ├── SimpleMergedSegmentWarmer.java │ │ │ ├── SingleTermsEnum.java │ │ │ ├── SingletonSortedNumericDocValues.java │ │ │ ├── SingletonSortedSetDocValues.java │ │ │ ├── SlowCodecReaderWrapper.java │ │ │ ├── SnapshotDeletionPolicy.java │ │ │ ├── SortedDocValues.java │ │ │ ├── SortedDocValuesTermsEnum.java │ │ │ ├── SortedDocValuesWriter.java │ │ │ ├── SortedNumericDocValues.java │ │ │ ├── SortedNumericDocValuesWriter.java │ │ │ ├── SortedSetDocValues.java │ │ │ ├── SortedSetDocValuesTermsEnum.java │ │ │ ├── SortedSetDocValuesWriter.java │ │ │ ├── StandardDirectoryReader.java │ │ │ ├── StoredFieldVisitor.java │ │ │ ├── Term.java │ │ │ ├── TermContext.java │ │ │ ├── TermState.java │ │ │ ├── TermVectorsConsumer.java │ │ │ ├── TermVectorsConsumerPerField.java │ │ │ ├── Terms.java │ │ │ ├── TermsEnum.java │ │ │ ├── TermsHash.java │ │ │ ├── TermsHashPerField.java │ │ │ ├── TieredMergePolicy.java │ │ │ ├── TrackingIndexWriter.java │ │ │ ├── TwoPhaseCommit.java │ │ │ ├── TwoPhaseCommitTool.java │ │ │ ├── UpgradeIndexMergePolicy.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── search │ │ │ ├── AutomatonQuery.java │ │ │ ├── BlendedTermQuery.java │ │ │ ├── BooleanClause.java │ │ │ ├── BooleanQuery.java │ │ │ ├── BooleanScorer.java │ │ │ ├── BooleanTopLevelScorers.java │ │ │ ├── BooleanWeight.java │ │ │ ├── BoostAttribute.java │ │ │ ├── BoostAttributeImpl.java │ │ │ ├── BoostQuery.java │ │ │ ├── BulkScorer.java │ │ │ ├── CachingCollector.java │ │ │ ├── CollectionStatistics.java │ │ │ ├── CollectionTerminatedException.java │ │ │ ├── Collector.java │ │ │ ├── CollectorManager.java │ │ │ ├── ConjunctionDISI.java │ │ │ ├── ConjunctionScorer.java │ │ │ ├── ConstantScoreQuery.java │ │ │ ├── ConstantScoreScorer.java │ │ │ ├── ConstantScoreWeight.java │ │ │ ├── ControlledRealTimeReopenThread.java │ │ │ ├── DisiPriorityQueue.java │ │ │ ├── DisiWrapper.java │ │ │ ├── DisjunctionDISIApproximation.java │ │ │ ├── DisjunctionMaxQuery.java │ │ │ ├── DisjunctionMaxScorer.java │ │ │ ├── DisjunctionScorer.java │ │ │ ├── DisjunctionSumScorer.java │ │ │ ├── DocIdSet.java │ │ │ ├── DocIdSetIterator.java │ │ │ ├── DocValuesDocIdSet.java │ │ │ ├── DocValuesRewriteMethod.java │ │ │ ├── ExactPhraseScorer.java │ │ │ ├── Explanation.java │ │ │ ├── FakeScorer.java │ │ │ ├── FieldComparator.java │ │ │ ├── FieldComparatorSource.java │ │ │ ├── FieldDoc.java │ │ │ ├── FieldValueHitQueue.java │ │ │ ├── FieldValueQuery.java │ │ │ ├── FilterCollector.java │ │ │ ├── FilterLeafCollector.java │ │ │ ├── FilterScorer.java │ │ │ ├── FilteredDocIdSetIterator.java │ │ │ ├── FuzzyQuery.java │ │ │ ├── FuzzyTermsEnum.java │ │ │ ├── HitQueue.java │ │ │ ├── IndexSearcher.java │ │ │ ├── LRUQueryCache.java │ │ │ ├── LeafCollector.java │ │ │ ├── LeafFieldComparator.java │ │ │ ├── LegacyNumericRangeQuery.java │ │ │ ├── LiveFieldValues.java │ │ │ ├── MatchAllDocsQuery.java │ │ │ ├── MatchNoDocsQuery.java │ │ │ ├── MaxNonCompetitiveBoostAttribute.java │ │ │ ├── MaxNonCompetitiveBoostAttributeImpl.java │ │ │ ├── MinShouldMatchSumScorer.java │ │ │ ├── MultiCollector.java │ │ │ ├── MultiPhraseQuery.java │ │ │ ├── MultiTermQuery.java │ │ │ ├── MultiTermQueryConstantScoreWrapper.java │ │ │ ├── Multiset.java │ │ │ ├── NGramPhraseQuery.java │ │ │ ├── PhrasePositions.java │ │ │ ├── PhraseQuery.java │ │ │ ├── PhraseQueue.java │ │ │ ├── PointInSetQuery.java │ │ │ ├── PointRangeQuery.java │ │ │ ├── PositiveScoresOnlyCollector.java │ │ │ ├── PrefixQuery.java │ │ │ ├── Query.java │ │ │ ├── QueryCache.java │ │ │ ├── QueryCachingPolicy.java │ │ │ ├── QueryRescorer.java │ │ │ ├── RandomAccessWeight.java │ │ │ ├── ReferenceManager.java │ │ │ ├── RegexpQuery.java │ │ │ ├── ReqExclBulkScorer.java │ │ │ ├── ReqExclScorer.java │ │ │ ├── ReqOptSumScorer.java │ │ │ ├── Rescorer.java │ │ │ ├── ScoreCachingWrappingScorer.java │ │ │ ├── ScoreDoc.java │ │ │ ├── Scorer.java │ │ │ ├── ScoringRewrite.java │ │ │ ├── SearcherFactory.java │ │ │ ├── SearcherLifetimeManager.java │ │ │ ├── SearcherManager.java │ │ │ ├── SimpleCollector.java │ │ │ ├── SimpleFieldComparator.java │ │ │ ├── SloppyPhraseScorer.java │ │ │ ├── Sort.java │ │ │ ├── SortField.java │ │ │ ├── SortRescorer.java │ │ │ ├── SortedNumericSelector.java │ │ │ ├── SortedNumericSortField.java │ │ │ ├── SortedSetSelector.java │ │ │ ├── SortedSetSortField.java │ │ │ ├── SynonymQuery.java │ │ │ ├── TermCollectingRewrite.java │ │ │ ├── TermQuery.java │ │ │ ├── TermRangeQuery.java │ │ │ ├── TermScorer.java │ │ │ ├── TermStatistics.java │ │ │ ├── TimeLimitingCollector.java │ │ │ ├── TopDocs.java │ │ │ ├── TopDocsCollector.java │ │ │ ├── TopFieldCollector.java │ │ │ ├── TopFieldDocs.java │ │ │ ├── TopScoreDocCollector.java │ │ │ ├── TopTermsRewrite.java │ │ │ ├── TotalHitCountCollector.java │ │ │ ├── TwoPhaseIterator.java │ │ │ ├── UsageTrackingQueryCachingPolicy.java │ │ │ ├── Weight.java │ │ │ ├── WildcardQuery.java │ │ │ ├── doc-files │ │ │ │ ├── nrq-formula-1.png │ │ │ │ └── nrq-formula-2.png │ │ │ ├── package-info.java │ │ │ ├── similarities │ │ │ │ ├── AfterEffect.java │ │ │ │ ├── AfterEffectB.java │ │ │ │ ├── AfterEffectL.java │ │ │ │ ├── BM25Similarity.java │ │ │ │ ├── BasicModel.java │ │ │ │ ├── BasicModelBE.java │ │ │ │ ├── BasicModelD.java │ │ │ │ ├── BasicModelG.java │ │ │ │ ├── BasicModelIF.java │ │ │ │ ├── BasicModelIn.java │ │ │ │ ├── BasicModelIne.java │ │ │ │ ├── BasicModelP.java │ │ │ │ ├── BasicStats.java │ │ │ │ ├── ClassicSimilarity.java │ │ │ │ ├── DFISimilarity.java │ │ │ │ ├── DFRSimilarity.java │ │ │ │ ├── Distribution.java │ │ │ │ ├── DistributionLL.java │ │ │ │ ├── DistributionSPL.java │ │ │ │ ├── IBSimilarity.java │ │ │ │ ├── Independence.java │ │ │ │ ├── IndependenceChiSquared.java │ │ │ │ ├── IndependenceSaturated.java │ │ │ │ ├── IndependenceStandardized.java │ │ │ │ ├── LMDirichletSimilarity.java │ │ │ │ ├── LMJelinekMercerSimilarity.java │ │ │ │ ├── LMSimilarity.java │ │ │ │ ├── Lambda.java │ │ │ │ ├── LambdaDF.java │ │ │ │ ├── LambdaTTF.java │ │ │ │ ├── MultiSimilarity.java │ │ │ │ ├── Normalization.java │ │ │ │ ├── NormalizationH1.java │ │ │ │ ├── NormalizationH2.java │ │ │ │ ├── NormalizationH3.java │ │ │ │ ├── NormalizationZ.java │ │ │ │ ├── PerFieldSimilarityWrapper.java │ │ │ │ ├── Similarity.java │ │ │ │ ├── SimilarityBase.java │ │ │ │ ├── TFIDFSimilarity.java │ │ │ │ └── package-info.java │ │ │ └── spans │ │ │ │ ├── ConjunctionSpans.java │ │ │ │ ├── ContainSpans.java │ │ │ │ ├── FieldMaskingSpanQuery.java │ │ │ │ ├── FilterSpans.java │ │ │ │ ├── NearSpansOrdered.java │ │ │ │ ├── NearSpansUnordered.java │ │ │ │ ├── ScoringWrapperSpans.java │ │ │ │ ├── SpanBoostQuery.java │ │ │ │ ├── SpanCollector.java │ │ │ │ ├── SpanContainQuery.java │ │ │ │ ├── SpanContainingQuery.java │ │ │ │ ├── SpanFirstQuery.java │ │ │ │ ├── SpanMultiTermQueryWrapper.java │ │ │ │ ├── SpanNearQuery.java │ │ │ │ ├── SpanNotQuery.java │ │ │ │ ├── SpanOrQuery.java │ │ │ │ ├── SpanPositionCheckQuery.java │ │ │ │ ├── SpanPositionQueue.java │ │ │ │ ├── SpanPositionRangeQuery.java │ │ │ │ ├── SpanQuery.java │ │ │ │ ├── SpanScorer.java │ │ │ │ ├── SpanTermQuery.java │ │ │ │ ├── SpanWeight.java │ │ │ │ ├── SpanWithinQuery.java │ │ │ │ ├── Spans.java │ │ │ │ ├── TermSpans.java │ │ │ │ └── package-info.java │ │ │ ├── store │ │ │ ├── AlreadyClosedException.java │ │ │ ├── BaseDirectory.java │ │ │ ├── BufferedChecksum.java │ │ │ ├── BufferedChecksumIndexInput.java │ │ │ ├── BufferedIndexInput.java │ │ │ ├── ByteArrayDataInput.java │ │ │ ├── ByteArrayDataOutput.java │ │ │ ├── ByteArrayIndexInput.java │ │ │ ├── ByteBufferIndexInput.java │ │ │ ├── ChecksumIndexInput.java │ │ │ ├── DataInput.java │ │ │ ├── DataOutput.java │ │ │ ├── Directory.java │ │ │ ├── FSDirectory.java │ │ │ ├── FSLockFactory.java │ │ │ ├── FileSwitchDirectory.java │ │ │ ├── FilterDirectory.java │ │ │ ├── FlushInfo.java │ │ │ ├── IOContext.java │ │ │ ├── IndexInput.java │ │ │ ├── IndexOutput.java │ │ │ ├── InputStreamDataInput.java │ │ │ ├── Lock.java │ │ │ ├── LockFactory.java │ │ │ ├── LockObtainFailedException.java │ │ │ ├── LockReleaseFailedException.java │ │ │ ├── LockStressTest.java │ │ │ ├── LockValidatingDirectoryWrapper.java │ │ │ ├── LockVerifyServer.java │ │ │ ├── MMapDirectory.java │ │ │ ├── MergeInfo.java │ │ │ ├── NIOFSDirectory.java │ │ │ ├── NRTCachingDirectory.java │ │ │ ├── NativeFSLockFactory.java │ │ │ ├── NoLockFactory.java │ │ │ ├── OutputStreamDataOutput.java │ │ │ ├── OutputStreamIndexOutput.java │ │ │ ├── RAMDirectory.java │ │ │ ├── RAMFile.java │ │ │ ├── RAMInputStream.java │ │ │ ├── RAMOutputStream.java │ │ │ ├── RandomAccessInput.java │ │ │ ├── RateLimitedIndexOutput.java │ │ │ ├── RateLimiter.java │ │ │ ├── SimpleFSDirectory.java │ │ │ ├── SimpleFSLockFactory.java │ │ │ ├── SingleInstanceLockFactory.java │ │ │ ├── SleepingLockWrapper.java │ │ │ ├── TrackingDirectoryWrapper.java │ │ │ ├── VerifyingLockFactory.java │ │ │ └── package-info.java │ │ │ └── util │ │ │ ├── Accountable.java │ │ │ ├── Accountables.java │ │ │ ├── ArrayInPlaceMergeSorter.java │ │ │ ├── ArrayIntroSorter.java │ │ │ ├── ArrayTimSorter.java │ │ │ ├── ArrayUtil.java │ │ │ ├── Attribute.java │ │ │ ├── AttributeFactory.java │ │ │ ├── AttributeImpl.java │ │ │ ├── AttributeReflector.java │ │ │ ├── AttributeSource.java │ │ │ ├── BitDocIdSet.java │ │ │ ├── BitSet.java │ │ │ ├── BitSetIterator.java │ │ │ ├── BitUtil.java │ │ │ ├── Bits.java │ │ │ ├── ByteBlockPool.java │ │ │ ├── BytesRef.java │ │ │ ├── BytesRefArray.java │ │ │ ├── BytesRefBuilder.java │ │ │ ├── BytesRefComparator.java │ │ │ ├── BytesRefHash.java │ │ │ ├── BytesRefIterator.java │ │ │ ├── CharsRef.java │ │ │ ├── CharsRefBuilder.java │ │ │ ├── CloseableThreadLocal.java │ │ │ ├── CollectionUtil.java │ │ │ ├── CommandLineUtil.java │ │ │ ├── Constants.java │ │ │ ├── Counter.java │ │ │ ├── DocIdSetBuilder.java │ │ │ ├── FilterIterator.java │ │ │ ├── FixedBitSet.java │ │ │ ├── FixedLengthBytesRefArray.java │ │ │ ├── FrequencyTrackingRingBuffer.java │ │ │ ├── IOUtils.java │ │ │ ├── InPlaceMergeSorter.java │ │ │ ├── InfoStream.java │ │ │ ├── IntArrayDocIdSet.java │ │ │ ├── IntBlockPool.java │ │ │ ├── IntroSorter.java │ │ │ ├── IntsRef.java │ │ │ ├── IntsRefBuilder.java │ │ │ ├── LSBRadixSorter.java │ │ │ ├── LegacyNumericUtils.java │ │ │ ├── LongBitSet.java │ │ │ ├── LongValues.java │ │ │ ├── LongsRef.java │ │ │ ├── MSBRadixSorter.java │ │ │ ├── MapOfSets.java │ │ │ ├── MathUtil.java │ │ │ ├── MergedIterator.java │ │ │ ├── MutableBits.java │ │ │ ├── NamedSPILoader.java │ │ │ ├── NamedThreadFactory.java │ │ │ ├── NotDocIdSet.java │ │ │ ├── NumericUtils.java │ │ │ ├── OfflineSorter.java │ │ │ ├── PagedBytes.java │ │ │ ├── PrintStreamInfoStream.java │ │ │ ├── PriorityQueue.java │ │ │ ├── QueryBuilder.java │ │ │ ├── RamUsageEstimator.java │ │ │ ├── RecyclingByteBlockAllocator.java │ │ │ ├── RecyclingIntBlockAllocator.java │ │ │ ├── RefCount.java │ │ │ ├── RoaringDocIdSet.java │ │ │ ├── RollingBuffer.java │ │ │ ├── SPIClassIterator.java │ │ │ ├── SentinelIntSet.java │ │ │ ├── SetOnce.java │ │ │ ├── SloppyMath.java │ │ │ ├── SmallFloat.java │ │ │ ├── SortableBytesRefArray.java │ │ │ ├── Sorter.java │ │ │ ├── SparseFixedBitSet.java │ │ │ ├── StrictStringTokenizer.java │ │ │ ├── StringHelper.java │ │ │ ├── StringMSBRadixSorter.java │ │ │ ├── SuppressForbidden.java │ │ │ ├── ThreadInterruptedException.java │ │ │ ├── TimSorter.java │ │ │ ├── ToStringUtils.java │ │ │ ├── UnicodeUtil.java │ │ │ ├── Version.java │ │ │ ├── VirtualMethod.java │ │ │ ├── WeakIdentityMap.java │ │ │ ├── automaton │ │ │ ├── Automata.java │ │ │ ├── Automaton.java │ │ │ ├── AutomatonProvider.java │ │ │ ├── ByteRunAutomaton.java │ │ │ ├── CharacterRunAutomaton.java │ │ │ ├── CompiledAutomaton.java │ │ │ ├── DaciukMihovAutomatonBuilder.java │ │ │ ├── FiniteStringsIterator.java │ │ │ ├── Lev1ParametricDescription.java │ │ │ ├── Lev1TParametricDescription.java │ │ │ ├── Lev2ParametricDescription.java │ │ │ ├── Lev2TParametricDescription.java │ │ │ ├── LevenshteinAutomata.java │ │ │ ├── LimitedFiniteStringsIterator.java │ │ │ ├── MinimizationOperations.java │ │ │ ├── Operations.java │ │ │ ├── RegExp.java │ │ │ ├── RunAutomaton.java │ │ │ ├── SortedIntSet.java │ │ │ ├── StatePair.java │ │ │ ├── TooComplexToDeterminizeException.java │ │ │ ├── Transition.java │ │ │ ├── UTF32ToUTF8.java │ │ │ ├── UTF32ToUTF8.py │ │ │ ├── createLevAutomata.py │ │ │ └── package-info.java │ │ │ ├── bkd │ │ │ ├── BKDReader.java │ │ │ ├── BKDWriter.java │ │ │ ├── HeapPointReader.java │ │ │ ├── HeapPointWriter.java │ │ │ ├── OfflinePointReader.java │ │ │ ├── OfflinePointWriter.java │ │ │ ├── PointReader.java │ │ │ ├── PointWriter.java │ │ │ └── package-info.java │ │ │ ├── fst │ │ │ ├── Builder.java │ │ │ ├── ByteSequenceOutputs.java │ │ │ ├── BytesRefFSTEnum.java │ │ │ ├── BytesStore.java │ │ │ ├── CharSequenceOutputs.java │ │ │ ├── FST.java │ │ │ ├── FSTEnum.java │ │ │ ├── ForwardBytesReader.java │ │ │ ├── IntSequenceOutputs.java │ │ │ ├── IntsRefFSTEnum.java │ │ │ ├── NoOutputs.java │ │ │ ├── NodeHash.java │ │ │ ├── Outputs.java │ │ │ ├── PairOutputs.java │ │ │ ├── PositiveIntOutputs.java │ │ │ ├── ReverseBytesReader.java │ │ │ ├── Util.java │ │ │ └── package-info.java │ │ │ ├── mutable │ │ │ ├── MutableValue.java │ │ │ ├── MutableValueBool.java │ │ │ ├── MutableValueDate.java │ │ │ ├── MutableValueDouble.java │ │ │ ├── MutableValueFloat.java │ │ │ ├── MutableValueInt.java │ │ │ ├── MutableValueLong.java │ │ │ ├── MutableValueStr.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── packed │ │ │ ├── AbstractBlockPackedWriter.java │ │ │ ├── AbstractPagedMutable.java │ │ │ ├── BlockPackedReader.java │ │ │ ├── BlockPackedReaderIterator.java │ │ │ ├── BlockPackedWriter.java │ │ │ ├── BulkOperation.java │ │ │ ├── BulkOperationPacked.java │ │ │ ├── BulkOperationPacked1.java │ │ │ ├── BulkOperationPacked10.java │ │ │ ├── BulkOperationPacked11.java │ │ │ ├── BulkOperationPacked12.java │ │ │ ├── BulkOperationPacked13.java │ │ │ ├── BulkOperationPacked14.java │ │ │ ├── BulkOperationPacked15.java │ │ │ ├── BulkOperationPacked16.java │ │ │ ├── BulkOperationPacked17.java │ │ │ ├── BulkOperationPacked18.java │ │ │ ├── BulkOperationPacked19.java │ │ │ ├── BulkOperationPacked2.java │ │ │ ├── BulkOperationPacked20.java │ │ │ ├── BulkOperationPacked21.java │ │ │ ├── BulkOperationPacked22.java │ │ │ ├── BulkOperationPacked23.java │ │ │ ├── BulkOperationPacked24.java │ │ │ ├── BulkOperationPacked3.java │ │ │ ├── BulkOperationPacked4.java │ │ │ ├── BulkOperationPacked5.java │ │ │ ├── BulkOperationPacked6.java │ │ │ ├── BulkOperationPacked7.java │ │ │ ├── BulkOperationPacked8.java │ │ │ ├── BulkOperationPacked9.java │ │ │ ├── BulkOperationPackedSingleBlock.java │ │ │ ├── DeltaPackedLongValues.java │ │ │ ├── Direct16.java │ │ │ ├── Direct32.java │ │ │ ├── Direct64.java │ │ │ ├── Direct8.java │ │ │ ├── DirectMonotonicReader.java │ │ │ ├── DirectMonotonicWriter.java │ │ │ ├── DirectPacked64SingleBlockReader.java │ │ │ ├── DirectPackedReader.java │ │ │ ├── DirectReader.java │ │ │ ├── DirectWriter.java │ │ │ ├── GrowableWriter.java │ │ │ ├── MonotonicBlockPackedReader.java │ │ │ ├── MonotonicBlockPackedWriter.java │ │ │ ├── MonotonicLongValues.java │ │ │ ├── Packed16ThreeBlocks.java │ │ │ ├── Packed64.java │ │ │ ├── Packed64SingleBlock.java │ │ │ ├── Packed8ThreeBlocks.java │ │ │ ├── PackedDataInput.java │ │ │ ├── PackedDataOutput.java │ │ │ ├── PackedInts.java │ │ │ ├── PackedLongValues.java │ │ │ ├── PackedReaderIterator.java │ │ │ ├── PackedWriter.java │ │ │ ├── PagedGrowableWriter.java │ │ │ ├── PagedMutable.java │ │ │ ├── gen_BulkOperation.py │ │ │ ├── gen_Direct.py │ │ │ ├── gen_Packed64SingleBlock.py │ │ │ ├── gen_PackedThreeBlocks.py │ │ │ └── package-info.java │ │ └── overview.html ├── store.md ├── uml.asta └── utils.md ├── mit6006_algorithms ├── index.md └── lecture_1 │ ├── lec01_note.pdf │ ├── ps │ ├── README.txt │ ├── algorithms.py │ ├── generate.py │ ├── macros.tex │ ├── main.py │ ├── peak.py │ ├── problem.py │ ├── ps1.pdf │ ├── ps1_critique.tex │ ├── ps1_sol.tex │ ├── trace.jsonp │ ├── trace.py │ ├── utils.py │ └── visualizer.html │ ├── ps1.pdf │ ├── ps1.zip │ └── ps1_sol.pdf ├── mysql ├── 01.md ├── 02.md ├── 03.md ├── 04.md ├── 05.md ├── 06.md ├── 07.md ├── 08.md ├── 09.md ├── 10.md ├── 11.md ├── 12.md ├── 13.md ├── 14.md ├── 16.md ├── 17.md ├── 18.md ├── 19.md ├── 20.md ├── 21.md ├── 22.md ├── 23.md ├── 24.md ├── 25.md ├── 26.md ├── 27.md ├── 28.md ├── 29.md ├── 31.md ├── 32.md ├── 33.md ├── 34.md ├── 35.md ├── 36.md ├── 37.md ├── 38.md ├── 39.md ├── 40.md ├── 41.md ├── 42.md ├── 43.md ├── 45.md └── index.md ├── netty ├── buffer.md ├── channel.md ├── images │ ├── buffer.jpg │ ├── bufferfactory.png │ ├── channel.jpg │ └── directbuffer.png └── list.md ├── nlp ├── index.md └── salp │ └── chaptor_01.md ├── python └── Fluent_Python.md ├── rs ├── index.md └── tj36 │ ├── chapter01.md │ ├── chapter02.md │ └── chapter03.md ├── shardingsphere ├── index.md ├── uml.asta └── uml.drawio └── spring ├── images ├── beanFactory_life.png ├── bean_life.png └── class.png ├── index.md ├── ioc.md └── samples ├── pom.xml └── src ├── java └── spring │ ├── HelloController.java │ └── util │ ├── ApiVersion.java │ ├── ApiVesrsionCondition.java │ ├── AuthInteceptor.java │ ├── CustomRequestMappingHandlerMapping.java │ └── WebConfig.java └── main ├── resources ├── applicationContext.xml └── log4j.properties └── webapp ├── WEB-INF ├── mvc-servlet.xml └── web.xml └── index.jsp /.gitignore: -------------------------------------------------------------------------------- 1 | *.md~ 2 | .DS_Store 3 | .~* 4 | *.swp 5 | -------------------------------------------------------------------------------- /AUP2/chapter11.md: -------------------------------------------------------------------------------- 1 | # 线程概念 2 | 在一个进程内, 可以有多个控制线程, 线程包含了表示进程内执行环境必需的信息, 其中包括标识线程的ID, 一组寄存器, 栈, 调度优先级和策略, 信息屏蔽字, error变量. 3 | 4 | # 线程标识 5 | 在Linux中用无符号长整形表示线程id, 在有的操作系统用一个数据结构定义. 6 | 线程的比较: 7 | ```c 8 | #include 9 | int pthread_equal(pthread_t tid1, pthread_t tid2); // 相等返回0, 否则返回非0 10 | ``` 11 | 12 | # 线程创建 13 | ```c 14 | #include "apue.h" 15 | #include 16 | 17 | pthread_t ntid; 18 | 19 | void printtids(const char *s){ 20 | pid_t pid; 21 | pthread_t tid; 22 | pid = getpid(); 23 | tid = pthread_self(); 24 | printf("%s pid %u tid %u (0x%x)\n", s, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid); 25 | } 26 | 27 | void * thr_fn(void *arg){ 28 | printtids("new thread :"); 29 | sleep(1000); 30 | return ((void *)0); 31 | } 32 | 33 | int main(int argc, char *argv[]){ 34 | int err; 35 | err = pthread_create(&ntid, NULL, thr_fn, NULL); 36 | if(err != 0){ 37 | err_quit("can not create thread : %s\n", strerror(err)); 38 | } 39 | printtids("main thread :"); 40 | sleep(10000); 41 | exit(0); 42 | } 43 | ``` 44 | 输出: 45 | ```bash 46 | main thread : pid 3726 tid 3970209536 (0xeca49700) 47 | new thread : pid 3726 tid 3961923328 (0xec262700) 48 | ``` 49 | 50 | # 线程退出 51 | ```c 52 | #include 53 | void pthread_exit(void *rval_ptr); 54 | ``` 55 | 进程中的其它线程可以调用join来得到一个线程退出时的状态: 56 | ```c 57 | int pthread_join(pthread_t thread, void **rval_ptr); // 成功返回0, 出错返回错误码 58 | ``` 59 | 60 | # 线程同步 61 | ```c 62 | #include 63 | int pthread_mutex_lock(pthread_mutex_t *mutex); 64 | int pthread_mutex_trylock(pthread_mutex_t *mutex); 65 | int pthread_mutex_unlock(pthread_mutex_t *mutex); 66 | // 成功返回0,出错返回错误码 67 | ``` 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /AUP2/chapter5.md: -------------------------------------------------------------------------------- 1 | ### 引言 2 | 在第三章,学习了`文件IO`(系统IO),这是一种无缓冲. 这里学习的`标准IO`(对`系统IO`的封装)是由ISO C标准说明, 它在系统IO的基础上处理了很多细节, 如分配系统最优的缓冲区长度. 3 | 4 | `标准IO`的所有函数操作对象都是`FILE`, 我们称为流. 该结构通常包含: 对应的实际文件描述符, 用于该流缓冲区的指针, 缓冲区长度及缓冲区当前内容信息,出错标志. 5 | 6 | ### 缓冲 7 | 我们说`标准IO`相对于`系统IO`而言, 就是做了很多缓冲优化处理. 标准IO的缓冲有三种类型: 8 | 9 | 1. 全缓冲 10 | 1. 行缓冲 11 | 1. 不带缓冲; 如标准出错流stderr就是不带缓冲的, 便出错信息及时反馈打印出来 12 | 13 | 下列函数更改缓冲类型: 14 | ```c 15 | #include 16 | void setbuf(FILE *fp, char *buf); 17 | int setvbuf(FILE *fp, char *buf, int mode, size_t bufSize); 18 | ``` 19 | `setbuf`用指定的`buf`作为缓冲存储区域, 其长度一定是`BUFSIZE`(在stdio.h中定义); 而`setvbuf`则提供更细粒度的控制, 如`mode`指定缓冲类型(_IOFBF:全缓冲;_IOLBF:行缓冲;_IONBF:无缓冲), `bufSize`指定缓冲区大小. 20 | 21 | ### 打开流 22 | ```c 23 | #include 24 | FILE *fopen(const char *pathname, const char *type); 25 | FILE *freopen(const char *pathname, const char *type, FILE *fp); 26 | FILE *fdopen(int fd, const char *type); 27 | ``` 28 | 参数type有几种值: `r`, `w`, `a` ,`r+`, `w+`, `a+` 29 | 30 | ### 关闭流 31 | ```c 32 | #include 33 | int fclose(FILE *fp); 34 | ``` 35 | 在文件关闭前, 会flush缓冲区的数据. 当进程终止时, 会自动关闭所有打开的流. 36 | 37 | ### 读写流 38 | 标准IO读写流有三种方式: 每次一个字符; 每次一行; 读取指定数据结构和长度(二进制IO) 39 | 40 | #### 每次一个字符 41 | ```c 42 | #include 43 | //读 44 | int getc(FILE *fp); 45 | int fgetc(FILE *fp); 46 | int getchar(void); 47 | //写 48 | int putc(int c, FILE *fp); 49 | int fputc(int c, FILE *fp); 50 | int putchar(int c); 51 | ``` 52 | 53 | `getc`和`fgetc`的区别是:`getc`是宏, 而`fgetc`是真正的函数 54 | 55 | #### 每次一行 56 | ```c 57 | //读 58 | char *fgets(char *buf, int n, FILE *fp); 59 | char *gets(char *buf); 60 | //写 61 | int fputs(const char *str, FILE *fp); 62 | int puts(const char *str); 63 | ``` 64 | 65 | #### 二进制IO 66 | ```c 67 | size_t fread(void *ptr, size_t size, size_t nobj, FILE *fp); 68 | size_t fwrite(const void *ptr, size_t size, size_t nobj, FILE *fp); 69 | ``` 70 | 71 | 72 | -------------------------------------------------------------------------------- /AUP2/images/chapter3_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/images/chapter3_1.png -------------------------------------------------------------------------------- /AUP2/images/chapter3_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/images/chapter3_2.png -------------------------------------------------------------------------------- /AUP2/images/chapter7_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/images/chapter7_1.png -------------------------------------------------------------------------------- /AUP2/images/chapter7_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/images/chapter7_3.png -------------------------------------------------------------------------------- /AUP2/images/chapter8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/images/chapter8_1.png -------------------------------------------------------------------------------- /AUP2/images/未命名 1.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/images/未命名 1.odp -------------------------------------------------------------------------------- /AUP2/index.md: -------------------------------------------------------------------------------- 1 | 1. [Unix基础知识](chapter1.md) 2 | 1. UNIX标准及实现 3 | 1. [文件IO](chapter3.md) 4 | 1. [文件与目录](chapter4.md) 5 | 1. [标准IO库](chapter5.md) 6 | 1. 系统数据文件和信息 7 | 1. [进程环境](chapter7.md) 8 | 1. [进程控制](chapter8.md) 9 | 1. 进程关系 10 | 1. [信号](chapter10.md) 11 | 1. [线程](chapter11.md) 12 | -------------------------------------------------------------------------------- /AUP2/无标题文档 1~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/AUP2/无标题文档 1~ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 学习手记 2 | ========== 3 | 1. [Netty](netty/list.md) 4 | 1. [Spring](spring/index.md) 5 | 1. [Lucene](lucene/index.md) 6 | 1. [APUE](AUP2/index.md) 7 | 1. [Linux性能优化与实战](linux_tuning_practice/index.md) 8 | 1. [Recommended System](rs/index.md) 9 | 1. [NLP](nlp/index.md) 10 | 1. [Fluent Python](python/Fluent_Python.md) 11 | 1. [MySQL](mysql/index.md) 12 | 1. [ShardingSphere](shardingsphere/index.md) 13 | 1. [Linear Algebra (线性代数)](linear_algebra/index.md) 14 | 1. [计算机图形学入门](compute_graphic_guide/index.md) 15 | 1. [云原生模式](cloud_native_patterns/index.md) 16 | 1. [AWS Tutorial](aws_tutorial/index.md) 17 | -------------------------------------------------------------------------------- /aws_tutorial/index.md: -------------------------------------------------------------------------------- 1 | # AWS Tutorial 2 | 3 | ## VPC 4 | 5 | 1. Youtube: [https://www.youtube.com/watch?v=g2JOHLHh4rI](https://www.youtube.com/watch?v=g2JOHLHh4rI) 6 | 7 | ## IAM 8 | 9 | 1. Youtube: [https://www.youtube.com/watch?v=_ZCTvmaPgao](https://www.youtube.com/watch?v=_ZCTvmaPgao) 10 | -------------------------------------------------------------------------------- /cloud_native_patterns/index.md: -------------------------------------------------------------------------------- 1 | # 云原生模式读书笔记 2 | 3 | ![Clound Native Patterns](云原生模式.png) 4 | -------------------------------------------------------------------------------- /cloud_native_patterns/云原生模式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/cloud_native_patterns/云原生模式.png -------------------------------------------------------------------------------- /compute_graphic_guide/index.md: -------------------------------------------------------------------------------- 1 | # PPT 2 | [课程笔记ppt](计算机图形学入门分享.pdf) 3 | 4 | 5 | # Github 代码参考(Python) 6 | [Github tinyrenderer-py](https://github.com/hongfuli/tinyrenderer-py) 7 | -------------------------------------------------------------------------------- /compute_graphic_guide/计算机图形学入门分享.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/compute_graphic_guide/计算机图形学入门分享.pdf -------------------------------------------------------------------------------- /django/core_handlers.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/django/core_handlers.md -------------------------------------------------------------------------------- /django/core_management.md: -------------------------------------------------------------------------------- 1 | # 命令参数解析 2 | 3 | 4 | -------------------------------------------------------------------------------- /django/test.py: -------------------------------------------------------------------------------- 1 | import sys, os 2 | import argparse 3 | 4 | if __name__ == '__main__': 5 | parse = argparse.ArgumentParser(argument_default=12) 6 | parse.add_argument('--foo', help='foo help') 7 | parse.add_argument('--fe', help='fe help') 8 | parse.add_argument('bar', nargs='+', help='bar help') 9 | args = parse.parse_args() 10 | print('======', args) 11 | -------------------------------------------------------------------------------- /js/javascript.md: -------------------------------------------------------------------------------- 1 | # Javascript 高级程序设计 2 | 3 | 1. 变量/常量使用优先级:const > let > var; 4 | -------------------------------------------------------------------------------- /linear_algebra/10_four_subspaces/MIT18_06SCF11_Ses1.10prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/10_four_subspaces/MIT18_06SCF11_Ses1.10prob.pdf -------------------------------------------------------------------------------- /linear_algebra/10_four_subspaces/MIT18_06SCF11_Ses1.10sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/10_four_subspaces/MIT18_06SCF11_Ses1.10sol.pdf -------------------------------------------------------------------------------- /linear_algebra/11_graphs_incidence/MIT18_06SCF11_Ses1.12prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/11_graphs_incidence/MIT18_06SCF11_Ses1.12prob.pdf -------------------------------------------------------------------------------- /linear_algebra/11_graphs_incidence/MIT18_06SCF11_Ses1.12sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/11_graphs_incidence/MIT18_06SCF11_Ses1.12sol.pdf -------------------------------------------------------------------------------- /linear_algebra/12_orthogonal_vectors/MIT18_06SCF11_Ses2.1prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/12_orthogonal_vectors/MIT18_06SCF11_Ses2.1prob.pdf -------------------------------------------------------------------------------- /linear_algebra/12_orthogonal_vectors/MIT18_06SCF11_Ses2.1sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/12_orthogonal_vectors/MIT18_06SCF11_Ses2.1sol.pdf -------------------------------------------------------------------------------- /linear_algebra/13_projections_subspaces/MIT18_06SCF11_Ses2.2prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/13_projections_subspaces/MIT18_06SCF11_Ses2.2prob.pdf -------------------------------------------------------------------------------- /linear_algebra/13_projections_subspaces/MIT18_06SCF11_Ses2.2sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/13_projections_subspaces/MIT18_06SCF11_Ses2.2sol.pdf -------------------------------------------------------------------------------- /linear_algebra/14_projection_and_least_squares/MIT18_06SCF11_Ses2.3prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/14_projection_and_least_squares/MIT18_06SCF11_Ses2.3prob.pdf -------------------------------------------------------------------------------- /linear_algebra/14_projection_and_least_squares/MIT18_06SCF11_Ses2.3sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/14_projection_and_least_squares/MIT18_06SCF11_Ses2.3sol.pdf -------------------------------------------------------------------------------- /linear_algebra/15_orthogoanl_gram_schmidt/MIT18_06SCF11_Ses2.4prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/15_orthogoanl_gram_schmidt/MIT18_06SCF11_Ses2.4prob.pdf -------------------------------------------------------------------------------- /linear_algebra/15_orthogoanl_gram_schmidt/MIT18_06SCF11_Ses2.4sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/15_orthogoanl_gram_schmidt/MIT18_06SCF11_Ses2.4sol.pdf -------------------------------------------------------------------------------- /linear_algebra/16_properties_of_determinants/MIT18_06SCF11_Ses2.5prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/16_properties_of_determinants/MIT18_06SCF11_Ses2.5prob.pdf -------------------------------------------------------------------------------- /linear_algebra/16_properties_of_determinants/MIT18_06SCF11_Ses2.5sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/16_properties_of_determinants/MIT18_06SCF11_Ses2.5sol.pdf -------------------------------------------------------------------------------- /linear_algebra/17_determinant_formulas_cofactors/MIT18_06SCF11_Ses2.6prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/17_determinant_formulas_cofactors/MIT18_06SCF11_Ses2.6prob.pdf -------------------------------------------------------------------------------- /linear_algebra/17_determinant_formulas_cofactors/MIT18_06SCF11_Ses2.6sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/17_determinant_formulas_cofactors/MIT18_06SCF11_Ses2.6sol.pdf -------------------------------------------------------------------------------- /linear_algebra/18_cramer_inverse_volume/MIT18_06SCF11_Ses2.7prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/18_cramer_inverse_volume/MIT18_06SCF11_Ses2.7prob.pdf -------------------------------------------------------------------------------- /linear_algebra/18_cramer_inverse_volume/MIT18_06SCF11_Ses2.7sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/18_cramer_inverse_volume/MIT18_06SCF11_Ses2.7sol.pdf -------------------------------------------------------------------------------- /linear_algebra/19_eigenvalues_eigenvectors/MIT18_06SCF11_Ses2.8prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/19_eigenvalues_eigenvectors/MIT18_06SCF11_Ses2.8prob.pdf -------------------------------------------------------------------------------- /linear_algebra/19_eigenvalues_eigenvectors/MIT18_06SCF11_Ses2.8sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/19_eigenvalues_eigenvectors/MIT18_06SCF11_Ses2.8sol.pdf -------------------------------------------------------------------------------- /linear_algebra/1_the_geometry_of_linear_equations/MIT18_06SCF11_Ses1.1prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/1_the_geometry_of_linear_equations/MIT18_06SCF11_Ses1.1prob.pdf -------------------------------------------------------------------------------- /linear_algebra/1_the_geometry_of_linear_equations/MIT18_06SCF11_Ses1.1sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/1_the_geometry_of_linear_equations/MIT18_06SCF11_Ses1.1sol.pdf -------------------------------------------------------------------------------- /linear_algebra/1_the_geometry_of_linear_equations/MIT18_06SCF11_Ses1.1sum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/1_the_geometry_of_linear_equations/MIT18_06SCF11_Ses1.1sum.pdf -------------------------------------------------------------------------------- /linear_algebra/20_powers_of_matrix/MIT18_06SCF11_Ses2.9prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/20_powers_of_matrix/MIT18_06SCF11_Ses2.9prob.pdf -------------------------------------------------------------------------------- /linear_algebra/20_powers_of_matrix/MIT18_06SCF11_Ses2.9sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/20_powers_of_matrix/MIT18_06SCF11_Ses2.9sol.pdf -------------------------------------------------------------------------------- /linear_algebra/2_elimination_with_matrices/MIT18_06SCF11_Ses1.2prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/2_elimination_with_matrices/MIT18_06SCF11_Ses1.2prob.pdf -------------------------------------------------------------------------------- /linear_algebra/2_elimination_with_matrices/MIT18_06SCF11_Ses1.2sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/2_elimination_with_matrices/MIT18_06SCF11_Ses1.2sol.pdf -------------------------------------------------------------------------------- /linear_algebra/2_elimination_with_matrices/MIT18_06SCF11_Ses1.2sum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/2_elimination_with_matrices/MIT18_06SCF11_Ses1.2sum.pdf -------------------------------------------------------------------------------- /linear_algebra/3_multiplication_and_inverse_matrices/MIT18_06SCF11_Ses1.3prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/3_multiplication_and_inverse_matrices/MIT18_06SCF11_Ses1.3prob.pdf -------------------------------------------------------------------------------- /linear_algebra/3_multiplication_and_inverse_matrices/MIT18_06SCF11_Ses1.3sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/3_multiplication_and_inverse_matrices/MIT18_06SCF11_Ses1.3sol.pdf -------------------------------------------------------------------------------- /linear_algebra/3_multiplication_and_inverse_matrices/MIT18_06SCF11_Ses1.3sum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/3_multiplication_and_inverse_matrices/MIT18_06SCF11_Ses1.3sum.pdf -------------------------------------------------------------------------------- /linear_algebra/4_factorization_LU/MIT18_06SCF11_Ses1.4prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/4_factorization_LU/MIT18_06SCF11_Ses1.4prob.pdf -------------------------------------------------------------------------------- /linear_algebra/4_factorization_LU/MIT18_06SCF11_Ses1.4sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/4_factorization_LU/MIT18_06SCF11_Ses1.4sol.pdf -------------------------------------------------------------------------------- /linear_algebra/4_factorization_LU/MIT18_06SCF11_Ses1.4sum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/4_factorization_LU/MIT18_06SCF11_Ses1.4sum.pdf -------------------------------------------------------------------------------- /linear_algebra/5_trans_permu_vector/MIT18_06SCF11_Ses1.5prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/5_trans_permu_vector/MIT18_06SCF11_Ses1.5prob.pdf -------------------------------------------------------------------------------- /linear_algebra/5_trans_permu_vector/MIT18_06SCF11_Ses1.5sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/5_trans_permu_vector/MIT18_06SCF11_Ses1.5sol.pdf -------------------------------------------------------------------------------- /linear_algebra/5_trans_permu_vector/MIT18_06SCF11_Ses1.5sum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/5_trans_permu_vector/MIT18_06SCF11_Ses1.5sum.pdf -------------------------------------------------------------------------------- /linear_algebra/5_trans_permu_vector/sol.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/5_trans_permu_vector/sol.jpeg -------------------------------------------------------------------------------- /linear_algebra/6_column_space/MIT18_06SCF11_Ses1.6prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/6_column_space/MIT18_06SCF11_Ses1.6prob.pdf -------------------------------------------------------------------------------- /linear_algebra/6_column_space/MIT18_06SCF11_Ses1.6sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/6_column_space/MIT18_06SCF11_Ses1.6sol.pdf -------------------------------------------------------------------------------- /linear_algebra/6_column_space/MIT18_06SCF11_Ses1.6sum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/6_column_space/MIT18_06SCF11_Ses1.6sum.pdf -------------------------------------------------------------------------------- /linear_algebra/7_pivot_variables/MIT18_06SCF11_Ses1.7prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/7_pivot_variables/MIT18_06SCF11_Ses1.7prob.pdf -------------------------------------------------------------------------------- /linear_algebra/7_pivot_variables/MIT18_06SCF11_Ses1.7sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/7_pivot_variables/MIT18_06SCF11_Ses1.7sol.pdf -------------------------------------------------------------------------------- /linear_algebra/8_rrfr/MIT18_06SCF11_Ses1.8prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/8_rrfr/MIT18_06SCF11_Ses1.8prob.pdf -------------------------------------------------------------------------------- /linear_algebra/8_rrfr/MIT18_06SCF11_Ses1.8sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/8_rrfr/MIT18_06SCF11_Ses1.8sol.pdf -------------------------------------------------------------------------------- /linear_algebra/9_indepence/MIT18_06SCF11_Ses1.9prob.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/9_indepence/MIT18_06SCF11_Ses1.9prob.pdf -------------------------------------------------------------------------------- /linear_algebra/9_indepence/MIT18_06SCF11_Ses1.9sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linear_algebra/9_indepence/MIT18_06SCF11_Ses1.9sol.pdf -------------------------------------------------------------------------------- /linear_algebra/index.md: -------------------------------------------------------------------------------- 1 | MIT OCW : Linear Algebra 2 | ======================== 3 | 4 | 1. [The Geometry of Linear Equations](1_the_geometry_of_linear_equations/) 5 | 2. [Elimination with Matrice](2_elimination_with_matrices/) 6 | 3. [Multiplication and Inverse Matrices](3_multiplication_and_inverse_matrices/) 7 | 4. [Factorization into A = LU](4_factorization_LU/) 8 | 5. [Transposes, Permutations, Vector Spaces](5_trans_permu_vector/) 9 | 6. [Column Space and Nullspace](6_column_space/) 10 | 7. [Ax=0: Pivot variables, special solutions](7_pivot_variables/) 11 | 8. [Ax=b: Row Reduced Form R](8_rrfr/) 12 | 9. [Independence, Basis and Dimension](9_indepence/) 13 | 10. [The Four Fundamental Subspaces](10_four_subspaces/) 14 | 11. [Graphs, Networks, Incidence Matrics](11_graphs_incidence/) 15 | 12. [Orthogonal Vectors and Subspaces](12_orthogonal_vectors/) 16 | 13. [Projections onto Subspaces](13_projections_subspaces/) 17 | 14. [Projection Matrices and Least Squares](14_projection_and_least_squares/) 18 | 15. [Orthogonal Matrices and Gram-Schmidt](15_orthogoanl_gram_schmidt/) 19 | 16. [Properties of Determinants](16_properties_of_determinants/) 20 | 17. [Determinant Formulas and Cofactors](17_determinant_formulas_cofactors/) 21 | 18. [Cramer's Rule, Inverse Matrix and Volume](18_cramer_inverse_volume/) 22 | 19. [Eigenvalues and Eigenvectors](19_eigenvalues_eigenvectors/) 23 | 20. [Diagonalization and Powers of A](20_powers_of_matrix/) 24 | 21. [Differential Equations and exp(At)](21_differential_equations/) 25 | 22. [Markov Matrices and Fourier Series](22_markov_matrices/) 26 | -------------------------------------------------------------------------------- /linux_tuning_practice/cpu.md: -------------------------------------------------------------------------------- 1 | ## cpu load averages 2 | 周期时间内“正在运行”或者”等待运行“的平均进程数。它和CPU的使用率没有什么关系。 3 | 4 | ## 压力测试工具 5 | stress, sysbench 6 | 7 | ## CPU上下文 8 | CPU上下文一般指任务执行时CPU寄存器和程序计数器保存的数据,分别用来保存当前执行的一些指令和程序执行点位置。 9 | 10 | 而CPU上下文切换就是多个任务在使用同一个CPU时,上述数据的交换切入和切出。 11 | 12 | 切换是有成本的。 13 | 14 | ### CPU上下文切换 15 | 如果同一个进程或者线程内发生系统调用,会发生上下文切换吗?我之前的理解是没有,其实肯定是有的。因为CPU上面的指令是需要从用户态切换到内核态执行的。 16 | 17 | 但是和进程上下文切换不同,因为进程都是独立的虚拟内存空间和全局环境变量,所以需要CPU切换这些数据。 18 | 19 | ### CPU切换时间点 20 | 1. 当前执行任务完成。 21 | 2. 系统资源不足时,比如内存不足,网络数据未达到,进程会挂起。 22 | 3. 通过sleep相关函数调用。 23 | 4. 多个任务竞争,且其它任务优先级更高时。 24 | 5. 硬件中断时,需要执行内核中的中断处理程序。 25 | 26 | ### 线程上下文切换 27 | 首先需要理解进程,线程的区别。内核中的任务调度,操作的对象都是线程切换。一句话总结:线程是调度的基本单位,进程是资源拥有的基本单位。 28 | 进程内所有线程共享所有内存,全局变量。 29 | 30 | ### 中断上下文切换 31 | 中断上下文切换和进程上下文不同,因为中断都是内核态的,所以没有虚拟内存和全局变量的切换。而且中断一般拥有更高的优先级。 32 | 33 | ### 上下文切换的成本 34 | CPU上下文切换,会消耗很多时间在CPU寄存器和计数器在不断的存储和恢复上,缩短CPU真实计算的时间,导致利用率下降。 35 | 36 | ## 诊断工作 37 | uptime, pidstat, vmstat, top, perf 38 | 39 | 短进程总是的诊断(创建后很快结束),需要使用pstree,execsnoop或者perf top。 40 | 41 | ![CPU性能指标](images/linux_tuning_cpu_01.png) 42 | ![CPU性能指标](images/linux_tuning_cpu_02.png) 43 | ![CPU性能指标](images/linux_tuning_cpu_03.png) 44 | ![CPU性能指标](images/linux_tuning_cpu_04.png) 45 | -------------------------------------------------------------------------------- /linux_tuning_practice/file_system.md: -------------------------------------------------------------------------------- 1 | # 文件结构:索引节点及目录项 2 | ![file_struct](images/file_01.png) 3 | ![file_global](images/file_global.png) 4 | ![file_md](images/file_md.png) 5 | ![file_tuning_1](images/file_tuning_1.png) 6 | ![file_tuning_2](images/file_tuning_2.png) 7 | ![file_tuning_3](images/file_tuning_3.png) 8 | 9 | 10 | # 性能测试 11 | fio 12 | 13 | -------------------------------------------------------------------------------- /linux_tuning_practice/images/file_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/file_01.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/file_global.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/file_global.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/file_md.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/file_md.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/file_tuning_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/file_tuning_1.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/file_tuning_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/file_tuning_2.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/file_tuning_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/file_tuning_3.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/linux_tuning_cpu_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/linux_tuning_cpu_01.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/linux_tuning_cpu_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/linux_tuning_cpu_02.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/linux_tuning_cpu_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/linux_tuning_cpu_03.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/linux_tuning_cpu_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/linux_tuning_cpu_04.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/memory_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/memory_01.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/memory_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/memory_02.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/memory_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/memory_03.png -------------------------------------------------------------------------------- /linux_tuning_practice/images/memory_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/linux_tuning_practice/images/memory_04.png -------------------------------------------------------------------------------- /linux_tuning_practice/index.md: -------------------------------------------------------------------------------- 1 | Linux性能优化实战 - 倪朋飞 2 | ======== 3 | 1. [CPU性能问题分析](cpu.md) 4 | 1. [内存性能分析](memory_01.md) 5 | 1. [文件系统](file_system.md) 6 | 1. [网络](network.md) 7 | 8 | -------------------------------------------------------------------------------- /linux_tuning_practice/memory_01.md: -------------------------------------------------------------------------------- 1 | # Buffer/Cache含义 2 | Buffer用于磁盘的读写缓存。Cache用于文件的读写缓存。 3 | 4 | # bcc memleak 5 | `memleak`可以动态追踪内存泄漏。 6 | 7 | # Swap 8 | 当内存不足时,通过回收buff/cache(也称文件页)来释放内存。 9 | 还一个方法是回收不活跃进程的动态堆内存(也称匿名页)。 10 | 11 | # 常用分析工具 12 | ![001](images/memory_01.png) 13 | ![002](images/memory_02.png) 14 | ![003](images/memory_03.png) 15 | ![004](images/memory_04.png) 16 | -------------------------------------------------------------------------------- /linux_tuning_practice/network.md: -------------------------------------------------------------------------------- 1 | # 网络性能指标 2 | 带宽,吞吐量,延时,PPS。 3 | -------------------------------------------------------------------------------- /lucene/analyzer.md: -------------------------------------------------------------------------------- 1 | # 分词 2 | 「分词(tokenizer)」在IR系统占据比较重要的一块,它直接影响我们查询的召回率。我们知道索引文件中是以term为单位,而且IR系统中原始文件和查询的输入都是整个词组,句子或者文章,IR系统要把它们切分成一个个的term, 然后组织索引文件。因为世界语言丰富性及行业专业词汇存在,分词也有一定复杂性。而在 Lucene 中,它提供了一套可扩展完备的API接口方便大家提供自己的分词逻辑,而且 Lucene 本身也内置提供了一些功能强大的分词词。 3 | 4 | ## Lucene API Spec 5 | 6 | ![Analysis Api](images/ana_spec_api.png) 7 | 8 | Notes: 9 | 10 | * 自定义扩展分词器,继承自 Analyzer。 11 | * 但是一般分词逻辑在自定义的 TokenStream 中,由 Analyzer 调用 TokenStream,所以 Analyzer 一般写成匿名实现。 12 | * TokenStream是个抽象类,它有两个很重要的抽象子类:Tokenizer 和 TokenFilter 13 | * Tokenizer 和 TokenFilter 的作用区别。Tokenizer的输入是 Reader,对输入做分词的核心逻辑在这里实现;而 TokenFilter 的输入是 TokenStream,对原始 TokenStream 包装并加强。大家应该看出用的是「装饰器模式」。所以自定义的 Tokenizer 一般用 final 修饰,其它人想加强或者附加功能会以 Tokenizer 为输入。 14 | * TokenStream 继承自 AttributeSource,而 AttributeSource 是聚合 Attribute 的容器。所以 TokenStream 一般会在通过在分词过程中保存很多信息供外部使用。一般使用的多的是:OffsetAttribute 和 CharTermAttribute,前者保存Term的偏移量,后者保存Term的本身信息。 15 | -------------------------------------------------------------------------------- /lucene/blog.graffle/data.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/blog.graffle/data.plist -------------------------------------------------------------------------------- /lucene/blog.graffle/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/blog.graffle/image1.png -------------------------------------------------------------------------------- /lucene/blog.graffle/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/blog.graffle/image2.png -------------------------------------------------------------------------------- /lucene/blog_4.md: -------------------------------------------------------------------------------- 1 | 高效写入索引(Lucene) 2 | -------------------------------------------------------------------------------- /lucene/class_search.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/class_search.jpg -------------------------------------------------------------------------------- /lucene/d.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/d.odg -------------------------------------------------------------------------------- /lucene/document.md: -------------------------------------------------------------------------------- 1 | # Document, Field 核心 2 | 3 | Field 类中有几个重要的属性配置:IndexOptions,。。。 4 | 5 | ## IndexOptions(替换老版本的TermVector,Index) 6 | 枚举值,主要在索引时存储的信息量多少。并不是信息存储得越多越好,因为一是浪费静态存储空间和动态运行时内存,比如日期类型的字段,我们不会去做向量空间对比,权重排序,只是做简单查询和过滤,所以出现的次数或者所在的位置就不是那么重要。 7 | 8 | ## Field 9 | ### boost 10 | 每个 Document 都是由多个 Field 组成, 我们在检索查询时,提供的字段关键词的影响权值不是相同的,比如一个网页,可以标题就比内容占有更高的权值,通过设置 Field 的 boost 值来影响各字段的权值。 11 | 12 | ### Norm 13 | normilization,针对每个 Field 词项长度做规一化处理。即越长的内容,其 norm 值越低。当某个字段其长度比较一致平衡时,可以设置 omitNorm,节约存储和计算量。 -------------------------------------------------------------------------------- /lucene/images/add_doc_seq.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/add_doc_seq.jpg -------------------------------------------------------------------------------- /lucene/images/ana_spec_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/ana_spec_api.png -------------------------------------------------------------------------------- /lucene/images/blog1_js_web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog1_js_web.png -------------------------------------------------------------------------------- /lucene/images/blog1_tushuguang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog1_tushuguang.jpg -------------------------------------------------------------------------------- /lucene/images/blog2_fuzzy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog2_fuzzy.png -------------------------------------------------------------------------------- /lucene/images/blog2_tree.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog2_tree.jpg -------------------------------------------------------------------------------- /lucene/images/blog2_wildpre.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog2_wildpre.jpg -------------------------------------------------------------------------------- /lucene/images/blog3_cos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_cos.jpg -------------------------------------------------------------------------------- /lucene/images/blog3_coswiki.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_coswiki.jpg -------------------------------------------------------------------------------- /lucene/images/blog3_idf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_idf.png -------------------------------------------------------------------------------- /lucene/images/blog3_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_norm.png -------------------------------------------------------------------------------- /lucene/images/blog3_sim_art.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_sim_art.png -------------------------------------------------------------------------------- /lucene/images/blog3_sim_q_doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_sim_q_doc.png -------------------------------------------------------------------------------- /lucene/images/blog3_sim_q_doc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_sim_q_doc1.png -------------------------------------------------------------------------------- /lucene/images/blog3_tf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_tf.jpg -------------------------------------------------------------------------------- /lucene/images/blog3_zb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog3_zb.jpg -------------------------------------------------------------------------------- /lucene/images/blog_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog_1.jpg -------------------------------------------------------------------------------- /lucene/images/blog_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog_2.jpg -------------------------------------------------------------------------------- /lucene/images/blog_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog_3.png -------------------------------------------------------------------------------- /lucene/images/blog_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/blog_4.jpg -------------------------------------------------------------------------------- /lucene/images/dwpt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/dwpt.png -------------------------------------------------------------------------------- /lucene/images/fnm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/fnm.jpg -------------------------------------------------------------------------------- /lucene/images/search_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/search_01.jpg -------------------------------------------------------------------------------- /lucene/images/search_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/search_02.jpg -------------------------------------------------------------------------------- /lucene/images/segment.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/segment.jpg -------------------------------------------------------------------------------- /lucene/images/segments.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/images/segments.jpg -------------------------------------------------------------------------------- /lucene/index.md: -------------------------------------------------------------------------------- 1 | # 目录 2 | 3 | 1. [索引](_index.md) 4 | 1. [相关性计算](scores.md) 5 | 1. [存储](store.md) 6 | 1. [查询](search.md) 7 | 1. [分词](analyzer.md) 8 | 1. [文档](documentst.md) 9 | 1. [工具](utils.md) 10 | -------------------------------------------------------------------------------- /lucene/scores.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/scores.md -------------------------------------------------------------------------------- /lucene/search.md: -------------------------------------------------------------------------------- 1 | # 查询(Search) 2 | Lucene中负责查询功能的代码都放在`org.apache.lucene.search`包下。根据查询表达式得到我们想要的查询结果,这是检索系统最终的需求,比如大家用google就是主要操作查询。 3 | 4 | ## 查询主要模块(接口,类关系) 5 | 主要构件组成图如下: 6 | 7 | ![查询构件](images/search_01.jpg) 8 | 9 | ## search方法主要流程(类方法交互调用) 10 | 11 | ![查询seq图](images/search_02.jpg) 12 | 13 | ## 一些详细过程分析 14 | 整个查询模块有几个核心构件组成,IndexSearch是总体入口,直接对外提供各种search api方法。内部通过 Query, Weight,Scorer。这种设计把整个查询的主工作流程抽象出来统一,然后每个具体的查询逻辑只要扩展相应的Query,Weight就可以了。 15 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/LucenePackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene; 18 | 19 | 20 | /** Lucene's package information, including version. **/ 21 | public final class LucenePackage { 22 | 23 | private LucenePackage() {} // can't construct 24 | 25 | /** Return Lucene's package, including version information. */ 26 | public static Package get() { 27 | return LucenePackage.class.getPackage(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/analysis/tokenattributes/BytesTermAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.analysis.tokenattributes; 18 | 19 | 20 | import org.apache.lucene.util.BytesRef; 21 | 22 | /** 23 | * This attribute can be used if you have the raw term bytes to be indexed. 24 | * It can be used as replacement for {@link CharTermAttribute}, if binary 25 | * terms should be indexed. 26 | * @lucene.internal 27 | */ 28 | public interface BytesTermAttribute extends TermToBytesRefAttribute { 29 | /** Sets the {@link BytesRef} of the term */ 30 | public void setBytesRef(BytesRef bytes); 31 | } -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/analysis/tokenattributes/TypeAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.analysis.tokenattributes; 18 | 19 | 20 | import org.apache.lucene.util.Attribute; 21 | 22 | /** 23 | * A Token's lexical type. The Default value is "word". 24 | */ 25 | public interface TypeAttribute extends Attribute { 26 | 27 | /** the default type */ 28 | public static final String DEFAULT_TYPE = "word"; 29 | 30 | /** 31 | * Returns this Token's lexical type. Defaults to "word". 32 | * @see #setType(String) 33 | */ 34 | public String type(); 35 | 36 | /** 37 | * Set the lexical type. 38 | * @see #type() 39 | */ 40 | public void setType(String type); 41 | } 42 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/analysis/tokenattributes/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * General-purpose attributes for text analysis. 20 | */ 21 | package org.apache.lucene.analysis.tokenattributes; 22 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/StoredFieldsFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.codecs; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.lucene.index.FieldInfos; 23 | import org.apache.lucene.index.SegmentInfo; 24 | import org.apache.lucene.store.Directory; 25 | import org.apache.lucene.store.IOContext; 26 | 27 | /** 28 | * Controls the format of stored fields 29 | */ 30 | public abstract class StoredFieldsFormat { 31 | /** Sole constructor. (For invocation by subclass 32 | * constructors, typically implicit.) */ 33 | protected StoredFieldsFormat() { 34 | } 35 | 36 | /** Returns a {@link StoredFieldsReader} to load stored 37 | * fields. */ 38 | public abstract StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) throws IOException; 39 | 40 | /** Returns a {@link StoredFieldsWriter} to write stored 41 | * fields. */ 42 | public abstract StoredFieldsWriter fieldsWriter(Directory directory, SegmentInfo si, IOContext context) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/TermStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.codecs; 18 | 19 | 20 | import org.apache.lucene.index.TermsEnum; // javadocs 21 | 22 | /** 23 | * Holder for per-term statistics. 24 | * 25 | * @see TermsEnum#docFreq 26 | * @see TermsEnum#totalTermFreq 27 | */ 28 | public class TermStats { 29 | /** How many documents have at least one occurrence of 30 | * this term. */ 31 | public final int docFreq; 32 | 33 | /** Total number of times this term occurs across all 34 | * documents in the field. */ 35 | public final long totalTermFreq; 36 | 37 | /** Sole constructor. */ 38 | public TermStats(int docFreq, long totalTermFreq) { 39 | this.docFreq = docFreq; 40 | this.totalTermFreq = totalTermFreq; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/blocktree/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * BlockTree terms dictionary. 20 | * 21 | *

22 | * This terms dictionary organizes all terms into blocks according to 23 | * shared prefix, such that each block has enough terms, and then stores 24 | * the prefix trie in memory as an FST as the index structure. It allows 25 | * you to plug in your own {@link 26 | * org.apache.lucene.codecs.PostingsWriterBase} to implement the 27 | * postings. 28 | *

29 | * 30 | *

See {@link org.apache.lucene.codecs.blocktree.BlockTreeTermsWriter} 31 | * for the file format. 32 | *

33 | */ 34 | package org.apache.lucene.codecs.blocktree; 35 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/compressing/Compressor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.codecs.compressing; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.lucene.store.DataOutput; 23 | 24 | /** 25 | * A data compressor. 26 | */ 27 | public abstract class Compressor { 28 | 29 | /** Sole constructor, typically called from sub-classes. */ 30 | protected Compressor() {} 31 | 32 | /** 33 | * Compress bytes into out. It it the responsibility of the 34 | * compressor to add all necessary information so that a {@link Decompressor} 35 | * will know when to stop decompressing bytes from the stream. 36 | */ 37 | public abstract void compress(byte[] bytes, int off, int len, DataOutput out) throws IOException; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/compressing/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * StoredFieldsFormat that allows cross-document and cross-field compression of stored fields. 20 | */ 21 | package org.apache.lucene.codecs.compressing; 22 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/lucene50/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Components from the Lucene 5.0 index format 20 | * See {@link org.apache.lucene.codecs.lucene53} for an overview 21 | * of the index format. 22 | */ 23 | package org.apache.lucene.codecs.lucene50; 24 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/lucene53/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Components from the Lucene 5.3 index format 20 | * See {@link org.apache.lucene.codecs.lucene54} for an overview 21 | * of the index format. 22 | */ 23 | package org.apache.lucene.codecs.lucene53; 24 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/codecs/perfield/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Postings format that can delegate to different formats per-field. 20 | */ 21 | package org.apache.lucene.codecs.perfield; 22 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/geo/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Geospatial Utility Implementations for Lucene Core 20 | */ 21 | package org.apache.lucene.geo; -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/AbortingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** Thrown and caught internally in {@link IndexWriter} methods when an {@code IOException} would cause it to 21 | * lose previously indexed documents. When this happens, the {@link IndexWriter} is forcefully 22 | * closed, using {@link IndexWriter#rollback}). */ 23 | class AbortingException extends Exception { 24 | private AbortingException(Throwable cause) { 25 | super(cause); 26 | assert cause instanceof AbortingException == false; 27 | } 28 | 29 | public static AbortingException wrap(Throwable t) { 30 | if (t instanceof AbortingException) { 31 | return (AbortingException) t; 32 | } else { 33 | return new AbortingException(t); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/BinaryDocValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import org.apache.lucene.util.BytesRef; 21 | 22 | /** 23 | * A per-document byte[] 24 | */ 25 | public abstract class BinaryDocValues { 26 | 27 | /** Sole constructor. (For invocation by subclass 28 | * constructors, typically implicit.) */ 29 | protected BinaryDocValues() {} 30 | 31 | /** Lookup the value for document. The returned {@link BytesRef} may be 32 | * re-used across calls to {@link #get(int)} so make sure to 33 | * {@link BytesRef#deepCopyOf(BytesRef) copy it} if you want to keep it 34 | * around. */ 35 | public abstract BytesRef get(int docID); 36 | } 37 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/DocConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | abstract class DocConsumer { 23 | abstract void processDocument() throws IOException, AbortingException; 24 | abstract void flush(final SegmentWriteState state) throws IOException, AbortingException; 25 | abstract void abort(); 26 | } 27 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/DocValuesWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.lucene.codecs.DocValuesConsumer; 23 | 24 | abstract class DocValuesWriter { 25 | abstract void finish(int numDoc); 26 | abstract void flush(SegmentWriteState state, DocValuesConsumer consumer) throws IOException; 27 | } 28 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/FieldTermIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import org.apache.lucene.util.BytesRefIterator; 21 | 22 | /** Iterates over terms in across multiple fields. The caller must 23 | * check {@link #field} after each {@link #next} to see if the field 24 | * changed, but {@code ==} can be used since the iterator 25 | * implementation ensures it will use the same String instance for 26 | * a given field. */ 27 | 28 | abstract class FieldTermIterator implements BytesRefIterator { 29 | /** Returns current field. This method should not be called 30 | * after iteration is done. Note that you may use == to 31 | * detect a change in field. */ 32 | abstract String field(); 33 | 34 | /** Del gen of the current term. */ 35 | // TODO: this is really per-iterator not per term, but when we use MergedPrefixCodedTermsIterator we need to know which iterator we are on 36 | abstract long delGen(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/IndexNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import java.io.FileNotFoundException; 21 | 22 | /** 23 | * Signals that no index was found in the Directory. Possibly because the 24 | * directory is empty, however can also indicate an index corruption. 25 | */ 26 | public final class IndexNotFoundException extends FileNotFoundException { 27 | 28 | /** Creates IndexFileNotFoundException with the 29 | * description message. */ 30 | public IndexNotFoundException(String msg) { 31 | super(msg); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/MergeTrigger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** 21 | * MergeTrigger is passed to 22 | * {@link org.apache.lucene.index.MergePolicy#findMerges(MergeTrigger, org.apache.lucene.index.SegmentInfos, IndexWriter)} to indicate the 23 | * event that triggered the merge. 24 | */ 25 | public enum MergeTrigger { 26 | /** 27 | * Merge was triggered by a segment flush. 28 | */ 29 | SEGMENT_FLUSH, 30 | 31 | /** 32 | * Merge was triggered by a full flush. Full flushes 33 | * can be caused by a commit, NRT reader reopen or a close call on the index writer. 34 | */ 35 | FULL_FLUSH, 36 | 37 | /** 38 | * Merge has been triggered explicitly by the user. 39 | */ 40 | EXPLICIT, 41 | 42 | /** 43 | * Merge was triggered by a successfully finished merge. 44 | */ 45 | MERGE_FINISHED, 46 | 47 | /** 48 | * Merge was triggered by a closing IndexWriter. 49 | */ 50 | CLOSING 51 | } 52 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/NoDeletionPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * An {@link IndexDeletionPolicy} which keeps all index commits around, never 24 | * deleting them. This class is a singleton and can be accessed by referencing 25 | * {@link #INSTANCE}. 26 | */ 27 | public final class NoDeletionPolicy extends IndexDeletionPolicy { 28 | 29 | /** The single instance of this class. */ 30 | public static final IndexDeletionPolicy INSTANCE = new NoDeletionPolicy(); 31 | 32 | private NoDeletionPolicy() { 33 | // keep private to avoid instantiation 34 | } 35 | 36 | @Override 37 | public void onCommit(List commits) {} 38 | 39 | @Override 40 | public void onInit(List commits) {} 41 | 42 | @Override 43 | public IndexDeletionPolicy clone() { 44 | return this; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/NumericDocValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** 21 | * A per-document numeric value. 22 | */ 23 | public abstract class NumericDocValues { 24 | 25 | /** Sole constructor. (For invocation by subclass 26 | * constructors, typically implicit.) */ 27 | protected NumericDocValues() {} 28 | 29 | /** 30 | * Returns the numeric value for the specified document ID. 31 | * @param docID document ID to lookup 32 | * @return numeric value 33 | */ 34 | public abstract long get(int docID); 35 | } 36 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/OrdTermState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** 21 | * An ordinal based {@link TermState} 22 | * 23 | * @lucene.experimental 24 | */ 25 | public class OrdTermState extends TermState { 26 | /** Term ordinal, i.e. its position in the full list of 27 | * sorted terms. */ 28 | public long ord; 29 | 30 | /** Sole constructor. */ 31 | public OrdTermState() { 32 | } 33 | 34 | @Override 35 | public void copyFrom(TermState other) { 36 | assert other instanceof OrdTermState : "can not copy from " + other.getClass().getName(); 37 | this.ord = ((OrdTermState) other).ord; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "OrdTermState ord=" + ord; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/QueryTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** 21 | * Base for query timeout implementations, which will provide a {@code shouldExit()} method, 22 | * used with {@link ExitableDirectoryReader}. 23 | */ 24 | public interface QueryTimeout { 25 | 26 | /** 27 | * Called from {@link ExitableDirectoryReader.ExitableTermsEnum#next()} 28 | * to determine whether to stop processing a query. 29 | */ 30 | public abstract boolean shouldExit(); 31 | 32 | /** Returns true if timeouts are enabled for this query (i.e. if shouldExit would ever return true) */ 33 | public default boolean isTimeoutEnabled() { 34 | return true; 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/ReaderSlice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** 21 | * Subreader slice from a parent composite reader. 22 | * 23 | * @lucene.internal 24 | */ 25 | public final class ReaderSlice { 26 | 27 | /** Zero-length {@code ReaderSlice} array. */ 28 | public static final ReaderSlice[] EMPTY_ARRAY = new ReaderSlice[0]; 29 | 30 | /** Document ID this slice starts from. */ 31 | public final int start; 32 | 33 | /** Number of documents in this slice. */ 34 | public final int length; 35 | 36 | /** Sub-reader index for this slice. */ 37 | public final int readerIndex; 38 | 39 | /** Sole constructor. */ 40 | public ReaderSlice(int start, int length, int readerIndex) { 41 | this.start = start; 42 | this.length = length; 43 | this.readerIndex = readerIndex; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "slice start=" + start + " length=" + length + " readerIndex=" + readerIndex; 49 | } 50 | } -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/SerialMergeScheduler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | /** A {@link MergeScheduler} that simply does each merge 23 | * sequentially, using the current thread. */ 24 | public class SerialMergeScheduler extends MergeScheduler { 25 | 26 | /** Sole constructor. */ 27 | public SerialMergeScheduler() { 28 | } 29 | 30 | /** Just do the merges in sequence. We do this 31 | * "synchronized" so that even if the application is using 32 | * multiple threads, only one merge may run at a time. */ 33 | @Override 34 | synchronized public void merge(IndexWriter writer, MergeTrigger trigger, boolean newMergesFound) throws IOException { 35 | 36 | while(true) { 37 | MergePolicy.OneMerge merge = writer.getNextMerge(); 38 | if (merge == null) 39 | break; 40 | writer.merge(merge); 41 | } 42 | } 43 | 44 | @Override 45 | public void close() {} 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/index/SortedNumericDocValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.index; 18 | 19 | 20 | /** 21 | * A list of per-document numeric values, sorted 22 | * according to {@link Long#compare(long, long)}. 23 | */ 24 | public abstract class SortedNumericDocValues { 25 | 26 | /** Sole constructor. (For invocation by subclass 27 | * constructors, typically implicit.) */ 28 | protected SortedNumericDocValues() {} 29 | 30 | /** 31 | * Positions to the specified document 32 | */ 33 | public abstract void setDocument(int doc); 34 | 35 | /** 36 | * Retrieve the value for the current document at the specified index. 37 | * An index ranges from {@code 0} to {@code count()-1}. 38 | */ 39 | public abstract long valueAt(int index); 40 | 41 | /** 42 | * Retrieves the count of values for the current document. 43 | * This may be zero if a document has no values. 44 | */ 45 | public abstract int count(); 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Top-level package. 20 | */ 21 | package org.apache.lucene; 22 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/BoostAttributeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import org.apache.lucene.util.AttributeImpl; 21 | import org.apache.lucene.util.AttributeReflector; 22 | 23 | /** Implementation class for {@link BoostAttribute}. 24 | * @lucene.internal 25 | */ 26 | public final class BoostAttributeImpl extends AttributeImpl implements BoostAttribute { 27 | private float boost = 1.0f; 28 | 29 | @Override 30 | public void setBoost(float boost) { 31 | this.boost = boost; 32 | } 33 | 34 | @Override 35 | public float getBoost() { 36 | return boost; 37 | } 38 | 39 | @Override 40 | public void clear() { 41 | boost = 1.0f; 42 | } 43 | 44 | @Override 45 | public void copyTo(AttributeImpl target) { 46 | ((BoostAttribute) target).setBoost(boost); 47 | } 48 | 49 | @Override 50 | public void reflectWith(AttributeReflector reflector) { 51 | reflector.reflect(BoostAttribute.class, "boost", boost); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/CollectionTerminatedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | /** Throw this exception in {@link LeafCollector#collect(int)} to prematurely 21 | * terminate collection of the current leaf. 22 | *

Note: IndexSearcher swallows this exception and never re-throws it. 23 | * As a consequence, you should not catch it when calling 24 | * {@link IndexSearcher#search} as it is unnecessary and might hide misuse 25 | * of this exception. */ 26 | @SuppressWarnings("serial") 27 | public final class CollectionTerminatedException extends RuntimeException { 28 | 29 | /** Sole constructor. */ 30 | public CollectionTerminatedException() { 31 | super(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/FakeScorer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import java.util.Collection; 21 | 22 | /** Used by {@link BulkScorer}s that need to pass a {@link 23 | * Scorer} to {@link LeafCollector#setScorer}. */ 24 | final class FakeScorer extends Scorer { 25 | float score; 26 | int doc = -1; 27 | int freq = 1; 28 | 29 | public FakeScorer() { 30 | super(null); 31 | } 32 | 33 | @Override 34 | public int docID() { 35 | return doc; 36 | } 37 | 38 | @Override 39 | public int freq() { 40 | return freq; 41 | } 42 | 43 | @Override 44 | public float score() { 45 | return score; 46 | } 47 | 48 | @Override 49 | public DocIdSetIterator iterator() { 50 | throw new UnsupportedOperationException(); 51 | } 52 | 53 | @Override 54 | public Weight getWeight() { 55 | throw new UnsupportedOperationException(); 56 | } 57 | 58 | @Override 59 | public Collection getChildren() { 60 | throw new UnsupportedOperationException(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/FieldComparatorSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * Provides a {@link FieldComparator} for custom field sorting. 24 | * 25 | * @lucene.experimental 26 | * 27 | */ 28 | public abstract class FieldComparatorSource { 29 | 30 | /** 31 | * Creates a comparator for the field in the given index. 32 | * 33 | * @param fieldname 34 | * Name of the field to create comparator for. 35 | * @return FieldComparator. 36 | * @throws IOException 37 | * If an error occurs reading the index. 38 | */ 39 | public abstract FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) 40 | throws IOException; 41 | } 42 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/FilterCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | import java.io.IOException; 20 | 21 | import org.apache.lucene.index.LeafReaderContext; 22 | 23 | 24 | /** 25 | * {@link Collector} delegator. 26 | * 27 | * @lucene.experimental 28 | */ 29 | public abstract class FilterCollector implements Collector { 30 | 31 | protected final Collector in; 32 | 33 | /** Sole constructor. */ 34 | public FilterCollector(Collector in) { 35 | this.in = in; 36 | } 37 | 38 | @Override 39 | public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { 40 | return in.getLeafCollector(context); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return getClass().getSimpleName() + "(" + in + ")"; 46 | } 47 | 48 | @Override 49 | public boolean needsScores() { 50 | return in.needsScores(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/FilterLeafCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * {@link LeafCollector} delegator. 24 | * 25 | * @lucene.experimental 26 | */ 27 | public abstract class FilterLeafCollector implements LeafCollector { 28 | 29 | protected final LeafCollector in; 30 | 31 | /** Sole constructor. */ 32 | public FilterLeafCollector(LeafCollector in) { 33 | this.in = in; 34 | } 35 | 36 | @Override 37 | public void setScorer(Scorer scorer) throws IOException { 38 | in.setScorer(scorer); 39 | } 40 | 41 | @Override 42 | public void collect(int doc) throws IOException { 43 | in.collect(doc); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | String name = getClass().getSimpleName(); 49 | if (name.length() == 0) { 50 | // an anonoymous subclass will have empty name? 51 | name = "FilterLeafCollector"; 52 | } 53 | return name + "(" + in + ")"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/MatchNoDocsQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.lucene.index.IndexReader; 23 | 24 | /** 25 | * A query that matches no documents. 26 | */ 27 | public class MatchNoDocsQuery extends Query { 28 | @Override 29 | public Query rewrite(IndexReader reader) throws IOException { 30 | // Rewrite to an empty BooleanQuery so no Scorer or Weight is required 31 | return new BooleanQuery.Builder().build(); 32 | } 33 | 34 | @Override 35 | public String toString(String field) { 36 | return ""; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | return sameClassAs(o); 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return classHash(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/PhraseQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import org.apache.lucene.util.PriorityQueue; 21 | 22 | final class PhraseQueue extends PriorityQueue { 23 | PhraseQueue(int size) { 24 | super(size); 25 | } 26 | 27 | @Override 28 | protected final boolean lessThan(PhrasePositions pp1, PhrasePositions pp2) { 29 | if (pp1.position == pp2.position) 30 | // same doc and pp.position, so decide by actual term positions. 31 | // rely on: pp.position == tp.position - offset. 32 | if (pp1.offset == pp2.offset) { 33 | return pp1.ord < pp2.ord; 34 | } else { 35 | return pp1.offset < pp2.offset; 36 | } 37 | else { 38 | return pp1.position < pp2.position; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/QueryCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | /** 21 | * A cache for queries. 22 | * 23 | * @see LRUQueryCache 24 | * @lucene.experimental 25 | */ 26 | public interface QueryCache { 27 | 28 | /** 29 | * Return a wrapper around the provided weight that will cache 30 | * matching docs per-segment accordingly to the given policy. 31 | * NOTE: The returned weight will only be equivalent if scores are not needed. 32 | * @see Collector#needsScores() 33 | */ 34 | Weight doCache(Weight weight, QueryCachingPolicy policy); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/ScoreDoc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | /** Holds one hit in {@link TopDocs}. */ 21 | 22 | public class ScoreDoc { 23 | 24 | /** The score of this document for the query. */ 25 | public float score; 26 | 27 | /** A hit document's number. 28 | * @see IndexSearcher#doc(int) */ 29 | public int doc; 30 | 31 | /** Only set by {@link TopDocs#merge} */ 32 | public int shardIndex; 33 | 34 | /** Constructs a ScoreDoc. */ 35 | public ScoreDoc(int doc, float score) { 36 | this(doc, score, -1); 37 | } 38 | 39 | /** Constructs a ScoreDoc. */ 40 | public ScoreDoc(int doc, float score, int shardIndex) { 41 | this.doc = doc; 42 | this.score = score; 43 | this.shardIndex = shardIndex; 44 | } 45 | 46 | // A convenience method for debugging. 47 | @Override 48 | public String toString() { 49 | return "doc=" + doc + " score=" + score + " shardIndex=" + shardIndex; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/SimpleFieldComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.lucene.index.LeafReaderContext; 23 | 24 | /** 25 | * Base {@link FieldComparator} implementation that is used for all contexts. 26 | * 27 | * @lucene.experimental 28 | */ 29 | public abstract class SimpleFieldComparator extends FieldComparator implements LeafFieldComparator { 30 | 31 | /** This method is called before collecting context. */ 32 | protected abstract void doSetNextReader(LeafReaderContext context) throws IOException; 33 | 34 | @Override 35 | public final LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { 36 | doSetNextReader(context); 37 | return this; 38 | } 39 | 40 | @Override 41 | public void setScorer(Scorer scorer) {} 42 | } 43 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/TopFieldDocs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | 21 | /** Represents hits returned by {@link 22 | * IndexSearcher#search(Query,int,Sort)}. 23 | */ 24 | public class TopFieldDocs extends TopDocs { 25 | 26 | /** The fields which were used to sort results by. */ 27 | public SortField[] fields; 28 | 29 | /** Creates one of these objects. 30 | * @param totalHits Total number of hits for the query. 31 | * @param scoreDocs The top hits for the query. 32 | * @param fields The sort criteria used to find the top hits. 33 | * @param maxScore The maximum score encountered. 34 | */ 35 | public TopFieldDocs (int totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore) { 36 | super (totalHits, scoreDocs, maxScore); 37 | this.fields = fields; 38 | } 39 | } -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/TotalHitCountCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search; 18 | 19 | 20 | /** 21 | * Just counts the total number of hits. 22 | */ 23 | 24 | public class TotalHitCountCollector extends SimpleCollector { 25 | private int totalHits; 26 | 27 | /** Returns how many hits matched the search. */ 28 | public int getTotalHits() { 29 | return totalHits; 30 | } 31 | 32 | @Override 33 | public void collect(int doc) { 34 | totalHits++; 35 | } 36 | 37 | @Override 38 | public boolean needsScores() { 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/doc-files/nrq-formula-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/src/java/org/apache/lucene/search/doc-files/nrq-formula-1.png -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/doc-files/nrq-formula-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/src/java/org/apache/lucene/search/doc-files/nrq-formula-2.png -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/AfterEffectL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | import org.apache.lucene.search.Explanation; 21 | 22 | /** 23 | * Model of the information gain based on Laplace's law of succession. 24 | * @lucene.experimental 25 | */ 26 | public class AfterEffectL extends AfterEffect { 27 | 28 | /** Sole constructor: parameter-free */ 29 | public AfterEffectL() {} 30 | 31 | @Override 32 | public final float score(BasicStats stats, float tfn) { 33 | return 1 / (tfn + 1); 34 | } 35 | 36 | @Override 37 | public final Explanation explain(BasicStats stats, float tfn) { 38 | return Explanation.match( 39 | score(stats, tfn), 40 | getClass().getSimpleName() + ", computed from: ", 41 | Explanation.match(tfn, "tfn")); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "L"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/BasicModelIF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | import static org.apache.lucene.search.similarities.SimilarityBase.log2; 21 | 22 | /** 23 | * An approximation of the I(ne) model. 24 | * @lucene.experimental 25 | */ 26 | public class BasicModelIF extends BasicModel { 27 | 28 | /** Sole constructor: parameter-free */ 29 | public BasicModelIF() {} 30 | 31 | @Override 32 | public final float score(BasicStats stats, float tfn) { 33 | long N = stats.getNumberOfDocuments(); 34 | long F = stats.getTotalTermFreq(); 35 | return tfn * (float)(log2(1 + (N + 1) / (F + 0.5))); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "I(F)"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/BasicModelIne.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | import static org.apache.lucene.search.similarities.SimilarityBase.log2; 21 | 22 | /** 23 | * Tf-idf model of randomness, based on a mixture of Poisson and inverse 24 | * document frequency. 25 | * @lucene.experimental 26 | */ 27 | public class BasicModelIne extends BasicModel { 28 | 29 | /** Sole constructor: parameter-free */ 30 | public BasicModelIne() {} 31 | 32 | @Override 33 | public final float score(BasicStats stats, float tfn) { 34 | long N = stats.getNumberOfDocuments(); 35 | long F = stats.getTotalTermFreq(); 36 | double ne = N * (1 - Math.pow((N - 1) / (double)N, F)); 37 | return tfn * (float)(log2((N + 1) / (ne + 0.5))); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "I(ne)"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/DistributionLL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | /** 21 | * Log-logistic distribution. 22 | *

Unlike for DFR, the natural logarithm is used, as 23 | * it is faster to compute and the original paper does not express any 24 | * preference to a specific base.

25 | * @lucene.experimental 26 | */ 27 | public class DistributionLL extends Distribution { 28 | 29 | /** Sole constructor: parameter-free */ 30 | public DistributionLL() {} 31 | 32 | @Override 33 | public final float score(BasicStats stats, float tfn, float lambda) { 34 | return (float)-Math.log(lambda / (tfn + lambda)); 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "LL"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/Independence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | /** 21 | * Computes the measure of divergence from independence for DFI 22 | * scoring functions. 23 | *

24 | * See http://trec.nist.gov/pubs/trec21/papers/irra.web.nb.pdf for more information 25 | * on different methods. 26 | * @lucene.experimental 27 | */ 28 | public abstract class Independence { 29 | 30 | /** 31 | * Sole constructor. (For invocation by subclass 32 | * constructors, typically implicit.) 33 | */ 34 | public Independence() {} 35 | 36 | /** 37 | * Computes distance from independence 38 | * @param freq actual term frequency 39 | * @param expected expected term frequency 40 | */ 41 | public abstract float score(float freq, float expected); 42 | 43 | // subclasses must provide a name 44 | @Override 45 | public abstract String toString(); 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/IndependenceChiSquared.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | /** 21 | * Normalized chi-squared measure of distance from independence 22 | *

23 | * Described as: 24 | * "can be used for tasks that require high precision, against both 25 | * short and long queries." 26 | * @lucene.experimental 27 | */ 28 | public class IndependenceChiSquared extends Independence { 29 | 30 | /** 31 | * Sole constructor. 32 | */ 33 | public IndependenceChiSquared() {} 34 | 35 | @Override 36 | public float score(float freq, float expected) { 37 | return (freq - expected) * (freq - expected) / expected; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "ChiSquared"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/IndependenceSaturated.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | /** 21 | * Saturated measure of distance from independence 22 | *

23 | * Described as: 24 | * "for tasks that require high recall against long queries" 25 | * @lucene.experimental 26 | */ 27 | public class IndependenceSaturated extends Independence { 28 | 29 | /** 30 | * Sole constructor. 31 | */ 32 | public IndependenceSaturated() {} 33 | 34 | @Override 35 | public float score(float freq, float expected) { 36 | return (freq - expected) / expected; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "Saturated"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/IndependenceStandardized.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | /** 21 | * Standardized measure of distance from independence 22 | *

23 | * Described as: 24 | * "good at tasks that require high recall and high precision, especially 25 | * against short queries composed of a few words as in the case of Internet 26 | * searches" 27 | * @lucene.experimental 28 | */ 29 | public class IndependenceStandardized extends Independence { 30 | 31 | /** 32 | * Sole constructor. 33 | */ 34 | public IndependenceStandardized() {} 35 | 36 | @Override 37 | public float score(float freq, float expected) { 38 | return (freq - expected) / (float) Math.sqrt(expected); 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Standardized"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/LambdaDF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | import org.apache.lucene.search.Explanation; 21 | 22 | /** 23 | * Computes lambda as {@code docFreq+1 / numberOfDocuments+1}. 24 | * @lucene.experimental 25 | */ 26 | public class LambdaDF extends Lambda { 27 | 28 | /** Sole constructor: parameter-free */ 29 | public LambdaDF() {} 30 | 31 | @Override 32 | public final float lambda(BasicStats stats) { 33 | return (stats.getDocFreq()+1F) / (stats.getNumberOfDocuments()+1F); 34 | } 35 | 36 | @Override 37 | public final Explanation explain(BasicStats stats) { 38 | return Explanation.match( 39 | lambda(stats), 40 | getClass().getSimpleName() + ", computed from: ", 41 | Explanation.match(stats.getDocFreq(), "docFreq"), 42 | Explanation.match(stats.getNumberOfDocuments(), "numberOfDocuments")); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "D"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/similarities/LambdaTTF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.similarities; 18 | 19 | 20 | import org.apache.lucene.search.Explanation; 21 | 22 | /** 23 | * Computes lambda as {@code totalTermFreq+1 / numberOfDocuments+1}. 24 | * @lucene.experimental 25 | */ 26 | public class LambdaTTF extends Lambda { 27 | 28 | /** Sole constructor: parameter-free */ 29 | public LambdaTTF() {} 30 | 31 | @Override 32 | public final float lambda(BasicStats stats) { 33 | return (stats.getTotalTermFreq()+1F) / (stats.getNumberOfDocuments()+1F); 34 | } 35 | 36 | @Override 37 | public final Explanation explain(BasicStats stats) { 38 | return Explanation.match( 39 | lambda(stats), 40 | getClass().getSimpleName() + ", computed from: ", 41 | Explanation.match(stats.getTotalTermFreq(), "totalTermFreq"), 42 | Explanation.match(stats.getNumberOfDocuments(), "numberOfDocuments")); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "L"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/spans/SpanCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.spans; 18 | 19 | 20 | import org.apache.lucene.index.PostingsEnum; 21 | import org.apache.lucene.index.Term; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * An interface defining the collection of postings information from the leaves 27 | * of a {@link org.apache.lucene.search.spans.Spans} 28 | * 29 | * @lucene.experimental 30 | */ 31 | public interface SpanCollector { 32 | 33 | /** 34 | * Collect information from postings 35 | * @param postings a {@link PostingsEnum} 36 | * @param position the position of the PostingsEnum 37 | * @param term the {@link Term} for this postings list 38 | * @throws IOException on error 39 | */ 40 | public void collectLeaf(PostingsEnum postings, int position, Term term) throws IOException; 41 | 42 | /** 43 | * Call to indicate that the driving Spans has moved to a new position 44 | */ 45 | public void reset(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/search/spans/SpanPositionQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.search.spans; 18 | 19 | 20 | import org.apache.lucene.util.PriorityQueue; 21 | 22 | class SpanPositionQueue extends PriorityQueue { 23 | SpanPositionQueue(int maxSize) { 24 | super(maxSize, false); // do not prepopulate 25 | } 26 | 27 | protected boolean lessThan(Spans s1, Spans s2) { 28 | int start1 = s1.startPosition(); 29 | int start2 = s2.startPosition(); 30 | return (start1 < start2) ? true 31 | : (start1 == start2) ? s1.endPosition() < s2.endPosition() 32 | : false; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/store/AlreadyClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.store; 18 | 19 | 20 | /** 21 | * This exception is thrown when there is an attempt to 22 | * access something that has already been closed. 23 | */ 24 | public class AlreadyClosedException extends IllegalStateException { 25 | public AlreadyClosedException(String message) { 26 | super(message); 27 | } 28 | 29 | public AlreadyClosedException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/store/LockObtainFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.store; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * This exception is thrown when the write.lock 23 | * could not be acquired. This 24 | * happens when a writer tries to open an index 25 | * that another writer already has open. 26 | * @see LockFactory#obtainLock(Directory, String) 27 | */ 28 | public class LockObtainFailedException extends IOException { 29 | public LockObtainFailedException(String message) { 30 | super(message); 31 | } 32 | 33 | public LockObtainFailedException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/store/LockReleaseFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.store; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * This exception is thrown when the write.lock 23 | * could not be released. 24 | * @see Lock#close() 25 | */ 26 | public class LockReleaseFailedException extends IOException { 27 | public LockReleaseFailedException(String message) { 28 | super(message); 29 | } 30 | 31 | public LockReleaseFailedException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/store/OutputStreamDataOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.store; 18 | 19 | 20 | import java.io.*; 21 | 22 | /** 23 | * A {@link DataOutput} wrapping a plain {@link OutputStream}. 24 | */ 25 | public class OutputStreamDataOutput extends DataOutput implements Closeable { 26 | private final OutputStream os; 27 | 28 | public OutputStreamDataOutput(OutputStream os) { 29 | this.os = os; 30 | } 31 | 32 | @Override 33 | public void writeByte(byte b) throws IOException { 34 | os.write(b); 35 | } 36 | 37 | @Override 38 | public void writeBytes(byte[] b, int offset, int length) throws IOException { 39 | os.write(b, offset, length); 40 | } 41 | 42 | @Override 43 | public void close() throws IOException { 44 | os.close(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/store/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Binary i/o API, used for all index data. 20 | */ 21 | package org.apache.lucene.store; 22 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/Accountable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | import java.util.Collection; 21 | import java.util.Collections; 22 | 23 | /** 24 | * An object whose RAM usage can be computed. 25 | * 26 | * @lucene.internal 27 | */ 28 | public interface Accountable { 29 | 30 | /** 31 | * Return the memory usage of this object in bytes. Negative values are illegal. 32 | */ 33 | long ramBytesUsed(); 34 | 35 | /** 36 | * Returns nested resources of this class. 37 | * The result should be a point-in-time snapshot (to avoid race conditions). 38 | * @see Accountables 39 | */ 40 | default Collection getChildResources() { 41 | return Collections.emptyList(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/ArrayInPlaceMergeSorter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | import java.util.Comparator; 21 | 22 | /** 23 | * An {@link InPlaceMergeSorter} for object arrays. 24 | * @lucene.internal 25 | */ 26 | final class ArrayInPlaceMergeSorter extends InPlaceMergeSorter { 27 | 28 | private final T[] arr; 29 | private final Comparator comparator; 30 | 31 | /** Create a new {@link ArrayInPlaceMergeSorter}. */ 32 | public ArrayInPlaceMergeSorter(T[] arr, Comparator comparator) { 33 | this.arr = arr; 34 | this.comparator = comparator; 35 | } 36 | 37 | @Override 38 | protected int compare(int i, int j) { 39 | return comparator.compare(arr[i], arr[j]); 40 | } 41 | 42 | @Override 43 | protected void swap(int i, int j) { 44 | ArrayUtil.swap(arr, i, j); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/Attribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | /** 21 | * Base interface for attributes. 22 | */ 23 | public interface Attribute { 24 | } 25 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/AttributeReflector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | /** 21 | * This interface is used to reflect contents of {@link AttributeSource} or {@link AttributeImpl}. 22 | */ 23 | @FunctionalInterface 24 | public interface AttributeReflector { 25 | 26 | /** 27 | * This method gets called for every property in an {@link AttributeImpl}/{@link AttributeSource} 28 | * passing the class name of the {@link Attribute}, a key and the actual value. 29 | * E.g., an invocation of {@link org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl#reflectWith} 30 | * would call this method once using {@code org.apache.lucene.analysis.tokenattributes.CharTermAttribute.class} 31 | * as attribute class, {@code "term"} as key and the actual value as a String. 32 | */ 33 | public void reflect(Class attClass, String key, Object value); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/InPlaceMergeSorter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | /** {@link Sorter} implementation based on the merge-sort algorithm that merges 21 | * in place (no extra memory will be allocated). Small arrays are sorted with 22 | * insertion sort. 23 | * @lucene.internal */ 24 | public abstract class InPlaceMergeSorter extends Sorter { 25 | 26 | /** Create a new {@link InPlaceMergeSorter} */ 27 | public InPlaceMergeSorter() {} 28 | 29 | @Override 30 | public final void sort(int from, int to) { 31 | checkRange(from, to); 32 | mergeSort(from, to); 33 | } 34 | 35 | void mergeSort(int from, int to) { 36 | if (to - from < INSERTION_SORT_THRESHOLD) { 37 | insertionSort(from, to); 38 | } else { 39 | final int mid = (from + to) >>> 1; 40 | mergeSort(from, mid); 41 | mergeSort(mid, to); 42 | mergeInPlace(from, mid, to); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/LongValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | import org.apache.lucene.index.NumericDocValues; 21 | import org.apache.lucene.util.packed.PackedInts; 22 | 23 | /** Abstraction over an array of longs. 24 | * This class extends NumericDocValues so that we don't need to add another 25 | * level of abstraction every time we want eg. to use the {@link PackedInts} 26 | * utility classes to represent a {@link NumericDocValues} instance. 27 | * @lucene.internal */ 28 | public abstract class LongValues extends NumericDocValues { 29 | 30 | /** An instance that returns the provided value. */ 31 | public static final LongValues IDENTITY = new LongValues() { 32 | 33 | @Override 34 | public long get(long index) { 35 | return index; 36 | } 37 | 38 | }; 39 | 40 | /** Get value at index. */ 41 | public abstract long get(long index); 42 | 43 | @Override 44 | public long get(int idx) { 45 | return get((long) idx); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/MutableBits.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | /** 21 | * Extension of Bits for live documents. 22 | */ 23 | public interface MutableBits extends Bits { 24 | /** 25 | * Sets the bit specified by index to false. 26 | * @param index index, should be non-negative and < {@link #length()}. 27 | * The result of passing negative or out of bounds values is undefined 28 | * by this interface, just don't do it! 29 | */ 30 | public void clear(int index); 31 | } 32 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/SortableBytesRefArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.util; 19 | 20 | import java.util.Comparator; 21 | 22 | interface SortableBytesRefArray { 23 | /** Append a new value */ 24 | int append(BytesRef bytes); 25 | /** Clear all previously stored values */ 26 | void clear(); 27 | /** Returns the number of values appended so far */ 28 | int size(); 29 | /** Sort all values by the provided comparator and return an iterator over the sorted values */ 30 | BytesRefIterator iterator(final Comparator comp); 31 | } 32 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/SuppressForbidden.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | import java.lang.annotation.ElementType; 24 | 25 | /** 26 | * Annotation to suppress forbidden-apis errors inside a whole class, a method, or a field. 27 | * @lucene.internal 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE }) 31 | public @interface SuppressForbidden { 32 | /** A reason for suppressing should always be given. */ 33 | String reason(); 34 | } 35 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/ThreadInterruptedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | /** 20 | * Thrown by lucene on detecting that Thread.interrupt() had 21 | * been called. Unlike Java's InterruptedException, this 22 | * exception is not checked.. 23 | */ 24 | 25 | public final class ThreadInterruptedException extends RuntimeException { 26 | public ThreadInterruptedException(InterruptedException ie) { 27 | super(ie); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/ToStringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util; 18 | 19 | 20 | /** 21 | * Helper methods to ease implementing {@link Object#toString()}. 22 | */ 23 | public final class ToStringUtils { 24 | 25 | private ToStringUtils() {} // no instance 26 | 27 | public static void byteArray(StringBuilder buffer, byte[] bytes) { 28 | for (int i = 0; i < bytes.length; i++) { 29 | buffer.append("b[").append(i).append("]=").append(bytes[i]); 30 | if (i < bytes.length - 1) { 31 | buffer.append(','); 32 | } 33 | 34 | } 35 | } 36 | 37 | private final static char [] HEX = "0123456789abcdef".toCharArray(); 38 | 39 | public static String longHex(long x) { 40 | char [] asHex = new char [16]; 41 | for (int i = 16; --i >= 0; x >>>= 4) { 42 | asHex[i] = HEX[(int) x & 0x0F]; 43 | } 44 | return "0x" + new String(asHex); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/bkd/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Block KD-tree, implementing the generic spatial data structure described in 20 | * this paper. 21 | */ 22 | 23 | package org.apache.lucene.util.bkd; 24 | -------------------------------------------------------------------------------- /lucene/src/java/org/apache/lucene/util/fst/ReverseBytesReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.lucene.util.fst; 18 | 19 | 20 | /** Reads in reverse from a single byte[]. */ 21 | final class ReverseBytesReader extends FST.BytesReader { 22 | private final byte[] bytes; 23 | private int pos; 24 | 25 | public ReverseBytesReader(byte[] bytes) { 26 | this.bytes = bytes; 27 | } 28 | 29 | @Override 30 | public byte readByte() { 31 | return bytes[pos--]; 32 | } 33 | 34 | @Override 35 | public void readBytes(byte[] b, int offset, int len) { 36 | for(int i=0;i, Set...。 15 | 16 | ### Varint(变长整数) 17 | 这里重点要讲下 varint,我们知道 int 不论大小都是用 4 个字节表示,1 和 2147483647 都会占用相同的存储空间,显然这很浪费,优化方式就是不同大小的数字用不用长度的字节存储。在 Lucene 中也是采用这种方式,或者说 Lucene 就是采用了 [Google Protocal Buffer](https://developers.google.com/protocol-buffers/docs/encoding#simple) 的处理方式。 18 | 19 | 经过变长处理后的数据,每个字节只有低 7 位存储原始数据,最高 1 位做为标识位,如果为 1 表示后续还有数据,如果为 0 则表示达到数据末尾。 20 | 21 | 对于负整数,最高位是 1 ,这有个问题就是很浪费存储空间,比如 -1 ,也需要 5 个字节。ZigZag 算法就是应对这种问题。它会把绝对值比较小的负数变成正整数。算法公式是 (i << 1) ^ (i >> 31)。 22 | 23 | 24 | -------------------------------------------------------------------------------- /lucene/uml.asta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/lucene/uml.asta -------------------------------------------------------------------------------- /lucene/utils.md: -------------------------------------------------------------------------------- 1 | # 工具类(org.apache.lucene.util) 2 | 3 | ## org.apache.lucene.util.ByteBlockPool 4 | 5 | 4545 -------------------------------------------------------------------------------- /mit6006_algorithms/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/mit6006_algorithms/index.md -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/lec01_note.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/mit6006_algorithms/lecture_1/lec01_note.pdf -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps/generate.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import random 4 | import pprint 5 | import utils 6 | 7 | def randomProblem(rows = 10, columns = 10, max = 1000): 8 | """ 9 | Generate a random matrix, with the specified number of rows and 10 | columns. Each number is distributed uniformly at random between 11 | zero and the specified maximum. 12 | """ 13 | 14 | result = [] 15 | 16 | for i in range(rows): 17 | resultRow = [] 18 | 19 | for j in range(columns): 20 | resultRow.append(random.randint(0, max)) 21 | 22 | result.append(resultRow) 23 | 24 | return result 25 | 26 | def main(): 27 | filename = None 28 | if len(sys.argv) > 1: 29 | filename = sys.argv[1] 30 | 31 | (rows, cols) = (10, 10) 32 | if len(sys.argv) > 3: 33 | (rows, cols) = (int(sys.argv[2]), int(sys.argv[3])) 34 | 35 | maximum = rows * cols * 2 36 | if len(sys.argv) > 4: 37 | maximum = int(sys.argv[4]) 38 | 39 | generated = randomProblem(rows, cols, maximum) 40 | 41 | print("Generated a matrix with %d row and %d columns." % (rows, cols)) 42 | if filename is None: 43 | filename = utils.getSaveFilename("problem.py") 44 | if filename is None: 45 | return 46 | 47 | with open(filename, "w") as outputFile: 48 | outputFile.write("problemMatrix = ") 49 | pprint.pprint(generated, outputFile) 50 | 51 | if __name__ == "__main__": 52 | main() 53 | -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps/problem.py: -------------------------------------------------------------------------------- 1 | problemMatrix = [ 2 | [ 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2], 3 | [ 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3], 4 | [ 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4], 5 | [ 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5], 6 | [ 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6], 7 | [ 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 5], 8 | [ 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4], 9 | [ 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3], 10 | [ 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2], 11 | [ 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1], 12 | [ 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0] 13 | ] 14 | -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps/ps1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/mit6006_algorithms/lecture_1/ps/ps1.pdf -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps/ps1_critique.tex: -------------------------------------------------------------------------------- 1 | % 2 | % 6.006 problem set 1 3 | % 4 | \documentclass[12pt,twoside]{article} 5 | 6 | \input{macros} 7 | 8 | \usepackage{amsmath} 9 | \usepackage{url} 10 | \usepackage{mdwlist} 11 | \usepackage{graphicx} 12 | \usepackage{enumitem} 13 | %\usepackage{clrscode3e} 14 | 15 | \setlength{\oddsidemargin}{0pt} 16 | \setlength{\evensidemargin}{0pt} 17 | \setlength{\textwidth}{6.5in} 18 | \setlength{\topmargin}{0in} 19 | \setlength{\textheight}{8.5in} 20 | 21 | % Fill these in! 22 | \newcommand{\theproblemsetnum}{1B} 23 | \newcommand{\releasedate}{September 15, 2011} 24 | \newcommand{\partaduedate}{Tuesday, September 20} 25 | \newcommand{\tabUnit}{3ex} 26 | \newcommand{\tabT}{\hspace*{\tabUnit}} 27 | 28 | \begin{document} 29 | 30 | \handout{Problem Set \theproblemsetnum}{\releasedate} 31 | 32 | \textbf{Your critique is due {\bf \partaduedate} at {\bf 11:59PM}.} 33 | 34 | \setlength{\parindent}{0pt} 35 | 36 | \medskip 37 | 38 | \hrulefill 39 | 40 | \begin{problems} 41 | 42 | \problem \textbf{Proof Critique} 43 | 44 | \paragraph{Previous Proof.} 45 | 46 | %%% PREVIOUS PROOF START %%% 47 | Insert a copy of your previous proof here. 48 | %%% PREVIOUS PROOF END %%% 49 | 50 | \paragraph{Critique.} 51 | 52 | %%% CRITIQUE START %%% 53 | Insert your critique of your own proof here. 54 | %%% CRITIQUE END %%% 55 | 56 | \end{problems} 57 | 58 | \end{document} 59 | -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def getOpenFilename(default = None): 4 | """ 5 | Prompts the user to pick a file name. If the user doesn't enter a filename, 6 | returns the default. 7 | """ 8 | 9 | prompt = "Enter a file name to load from" 10 | if default is not None: 11 | prompt += (" (default: %s)" % default) 12 | prompt += ": " 13 | 14 | filename = raw_input(prompt) 15 | if filename == "" and not (default is None): 16 | filename = default 17 | 18 | return filename 19 | 20 | def getSaveFilename(default = None): 21 | """ 22 | Prompts the user to pick a file name. If the user doesn't enter a filename, 23 | returns the default. If the file already exists, checks to make sure that 24 | the user wants to overwrite it. 25 | """ 26 | 27 | prompt = "Enter a file name to save to" 28 | if default is not None: 29 | prompt += (" (default: %s)" % default) 30 | prompt += ": " 31 | 32 | filename = raw_input(prompt) 33 | if filename == "" and not (default is None): 34 | filename = default 35 | 36 | if os.path.exists(filename): 37 | print("The file %s already exists." % filename) 38 | prompt = ("Overwrite (o), enter another name (f), or cancel (c)? ") 39 | 40 | check = raw_input(prompt) 41 | while (check != "o" and check != "f" and check != "c"): 42 | check = raw_input(prompt) 43 | 44 | if check == "o": 45 | return filename 46 | elif check == "f": 47 | return getSaveFilename(default) 48 | elif check == "c": 49 | return None 50 | 51 | return filename 52 | -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/mit6006_algorithms/lecture_1/ps1.pdf -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/mit6006_algorithms/lecture_1/ps1.zip -------------------------------------------------------------------------------- /mit6006_algorithms/lecture_1/ps1_sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/mit6006_algorithms/lecture_1/ps1_sol.pdf -------------------------------------------------------------------------------- /mysql/01.md: -------------------------------------------------------------------------------- 1 | # 基础架构:一条SQL查询流程 2 | 3 | ## 组件 4 | 1. 连接器 5 | 1. 分析器 6 | 1. 优化器 7 | 1. 执行器 8 | 1. 存储引擎 9 | 10 | ## 连接器 11 | 连接长期保持会占用临时内存,只有断开连接才会释放连接,但是短连接的tcp连接及权限加载也会成本比较高。 12 | 折中办法是定时断开重连,或者执行 `mysql_reset_connection` (没有找到这个指令啊,难道是内部接口?)。 13 | 14 | ## 查询缓存 15 | 建议最好使用缓存,因为表上有任何更新都会导致整个和这表关联的缓存都会失效。MySQL8.0 版本后删除了整个缓存功能。 16 | 17 | ## 分析器 18 | 词法分析和语法分析阶段。 19 | 20 | ## 优化器 21 | 对 SQL 语句做优化分析,比如索引选择,表关联时连接顺序。 22 | 23 | ## 执行器 24 | 执行器和存储引擎提供的数据接口交互。比如查询,写入等。执行器每调用一次存储引擎,`rows_examined` 会累加一次,这个值可以在慢日志中看到。 25 | 26 | -------------------------------------------------------------------------------- /mysql/02.md: -------------------------------------------------------------------------------- 1 | # 日志系统:一条SQL更新如何执行 2 | 3 | ## 整体流程 4 | SQL执行整体流程和上一节 SQL 查询差不多一致,经历:连接器、分析器、优化器、执行器。但更新流程有一个很大的不同是涉及到两个日志模块的维护:rredo log 和 binlog。 5 | 6 | ## Redo Log 7 | 为了提高磁盘io效率,不能每次更新数据时直接从磁盘定位数据再更新。引入 WAL 技术(write ahead logging),先写日志,再写磁盘。 8 | 9 | Redo Log 是固定大小,固定数量的文件组成,循环写入,所以要记录两个 pos 来辅助工作。write pos 用于记录前写入点,check pos 用于记录已 flush 到磁盘点。 10 | 11 | ### 配置 12 | ```bash 13 | innodb_log_files_in_group = 文件数量 14 | innodb_log_file_size = 每个文件大小 15 | ``` 16 | 17 | 所以总共可用大小就是:`innodb_log_files_in_group' * `innodb_log_file_size`。这个值应该不要太少,不然会频繁执行 checkpoint 操作而影响磁盘 io。 18 | 19 | ## Bin Log 20 | Bin Log 和 Redo Log 不同: 21 | 22 | 1. Redo Log 是 innodb 引擎层,而 Bin Log 是 Server 层实现。 23 | 2. Redo Log 是物理日志,Bin Log 是 逻辑日志。 24 | 3. Redo Log 是循环写入,Bin Log 是追加写入。 25 | 26 | ## 执行流程 27 | ```sql 28 | update t set c = c+1 where id = 1; 29 | ``` 30 | 31 | 1. 执行器调用存储层,查询 id = 1 的数据。 32 | 1. 存储层通过树结构索引找到这行数据并返回。 33 | 1. 执行器执行加 1 操作,并调用引擎更新此行数据。 34 | 1. 引擎更新这些数据,记录到 Redo Log 中,并标记当前状态为 prepare 状态。 35 | 1. 执行器生成 Bin Log 并写入磁盘中。 36 | 1. 执行器调用引擎 commit 接口。 37 | 1. 引擎修改 Redo Log 为 commit 状态,更新完成。 38 | 39 | ## 2PC(Two Commit Phase) 40 | 上面的执行流程引入的 2PC。2PC 是分布式事务的一类算法,因为这里涉及到了两个文件的写入,所以引入了分布式事务。 41 | 42 | ### 2PC 协议学习 43 | TODO ... 44 | -------------------------------------------------------------------------------- /mysql/03.md: -------------------------------------------------------------------------------- 1 | # 事务隔离:为什么你改了我还看不见 2 | 3 | 在 MySQL 中,事务是在引擎层实现的。 4 | 5 | 事务在的 ACID,做业务开发的同学最关心的是 I(Isolation):事务隔离性。其中 Read Committed 和 Repeatable Read 最容易混淆。 6 | Repeatable Read 总结一句话就是:从一而终。 7 | 8 | MVCC 是 innodb 引擎中处理事务的技术。通过对单行数据多版本控制来实现事务的隔离性。 9 | 10 | MVCC 相关资料: 11 | 12 | 1. [Implementing Your Own Transactions with MVCC](https://levelup.gitconnected.com/implementing-your-own-transactions-with-mvcc-bba11cab8e70) 13 | 2. [InnoDB MVCC 详解](https://cloud.tencent.com/developer/article/1488871) 14 | -------------------------------------------------------------------------------- /mysql/04.md: -------------------------------------------------------------------------------- 1 | # 深入浅出索引:上 2 | ## Hash 3 | 无序,只能做等值比较 4 | 5 | ## SortArray 6 | 更新数据成本高 7 | 8 | ## Tree 9 | 应用场景最多,InnoDB 引擎使用 B+ 树模型。 10 | 11 | # InnoDB 索引模型 12 | 每个表至少一颗主键索引的 B+ 树,叫做聚簇索引(clustered index)。 13 | 14 | 其它非主键索引的 B+ 树称为二级索引(secondary index),存储的值是主键值。 15 | 16 | B+ 树的维护是比较复杂的,我之前做[IR搜索引擎练习](https://github.com/hongfuli/irstudy/blob/master/src/main/java/cnblogs/jcli/irstudy/store/BTree.java)写过一个 B+ 树的存储引擎 Demo。 17 | 18 | ## 主键规范 19 | 一般公司建表都有明确规范:每个表必须有一个自增主键。了解了 B+ 树的结构就知道原因了,因为有序数据可以减少 B+ 树的页分裂。这里扩展几个业务开发中建表意见: 20 | 21 | 1. 每个表必须有递增主键,这里没有说自增,因为考虑到分布式(分库分表)场景。int 或者 long。 22 | 2. 非主键索引更多是业务角度出发的需求,比如电商场景下的订单号是需要创建唯一索引的。在写 sql 的时候,还是尽量按主键查询,只有面向业务逻辑的场景才使用非主键索引。 23 | -------------------------------------------------------------------------------- /mysql/05.md: -------------------------------------------------------------------------------- 1 | # 深入浅出索引:下 2 | ## 索引覆盖 3 | 查询 SQL 返回的所有字段直接通过二级索引返回,不需要通过主键回表查询。 4 | 5 | 这里扩展说下互联网中 Cache 与索引覆盖结合用法。 6 | 比如电商首页需要根据商品类型分类展示,并按时间倒序排列。则可以创建 category + created\_at 联合字段索引, 7 | 然后这样写 sql: 8 | ``` 9 | select id from product where category = xx order by created_at limit 20; 10 | ``` 11 | 只用返回主键字段避免回表,然后在 Redis 存储 id 到 商品对象的缓存对。 12 | 13 | ## 联合索引及索引前缀 14 | 由于索引采用B+ 树,所以支持前缀索引(无论是联合索引还是字符串前 n 个字符)。 15 | 16 | ## 索引下推 17 | 有些 sql 的查询条件只会用到部分索引字段,在早期版本会主键回表查询整行数据再判断是否满足条件, 18 | 而索引下推技术会使用当前二级索引的可用字段值初步过滤,以减少回表频率。 19 | -------------------------------------------------------------------------------- /mysql/06.md: -------------------------------------------------------------------------------- 1 | # 全局锁和表锁 :给表加个字段怎么有这么多阻碍? 2 | 3 | ## 全局锁 4 | Flush tables with read lock(FTWRL) 给整个库加上锁,使其它线程对库只有读的权限。 5 | 6 | 可以使用 FTWRL 进行逻辑备份,因为备份期间事个库是只读状态。这会导致一个严重的问题是,备份期间不写写数据,基本上业务就算停了。所以可以使用 InnoDB 的 MVCC 的 Repeatable Read 事务隔离级别来做数据库备份。 7 | mysqldump 使用 `--single-transaction` 开启一个事务来做备份的。 8 | 9 | ## 表级锁 10 | `lock tables ... read/write` 锁表,`unlock tables` 释放锁。 11 | 12 | 另一个表级锁是 MDL (metadata lock)。 13 | 为了保证一个事务中读取数据的结构一致性,DML/DQL 操作都会加 MDL 读锁,而 DDL 操作会加 MDL 写锁。 14 | 15 | 因为 MDL 的存在,可以会导致我们对一个小表做 DDL 操作也会导致其它线程阻塞。 16 | 17 | 18 | -------------------------------------------------------------------------------- /mysql/07.md: -------------------------------------------------------------------------------- 1 | # 行锁功过:怎么减少行锁对性能的影响? 2 | 3 | ## 2PL 4 | 因为事务中对多行上锁使用的 2PL (最事务结束前,无论 commit/rollback,都不会释放任何行锁),所以最好把**访问最频繁**的行数据最后上锁。 5 | 6 | 2PL 为了满足 Serializable ,有一个原则是:在 Locked Point 前不会释放任何行锁,这个会导致可能死锁(deadlock)。InnoDB 解决死锁有两个方案: 7 | 8 | 1. 等待超时。通过这个参数 `innodb_lock_wait_timeout` 来控制等待超时时间。缺点:太长了系统基本不可用;少短了会误伤正常需要等待业务,比如用户余额流水上锁。 9 | 1. 检测死锁。通过 `innodb_deadlock_detect` 来开关。默认是 on。死锁的条件就是检测是否线程的等待依赖关系构成了循环图,所以当并发达到一定量级后,这个计算复杂度是很高的。 10 | 11 | 上面说的两个办法都有缺点,怎么破? 12 | 文中给出的解决思路是减少并发,如果有数据库专家,可以在 MySQL 内部修改并行控制。如果在业务层做,可以分散热点数据,但是这会增加业务代码复杂度。 13 | -------------------------------------------------------------------------------- /mysql/08.md: -------------------------------------------------------------------------------- 1 | # 事务到底是隔离的还是不隔离的? 2 | 基本上是详细说明 MVCC 的原理。 3 | 4 | 这里有个重点术语:当前读。 5 | 更新数据都是先读后写,所以需要读取当前最新的版本值。如果当前其它事务也正在更新此数据,则当前线程阻塞等待直到获取行锁后读取当前最新值再更新。 6 | 7 | 当前读不只是 update/delete 这种更新语句,对于 select 使用锁也会导致当前读,比如: 8 | ```sql 9 | select k from t where id=1 lock in share mode; 10 | select k from t where id=1 for update; 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /mysql/09.md: -------------------------------------------------------------------------------- 1 | # 普通索引和唯一索引,应该怎么选择? 2 | 3 | 虽然本篇内容在讲索引选择,其实引出数据更新和读取过程中 change buffer 概念。 4 | 5 | ## 读取数据 6 | 这里有个『数据页』的概念,即 B+ 树的叶子结点数据块。当查询数据时,哪怕只需要一行数据,也是读取所在的整页数据加载到内存中。 7 | 所以普通索引和唯一索引对于查询数据基本没有什么性能影响,不非就在一个数据页中多对比一点数据,这对于 CPU 来说可忽略不计。 8 | 9 | ## 写入数据 10 | 前面说到数据页会缓存在内存中,当更新数据数据时,对于普通索引: 11 | 12 | 1. 如果数据页在内存中,则直接更新内存数据。 13 | 2. 如果数据页不在内存中,则写 change buffer。这样不用加载数据页到内存,有两个好处:减少磁盘随机读;减少系统 buffer pool。 14 | 15 | 而对于唯一索引更新数据不能使用 change buffer,因为需要判断数据的唯一性,所以相关数据页必须加载到内存中,数据页在内存中的话,就没有 change buffer 什么事了。 16 | 17 | 结论就是:如果使用唯一索引,读取数据基本没有区别,更新数据唯一索引因为需要加载数据页到内存,不能使用 change buff,所以性能会差一点。 18 | 19 | ## change buffer 使用场景 20 | change buffer 用来缓存数据更新在内存,如果更新完数据马上查询数据,则会触发加载数据页到内存并 merge,这样适得其反。 21 | 所以 change buffer 适合写多读少场景。 22 | 23 | ## change buffer 与 redo log 关系 24 | redo log 主要是节省随机写磁盘的 IO 消耗:如果没有 redo log,则每次修改数据需要在磁盘上定位到写入位置,这就是随机写。 25 | 26 | change buffer 主要是节省随机读磁盘:如果没有 change buffer,则每次修改前需要加载相关数据页到内存,这会导致磁盘随机读。 27 | 28 | 我在这里有些疑问: 29 | 30 | 1. change buffer 会记录在 redo log,那应该没必要自己做持久啊? 31 | 1. 为什么不直接在 redo log 里记录这个更新操作而省掉 change buffer 呢?我想的原因是,这会导致在 merge 阶段时,如果从 redog log 中加载操作日志了,会导致磁盘扫描。 32 | 33 | -------------------------------------------------------------------------------- /mysql/10.md: -------------------------------------------------------------------------------- 1 | # MySQL为什么有时候会选错索引? 2 | 3 | 如果经常处理线上 sql 查询慢的问题的,对于本节的知识点还是比较熟悉的。MySQL 选择错索引,说白了就是 MySQL 的 bug,因为还不够智能,不够聪明,而现实业务中复杂数据场景基本很难很一套算法去应对所有未知场景。这让我想起后面 AI、深度学习 这些知识应该会在数据库引擎自动学习优化中利用起来。 4 | 5 | 本章思考题不难猜出是数据统计受到删除数据(逻辑删除)影响。丁奇老师每章的思考题出得还是很用心的,基本都能根据讲到的知识点来推断出答案。比如本章中提到扫描数据预估是抽样统计数据页,如果统计不准,如果数据页的真实数据和逻辑数据对不上,而删除数据在事务未提交时,不会物理删除数据。 6 | -------------------------------------------------------------------------------- /mysql/11.md: -------------------------------------------------------------------------------- 1 | # 怎么给字符串字段加索引? 2 | 本节内容比较简单,因为索引是 B+ 树结构,所以支持前缀索引,这个前缀即指多字段联合索引,也可以指字符串字段前缀。 3 | 4 | 什么场景下我们使用字符串字段前缀索引?这其实就是一个存储成本和计算成本的折中平衡。索引长度越长,存储空间越大,但是查询时可能搜索次数更少。相反索引长度越短,前面两个效果是相反的。 5 | 6 | 如果使用前缀索引,截取长度是多少合适呢?这个没有统一数字,但是有计算规则。在基于长度越少,但是数据区分度又不太差的情况下,就是最优解。用公式表达就是: 7 | 8 | ``` 9 | 长度N的区分度 = select count(distince(left(field, N))) from t) 10 | ``` 11 | 12 | 找到一个区分度满足业务要求,但是 N 相对较小的值。 13 | 14 | ## 一些优化 15 | 前缀索引在有些业务数据下也不合适,比如前面段字段基本相同的。有一些技术应对这种问题。 16 | 17 | 倒序存储并加索引。这适合字段前段相似,后段区分度高场景。 18 | 19 | 对字段做 hash 计算。这需要额外加一个字段,并同步维护值。 20 | 21 | 上面两种方法的目的一致,用最少的存储空间存储区分度高的值。但是都有弊端,就是该字段在业务上只支持精确对比查询了。 22 | 23 | ## 一些关联 24 | 字段串索引如果只做精确查询是最简单场景,如果还支持通配符查询就复杂了,比如查询 `hello*world`,需要匹配 hello world, hello the world。这些在 MySQL 好像不支持索引,不过在 IR 领域还是有一些解决方案的。 25 | 26 | -------------------------------------------------------------------------------- /mysql/12.md: -------------------------------------------------------------------------------- 1 | # 为什么我的MySQL会“抖”一下? 2 | 3 | 当内存数据页和磁盘上不一致时,则称内存数据页是脏页。脏页最终还是需要刷新磁盘中同步的,那触发条件是什么呢? 4 | 5 | 这个问题可以换一个角度推断:如果脏页不刷回磁盘,会有什么后果? 6 | 7 | 1. 内存数据页是放在 buffer pool 中,脏页过多,即总体使用内存也会更多,这样会耗尽内存。 8 | 2. 脏页是怎么产生的?就是数据更新操作引起的,我们知道数据更新会写 redo log,那么要以推断出脏渐多,那么 redo log 也会占用渐多。 9 | 10 | 所以会根据这两个因素算出一个数值来控制刷脏页频率。 11 | 12 | 还有一个关键参数:`innodb_io_capacity`。这个参数表示当前磁盘的 IOPS。 13 | 14 | 总结下: 15 | 16 | 磁盘IO越好,那到参数 `innodb_io_capacity` 设置太低的话,则系统 IO 负载不高,但是 MySQL 性能上不去。 17 | -------------------------------------------------------------------------------- /mysql/13.md: -------------------------------------------------------------------------------- 1 | # 为什么表数据删掉一半,表文件大小不变? 2 | 3 | InnoDB 的数据都是 B+ 树结构存储的,而我们都知道 B+ 树在插入数据时为了平衡树会分裂而导致某些叶子结点数据空白。而删除数据时,InnoDB 不是实际删除数据而只是标记一下。 4 | 所以插入数据和删除数据都会导致有效数据比占用的存储空间大。 5 | 6 | ## 怎样回收空间? 7 | 8 | 使用命令: 9 | 10 | ``` 11 | alter table A engine=InnoDB; 12 | ``` 13 | 14 | 大概流程是: 15 | 创建一个临时表,然后逐行拷贝数据到临时表,因为是根据主键依次写入,所以数据是紧凑的。 16 | 如果在拷贝数据的同时有新的数据更新发生,这个更新记录做另外记在单独的日志上,等数据拷贝完了后,再回放这个更新日志,所以最终数据逻辑是完整的。 17 | 18 | 这里使用的 alter 是属于 DDL 类型语句,前面文章说到 DDL 会对操作的表加 MDL (metadata lock) 写锁,那么该表是不允许任何读写操作的,相当于业务停止了,这个是业务不能的接受的,实际上 InnoDB 也不会这样。那是怎么突破这个限制的呢? 19 | 就是在执行这个 alter 语句后并在开始拷贝数据时,MDL 的写锁退化成读锁,这样就只会阻止其它线程并发做 DDL 操作,但不影响数据的增删改查操作。 20 | 21 | 如果对于大表要做这个操作,因为需要大量的 IO 和 CPU 资源,所以推荐使用 github 开源的 gh-ost。 22 | 23 | -------------------------------------------------------------------------------- /mysql/14.md: -------------------------------------------------------------------------------- 1 | # count(\*)这么慢,我该怎么办? 2 | 3 | 结论: 4 | 5 | ``` 6 | count(*) == count(1) > count(主键 id ) > count(字段) 7 | 8 | ``` 9 | 10 | 分析: 11 | 12 | count 说到底就是个普通聚合计算函数,根据参数传入的值是为 NULL 来累加。这个参数是 server 层找引擎层要,引擎把满足条件的值逐行返回聚合计算。 13 | 14 | count(\*) 做了专门优化,虽然 `*` 字符看起来返回所有数据,但是优化器并不实际返回任何数据,只是按行统计。 15 | 16 | count(1) 和 count(\*) 差不多,都不实际取值,每扫描一行传常量 1 值。所以性能基本一样。 17 | 18 | count(字段) 需要加载每一行数据并取出指定字段值,判断是为 NULL 来决定是否累加。所以这个性能是最差的,因为整行数据都加载了。 19 | 20 | count(主键) 和 count(字段) 区别是前者不用加载整行数据,而只是取出 pk 值即可,这在很多二级索引树上做计算时不用回主索引检索数据。 21 | 22 | 23 | ## 怎么加速 24 | count() 函数是逐行统计,看起来很傻,为什么不冗余一个统计量呢?因为事务,因为 MVCC。 25 | 26 | 对于某些业务场景,每次搜索表求 count 太慢的话,有一些方案: 27 | 28 | 1. 自已缓存冗余(比如 Redis),和数据库操作同步更新。 29 | 1. 在数据库添加一个行数统计表。 30 | 31 | 这两个方案没有谁最佳,就是性能和准确的平衡。和数据库一起存储,可以保证同一个事务操作,所以一致性可能满足。自己用高速缓存,性能好,但是又引入分布式事务。 32 | 33 | -------------------------------------------------------------------------------- /mysql/16.md: -------------------------------------------------------------------------------- 1 | # “order by”是怎么工作的? 2 | 3 | 对于这样的一条 sql : 4 | 5 | ```sql 6 | select * from city, name, age from t where city = '杭州' order by name limit 100; 7 | ``` 8 | 如果 city 字段上有索引,则会根据 city 索引树扫描出所有满足条件的行到 buffer 内存 9 | 排序。如果内存分配不够时,则需要使用文件系统辅助排序。用于排序的内存大小可通过 10 | `sort_buffer_size` 这个参数设置。 11 | 12 | 需要排序的 sql 语句,用 explain 分析时,extra 字段会显示 "Using filesort"。 13 | 14 | 如果想避免排序处理,可以建立 (city, name) 的联合索引。因为索引有序,所以扫描数据本身 15 | 就是有序的。现在用 explain 分析,extra 信息会显示 "Using index condition",即使用到了索引。 16 | 17 | 如果想更进一步提升性能,则可以创建 (city, name, age) 联合索引来达到查询索引覆盖。这时 18 | 如果用 explain 分析,extra 会显示 "Using where; Using index"。 19 | 20 | Using index 表示索引覆盖,不用再回表查询数据做过滤(index push down)。 21 | Using index condition 一般还需要回表加载数据来做比较计算。 22 | 所以 Using index 性能更好。 23 | 24 | ## 全字段 VS rowid 排序 25 | 如果数据都加载到内存排序当然是最快的,但是内存有限情况下,可以只把 order by 关联的字段和 pk 26 | 字段加载到内存排序,再用已排序后的这个元组值从主键索引树加载数据。这个就是 rowid 排序。 27 | 28 | 所以全字段排序不需要回表,但是需要资源更多。 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /mysql/17.md: -------------------------------------------------------------------------------- 1 | # 如何正确地显示随机消息? 2 | 3 | ```sql 4 | select * from t order by rand() limit 3; 5 | ``` 6 | 7 | order by rand() 内部执行是比较暴力的。需要把所有相关行数据取出来分别计算分配一个随机值(0~1),与主键 id 组成一个临时表,这个临时表优先使用内存,如果内存不足(`tmp_table_size`),则使用磁盘临时表。 8 | 9 | ordery by rand() 和 limit n 较小的值配合使用时,会使用 `优先队列排序算法` 。即在内存里只分配 n 个对象空间,依次扫描比较淘汰替换满足条件的值,有点像贪心算法。说到这里,我之前面试入职支付宝就是这道算法题,记忆深刻啊。 10 | 11 | 其实在业务架构中,如果表的数据比较多,一般会避免这种写法,会改写 sql 写法,或者在业务层引入其它技术方案,比如 Redis 之类。 12 | -------------------------------------------------------------------------------- /mysql/18.md: -------------------------------------------------------------------------------- 1 | # 为什么这些SQL语句逻辑相同,性能却差异巨大? 2 | 3 | 本章说了三个简单 sql 语句但是没有走索引的查询场景,本质都是因为对字段进行了函数操作导致的。 4 | 5 | 除了我们显示调用函数外,谨防隐式函数被调用,比如字符串转数字操作。 6 | 比如订单号(order\_no)定义是 varchar 类型,虽然都是数字字符,但是我们在写这样的 sql: 7 | 8 | ```sql 9 | select * from order where order_no = 123; 10 | ``` 11 | 12 | 因为 mysql 中如果字符串和数字比较时,会字符串转数字,所以会调用 `CONVERT(order_no, INTEGER)`。 13 | 14 | 个人觉得不管数字转字符还是反过来,不用记住这规则然后想着怎么避免,在业务开发规范中就明确 sql 参数必须和 DDL 中的数据类型一致,把坑口堵死。 15 | 16 | 还提到一个多表 join 查询导致的问题之前没有碰到过,因为外键字段的 chararctor 编码集不一致导致隐式编码转换。这个知识点可以为后面碰到问题了提供一种思路。 17 | -------------------------------------------------------------------------------- /mysql/19.md: -------------------------------------------------------------------------------- 1 | # 为什么我只查一行的语句,也执行这么慢? 2 | 3 | MySQL 执行很慢,除了机器物理资源(CPU, IO)受限外,内部执行逻辑问题也会引起查询一行语句很慢。 4 | 5 | 1. 等 MDL 锁 6 | 1. 等 flush 表(flush tables [T] with read lock;) 7 | 1. 等行锁 8 | 1. 没有走索引全表扫描 9 | 10 | show processlist 有时间没有引起阻塞线程的详细锁信息, 11 | 可以打开 `performance_schema=on` 后查看 `sys.schema_table_lock_waits`。 12 | -------------------------------------------------------------------------------- /mysql/20.md: -------------------------------------------------------------------------------- 1 | # 幻读是什么,幻读有什么问题? 2 | 3 | 之前理解重复读事务的作用是在同一个事务中有一致的数据视图,但是像 for update ,update 这样的语句会执行当前读,也会读到已读交的事务数据,而这种不能叫『幻读』。幻读一般指读插入的新行。 4 | 5 | 为了解决幻读,在 RR 级别下引入 gap 锁概念。 6 | 7 | 幻读引起问题? 8 | 9 | 数据不一致。如果线上数据库配置的 RC 级别,则最好把 `binlog_format=row`。因为 row 格式存储的是影响的行完整数据,而 statement 格式是逻辑 sql,这样在恢复备份或者从库复制时导致数据不一致。 10 | -------------------------------------------------------------------------------- /mysql/21.md: -------------------------------------------------------------------------------- 1 | # 为什么我只改一行的语句,锁这么多? 2 | 3 | 一些实用规则: 4 | 5 | 1. RR 级别才有 gap 锁。下面条例针对 RR 级别的。 6 | 1. 加锁的基本单位是 next-key lock。前开后闭。 7 | 1. 查找过程扫描到的数据才会加锁。 8 | 1. 索引上的等值查询,给唯一索引加锁的时候,退化成行锁。 9 | 1. 索引上的等值查询,遍历到最后一个不满足条件的值时,next-key lock即化成 gap 锁。 10 | 1. Bug: 唯一索引的范围查询会访问到不满足条件的第一个值为止。 11 | -------------------------------------------------------------------------------- /mysql/22.md: -------------------------------------------------------------------------------- 1 | # MySQL有哪些“饮鸩止渴”提高性能的方法? 2 | 3 | 引起 MySQL 性能问题的一些原因: 4 | 5 | ## 没有使用连接池。因为 connection init 是有成本的。 6 | 使用连接池,复用连接。 7 | 8 | ## 索引没有设计好。 9 | 把缺失的索引补上。线上操作推荐工具:gh-ost。 10 | 11 | ## SQL 语句没有写好:没有走索引。 12 | 优化 sql 。 13 | 14 | ## MySQL 优化器没有选对索引。 15 | 强制在使用索引: force index。 16 | 17 | ## 一些提前工作为了快速应急处理问题 18 | 19 | 业务开发人员在上线前,在测试环境把 slow log 打开,并把 `long_query_time` 设置为 0,这样每条 sql 都会记录日志,然后分析日志,检查 `rows_examined` 是否是预期的。 20 | 21 | -------------------------------------------------------------------------------- /mysql/23.md: -------------------------------------------------------------------------------- 1 | # MySQL是怎么保证数据不丢的? 2 | 3 | 本文主要介绍性能提升和数据持久保证的平衡。 4 | 5 | ## binlog 写入 6 | binlog 有对应的 binlog cache 阶段,每个线程独立一块 cache。 7 | write 及 fsync 写入行为是 `sync_blog` 控制。这个值为 N ,表示事务提交 N 次后执行 fsync。因为 fsync 才是实际写盘操作,成本比较高。这里可以看到如果该值设置成非 1 时,是有丢失数据风险的。 8 | 9 | ## redo log 写入 10 | redo log 对应有 redo log buffer。和前面 binlog 一样,这里有一个参数控制刷盘策略:`innodb_flush_log_at_trx_commit`。 11 | 12 | ## 组提交 13 | LSN(log sequence number)用来记录 redo log 的写入点。redo log 刷盘时会批量提交,即提交当前最大 LSN 序号。 14 | -------------------------------------------------------------------------------- /mysql/24.md: -------------------------------------------------------------------------------- 1 | # MySQL是怎么保证主备一致的? 2 | 3 | 在采用 M-S 架构时,建议将 S 节点设置成 readonly。设置成 readonly 模式不会对 repl 进程有影响,因为是超级角色。 4 | 5 | S 节点会启动两个线程,一个 io 线程用于网络读取 M 的 binlog 数据并写到 relay log 中,别一个 sql 线程将 relay log 回放到数据库。 6 | 7 | # binlog\_format 8 | 9 | 1. statement 10 | 1. row 11 | 1. mixed 12 | 13 | statement 是逻辑 sql 语句,有时候会不安全,比如: 14 | ```sql 15 | delete from t where a = 1 and b = 2 limit 1; 16 | ``` 17 | 假如 a 和 b 都有索引的话,那么这条语句可能走两个不同的索引,删除的数据也会不一样。 18 | 而 row 没有这个问题,因为它会记录修改数据修改前面的详细内容。 19 | 20 | 而引入 mixed 格式,其实是平衡 statement 和 row 两种优点。 21 | 22 | 在双 M 结构中,即双为主备关系,都会复杂对方的 binlog 日志,这样怎么避免循环复制呢?binlog 每个记录会有 server\_id,这个值会固定在它原始产生的实例上,而不会在其它实例备份执行而变化, 23 | 这样当 sql 在执行 relay log 日志时,判断 server\_id 和本实例配置一样,则直接丢弃。 24 | 25 | -------------------------------------------------------------------------------- /mysql/25.md: -------------------------------------------------------------------------------- 1 | # MySQL是怎么保证高可用的? 2 | 3 | 今天讲解的高可用架构是基于双 M 架构的。 4 | 虽然是 M 节点,但是同一时刻是只能一个节点能写入数据的,如果多写是可能导致数据不一致,而 binlog\_format 为非 row 时问题会更严重。这个很好理解,因为这就像多线程并发操作不加锁一样。 5 | 6 | 在做主备切换时,其实要关注两个指标: 7 | 8 | 1. 数据是否会不一致?可靠性。 9 | 2. 业务影响时间多久?可用性。 10 | 11 | 可靠性:不要出现双写,所以可以 `show slave status` 等 `seconds_behind_master` 的值为 0 时才能做主备写入切换。 12 | 13 | 可用性:就是缩短切换时间。这个依赖:binlog 网络传输是否延迟;relay log 回放执行是否延迟。 14 | 而现在网络延迟一般问题不大,所以可能原因是: 15 | 16 | 1. 备库机器性能差。 17 | 1. 大事务,本身执行就需要花费很久时间。 18 | -------------------------------------------------------------------------------- /mysql/26.md: -------------------------------------------------------------------------------- 1 | # 备库为什么会延迟好几个小时? 2 | 3 | 因为 MySQL 有 MMVC,支持多版本和行锁,所以对并行度支持是很好的,但是如果备库的 sql\_thread 是单线程执行的话,那么执行总体速度是赶不上主库的。 4 | 5 | MySQL 针对这个问题引入了多线程复制。通过 `slave_parallel_workers` 控制线程数,如果是 32 核,一般分配 8 ~ 16 之间。 6 | 7 | 大概思路是,有一个 coordinator 专门负责解析 binlog 事务日志并分发给 work 线程。这个分发工作不能随便分发,需要一些限制: 8 | 9 | 1. 如果更新同一行数据,则需要分发到同一个 work 中。不然不同的并行 work 没法控制本来的执行顺序。 10 | 1. 同一个事务多条语句不能分开,不然可见性会不一致。 11 | 12 | 一些分发策略: 13 | 14 | ## 按表 15 | 相同表的操作分配到一个 work。 16 | 17 | ## 按行 18 | 相同的行操作分配到一个 work。这里需要根据所有唯一字段来做行标识计算,比如主键,唯一索引都要考虑。 19 | 20 | 而且,因为需要解析 binlog 的数据修改前后的值,所以 `binlog_format` 是 row 格式。 21 | 22 | ## 按库 23 | 好处是内部维护的 hash 数据少,因为只需要计算库的参数。坏处也明显,现在大家一般一个实例也只放一个库,所以基本还是单线程复制。 24 | 25 | 26 | -------------------------------------------------------------------------------- /mysql/28.md: -------------------------------------------------------------------------------- 1 | # 读写分离有哪些坑? 2 | 3 | 一个坑:从库读不到最新的数据。 4 | 一些方案: 5 | 6 | ## 强制走主库查询 7 | 这个其实是看业务场景,有时候需要数据更新后立马可见,有时候数据晚点也没有事。 8 | 9 | 10 | ## sleep 方案 11 | 不说了。 12 | 13 | ## 判断主备延迟 14 | 15 | ``` 16 | show slave status 17 | ``` 18 | 根据返回的 `seconds_behind_master` 看延迟时长(秒)。 19 | 20 | 或者根据 `master_log_file`,`Read_Master_Log_Pos` 的值和 `Relay_Master_Log_File`,`Exec_Master_Log_Pos` 的值是否相等。 21 | 22 | 或者根据 `Retrived_Gtid_Set` 和 `Executed_Gtid_Set` 两个集合是否相同。 23 | 24 | ## 如果主库 binlog 没同步完就 crash 了呢? 25 | 可以打开 semi-sync replication。但是只要有一个从库响应了 ack 即表示复制完成,所以一主多从场景下防止过期读还是有问题。 26 | 27 | # 等主库位 28 | 即先查询主库最新的 pos ,再去从库主动发起检查是否最新同步状态,如果不是就先阻塞等待。 29 | 这个待库位,可以用 binlog 的 pos ,也可以用 GTID 值。 30 | -------------------------------------------------------------------------------- /mysql/29.md: -------------------------------------------------------------------------------- 1 | # 如何判断一个数据库是不是出问题了? 2 | 3 | 本文主要讲数据异常监控方法。 4 | 5 | ## select 1 判断 6 | 因为 select 1 很轻量,所以有时候发现不了问题。就像大家做业务开发监控 api 是否正常,如果只是写个 echo 接口,其实很多问题发现不了的。 7 | 8 | 这里提到了 `innodb_thread_concurrency` 这个参数,限制的不是客户端 socket 连接并发,而是真正消耗 CPU 操作的线程。要注意的,这里也不限制**等待锁**的操作,即如果一条 sql 因为等待锁而阻塞了,也是会释放这个并发统计的。 9 | 10 | 11 | ## update 判断 12 | 在某个库里写个 `health_checker` 表,使用 update 语句检测。主备库都需要这个检测的话,为了防止冲突导致 replication 中止,可以用 `server_id` 来做主键,不同实例更新不同的行。 13 | 14 | ## 利用 MySQL 内部性能检测机制 15 | `performance_schema` 库里面有一些监控性能指标的表。 16 | 17 | 18 | -------------------------------------------------------------------------------- /mysql/31.md: -------------------------------------------------------------------------------- 1 | # 误删数据后除了跑路,还能怎么办? 2 | 3 | ## Flashback 4 | 5 | ## 定期全量备份及 binlog 备份。 6 | 7 | ## 延迟复制备库 8 | ``` 9 | CHANGE MASTER TO MASTER_DELAY = N; 10 | ``` 11 | 即犯错一个后悔的时间缓冲。 12 | 13 | ## 预防为主 14 | ### 账号分离 15 | 最小权限原则;比如程序需要的账号一般 DML 权限即可。 16 | 17 | ### 规范 18 | 不要直接删除数据表,比如可以重命名。就像我们线上如果要删除某个配置文件,可以重命名为 XXX.bak。 19 | -------------------------------------------------------------------------------- /mysql/32.md: -------------------------------------------------------------------------------- 1 | # 为什么还有kill不掉的语句? 2 | 3 | kill query thread\_id 是终止线程执行。 4 | 5 | kill [collection] thread\_id 是断开连接。 6 | -------------------------------------------------------------------------------- /mysql/33.md: -------------------------------------------------------------------------------- 1 | # 我查这么多数据,会不会把数据库内存打爆? 2 | 3 | 当我们执行一条查询 sql 返回大量数据的话,会不会把 mysql 的内存撑爆呢?答案是不会,因为它边扫描边发送数据的,如果传输数据跟不上,则扫描会放缓。 4 | 5 | 这里有两个因素会影响扫描速度:`net_buffer_length`,这个是 MySQL 在 server 层最大缓冲的数据,另一个是 `socket_send_buffer`,这个是 OS 参数。如果两者中有数据没有发送干净的话,会阻塞等待。 6 | 7 | 全表扫描虽然不会把内存撑爆,但是会对其它正常业务查询也有影响。 8 | 我们知道 MySQL 使用 buffer pool 做数据页内存加速,而内存是有限的,如果内存不够则会淘汰内存。使用 **LRU** 算法。但是普通的 LRU 算法有个问题,如果大量查询非热点数据,则会把内存的当前数据页都清空掉。 9 | 所以 MySQL 加强了 LRU 算法,使用了 yong, old 分代内存算法,对于一次读取的数据会直接停留在 old 区。 10 | -------------------------------------------------------------------------------- /mysql/34.md: -------------------------------------------------------------------------------- 1 | # 到底可不可以使用join? 2 | 3 | 如果被驱动表有索引,join 的性能还可以。但是驱动表最好是能过滤少量数据。这样好处是:驱动表数据量很少(最好走索引),被驱动表也可以走索引。 4 | 5 | 6 | ## Simple Nested-Loop Join 7 | 如果被驱动表没有索引,则会每次从驱动表一行数据关联时,都会在被驱动表做一次全表扫描。这个性能最差。 8 | 9 | ## Block Nested-Loop Join 10 | 为了解决这个问题,可以一次性的把驱动表的数据加载到内存,然后只需要扫描一遍被驱动表,用每行数据对比驱动表内存数据。这样好处是:被驱动表只用扫描一次了。但是如果内存不够呢(`join_buffer_size`)?则需要分块(jblock)来加载驱动表了。 11 | 如果驱动表数据容量是 N,buffer 大小是 K,则被驱动表需要扫描的次数就变成了 N/K * M。其中 M 是被驱动数据容量。所以从这个公式看出,如果要减少有磁盘扫描次数,可以增加 buffer 值。 12 | 13 | 反正终极原则还是小表驱动大表,大表能索引。 14 | -------------------------------------------------------------------------------- /mysql/35.md: -------------------------------------------------------------------------------- 1 | # join语句怎么优化? 2 | 3 | ## Multi-Range Read 优化 4 | 上一章讲到,如果小表驱动,大表被驱动且有索引,那是最好的情况。但是大表的索引字段也是逐行读取的,然后再通过被驱动表的主键 id 回表。如果范围查询的时候索引字段本身主键都是有顺序一致的,则可以一次读取多行放入 buffer 中,然后在主键回表时相当于顺序读了。 5 | 6 | -------------------------------------------------------------------------------- /mysql/36.md: -------------------------------------------------------------------------------- 1 | # 为什么临时表可以重名? 2 | 3 | 临时表的生命周期是 session。 4 | 所以不同的 session 中可以有相同的表名。 5 | 但是表数据文件命名为了防止冲突,会加线程信息因子到文件路径中。 6 | 7 | 文章中提到临时表可以用来分库分表的场景,我觉得这是数据库中间件开发同学值得考虑的一个点,特别是有些 sql 很复杂但是返回数据量又不大时,如果强行做 sql 解析太复杂了,可以直接找个思路直接在临时表做汇总。 8 | 9 | 临时表在复制时在 binlog 有一些特殊,其实就是为了应对临时的一些特殊设置: 10 | 11 | 1. session 会话周期。但是复制 sql\_thread 是共享的。所以表名冲突要解决。 12 | 1. 同样因为 session 周期,需要显式生成 `drop temporary table` 给备库执行。 13 | -------------------------------------------------------------------------------- /mysql/37.md: -------------------------------------------------------------------------------- 1 | # 什么时候会使用内部临时表? 2 | 3 | 1. 如果对 group by 语句的结果没有排序要求,要在语句后面加 order by null; 4 | 1. 尽量让 group by 过程用上表的索引,确认方法是 explain 结果里没有 Using temporary 和 Using filesort; 5 | 1. 如果 group by 需要统计的数据量不大,尽量只使用内存临时表;也可以通过适当调大 `tmp_table_size` 参数,来避免用到磁盘临时表; 6 | 1. 如果数据量实在太大,使用 `SQL_BIG_RESULT` 这个提示,来告诉优化器直接使用排序算法得到 group by 的结果。 7 | 8 | 9 | -------------------------------------------------------------------------------- /mysql/38.md: -------------------------------------------------------------------------------- 1 | # 都说InnoDB好,那还要不要使用Memory引擎? 2 | 3 | 内存引擎表的索引(包括主键)都是索引和数据分离,索引部分使用 hash 结构。所以优点是:单值查询更快;缺点:不支持范围查询,而且如果数据部分位置变化,则所有索引指针都要更新。 4 | 5 | 内存索引只有表级锁,所以对并发度支持也比较差。 6 | 7 | 内存表在数据库重启后会删除,这在正常单实例情况下没有问题。但是如果在有 HA 架构下,因为内存在数据库重启时会在 binlog 里写入一个 delete from 删除所有数据,如果在备库重启后把这个语句传到主库,那么正常连接主库的连接会莫名发现数据丢失了。 8 | -------------------------------------------------------------------------------- /mysql/39.md: -------------------------------------------------------------------------------- 1 | # 自增主键为什么不是连续的? 2 | 3 | 因为申请主键成功后,事务可能会失败回滚,但是 id 不会退回申请前的值。 4 | 5 | 当前自增值是保存在内存中的,MySQL 8.0 后会做持久化。 6 | -------------------------------------------------------------------------------- /mysql/40.md: -------------------------------------------------------------------------------- 1 | # insert语句的锁为什么这么多 2 | 3 | insert ... select 会导致被查询的表加上所有关联数据的间隙锁和记录锁。 4 | 5 | 6 | -------------------------------------------------------------------------------- /mysql/41.md: -------------------------------------------------------------------------------- 1 | # 怎么最快地复制一张表? 2 | 3 | mysqldump 4 | 5 | 导出 csv 6 | ```sql 7 | select * from db1.t where a>900 into outfile '/server_tmp/t.csv'; 8 | ``` 9 | 10 | 物理拷贝 11 | -------------------------------------------------------------------------------- /mysql/42.md: -------------------------------------------------------------------------------- 1 | # grant之后要跟着flush privileges吗? 2 | 3 | 一个唯一的用户账号其实是个二元组:user + host。 4 | 5 | 回收权限 : 6 | ```sql 7 | revoke all privileges on *.* from 'ua'@'%'; 8 | ``` 9 | 10 | 11 | -------------------------------------------------------------------------------- /mysql/43.md: -------------------------------------------------------------------------------- 1 | # 要不要使用分区表? 2 | 3 | MySQL 的分区表其实在 server 层是一个表,但是引擎内部是多个表文文件数据。 4 | 5 | 6 | 分区表相比在用户在业务层的分库分表,其实一般选用用户分库分表,这样 DBA 对数据库维护更方便。而且分区表访问表时会把打开所有表文件。 7 | -------------------------------------------------------------------------------- /mysql/45.md: -------------------------------------------------------------------------------- 1 | # 自增id用完怎么办? 2 | 3 | 如果一个表没有主键, 则内部会分配一个 row\_id,在数据存储层时只有 6 位,即最大值是 2^48 -1。但是在代码里是 8 位长整型。所以如果当 row\_id 其实只是用了 8 位中的低 6 位。那么会存在一个问题,可能会存在 **0** 这个值出现多次,而且如果 row\_id 重复出现时,会覆盖存在的行。这个行为是不可接收的。 4 | 5 | 所以最好还是每个表需要显示定义主键。 6 | 7 | 自增整型在用尽时,会一直取当前最大值,所以会报重复 key 的错。 8 | -------------------------------------------------------------------------------- /mysql/index.md: -------------------------------------------------------------------------------- 1 | MySQL实战45讲 - 丁奇 2 | =================== 3 | 4 | 1. [基础架构:一条SQL查询流程](01.md) 5 | 1. [日志系统:一条SQL更新如何执行](02.md) 6 | 1. [事务隔离:为什么你改了我还看不见](03.md) 7 | 1. [深入浅出索引:上](04.md) 8 | 1. [深入浅出索引:下](05.md) 9 | 1. [全局锁和表锁:给表加个字段怎么有这么多阻碍?](06.md) 10 | 1. [行锁功过:怎么减少行锁对性能的影响?](07.md) 11 | 1. [事务到底是隔离的还是不隔离的?](08.md) 12 | 1. [普通索引和唯一索引,应该怎么选择?](09.md) 13 | 1. [MySQL为什么有时候会选错索引?](10.md) 14 | 1. [怎么给字符串字段加索引?](11.md) 15 | 1. [为什么我的MySQL会“抖”一下?](12.md) 16 | 1. [为什么表数据删掉一半,表文件大小不变?](13.md) 17 | 1. [count(\*)这么慢,我该怎么办?](14.md) 18 | 1. 答疑 19 | 1. [“order by”是怎么工作的?](16.md) 20 | 1. [如何正确地显示随机消息?](17.md) 21 | 1. [为什么这些SQL语句逻辑相同,性能却差异巨大?](18.md) 22 | 1. [为什么我只查一行的语句,也执行这么慢?](19.md) 23 | 1. [幻读是什么,幻读有什么问题?](20.md) 24 | 1. [为什么我只改一行的语句,锁这么多?](21.md) 25 | 1. [MySQL有哪些“饮鸩止渴”提高性能的方法?](22.md) 26 | 1. [MySQL是怎么保证数据不丢的?](23.md) 27 | 1. [MySQL是怎么保证主备一致的?](24.md) 28 | 1. [MySQL是怎么保证高可用的?](25.md) 29 | 1. [备库为什么会延迟好几个小时?](26.md) 30 | 1. [主库出问题了,从库怎么办?](27.md) 31 | 1. [读写分离有哪些坑?](28.md) 32 | 1. [如何判断一个数据库是不是出问题了?](29.md) 33 | 1. 答疑 34 | 1. [误删数据后除了跑路,还能怎么办?](31.md) 35 | 1. [为什么还有kill不掉的语句?](32.md) 36 | 1. [我查这么多数据,会不会把数据库内存打爆?](33.md) 37 | 1. [到底可不可以使用join?](34.md) 38 | 1. [join语句怎么优化?](35.md) 39 | 1. [为什么临时表可以重名?](36.md) 40 | 1. [什么时候会使用内部临时表?](37.md) 41 | 1. [都说InnoDB好,那还要不要使用Memory引擎?](38.md) 42 | 1. [自增主键为什么不是连续的?](39.md) 43 | 1. [insert语句的锁为什么这么多](40.md) 44 | 1. [怎么最快地复制一张表?](41.md) 45 | 1. [grant之后要跟着flush privileges吗?](42.md) 46 | 1. [要不要使用分区表?](43.md) 47 | 1. 答疑 48 | 1. [自增id用完怎么办?](45.md) 49 | -------------------------------------------------------------------------------- /netty/buffer.md: -------------------------------------------------------------------------------- 1 | # ChannelBufferFactory体系 2 | 3 | netty中ChannelBufferFactory的用于提供统一工厂接口来构造 `ChannelBuffer`, 主要有两种实现,基于`系统底层直接分配内存`的实现类`HeapChannelBufferFactory`和基于`JVM的堆内存`的实现类`DirectChannelBufferFactory`. 4 | ![uml](images/bufferfactory.png) 5 | 6 | `HeapChannelBufferFactory`就不用说了,它直接通过JVM来分配,管理内存. `DirectChannelBufferFactory`直接操作本地系统分配,管理内存.但是它做了一个很大的优化,就是针对JVM对低层操作的内存是通过`ReferenceQueue`来实现回收的,但是我们知道这种实现肯定是效率比较低的.所以它会直接分配一整块较大连续空间的内存用于后续频繁的内存分配请求,这样就相当于把减少了JVM和底层系统的交互,从而提高效率和吞吐量.请下下面示图: 7 | ![directbuffer](images/directbuffer.png) 8 | 9 | #ChannelBuffer体系 10 | 11 | ## `ChannelBuffer`和`java.nio.Buffer`的区别 12 | 13 | 我们知道`java.nio.Buffer`中最关键的有三个`指针`字段,`position`,`limit`,`capacity`,分别用来表示当前指针位置,最大指针移动位置, 及buffer容量. 他们必需满足: 0 <= position <= limit <= capacity 14 | ![java.nio.Buffer](images/buffer.jpg) 15 | 16 | 当对buffer进行写操作时,position向前移动,但不能超过limit.进行写的操作后,如果要从buffer读取数据怎么办呢?也还是从position位置读取数据并向前移动,但是在执行这个读操作前,必需把position=1和limit=positon这两步操作,没办法,因为对buffer的读写操作都要用共享用到这三个字段,所以只能在每次操作前都要预置好这些值. 17 | netty中`ChannelBuffer`重新定义了Buffer的操作方式,其原因之一就是解决上述的那个不断变换`position`,`limit`值的问题 18 | 19 | -------------------------------------------------------------------------------- /netty/channel.md: -------------------------------------------------------------------------------- 1 | # Netty中和Channel相关的几个重要概念 2 | 3 | ## Channel 4 | Channel,我可以理解成所有涉及到IO操作的统一接口,不管IO操作是基于网络,本地磁盘,还是进程内.这样很好的抽象了IO操作对象. 5 | 6 | ## ChannelFactory 7 | 生成Channel的工厂 8 | 9 | ## ChannelPipeline 10 | 在计算机术语中,所以和Pipeline相关的技术对象都是表达了相同的意思,中文翻译过来是"管道",这也很形象,管道的作用就是从某从东西从管道的一端流向别一端. 如在unix命令中, 用 `|` 表示一种管道技术. `ChannelPipeline`,即是处理`Channel`的一种管道. 11 | 12 | ## ChannelHandler 13 | 我们对`Channel`所有的操作(在Netty中,所有的操作都是异步的)都是交给`ChannelHandler`去处理. 14 | 关于`Channel`,`ChannelHandler`,`ChannelPipeline`的关联关系一定要理解清楚. 15 | ![Channel架构](images/channel.jpg) 16 | 17 | 一个`Channel`只能而且唯一绑定一个`ChannelPipeline`. 一个`ChannelPipeline`可以绑定多个`ChannelHandler`. 18 | 19 | 20 | ## ChannelEvent 21 | `ChannelHandler`处理的对象就是`ChannelEvent`. 包括建立新的socket连接,收到流,发送流等. Netty是基于事件模型的组件,所有的处理工作都是基于事件的触发,状态流转.这点很重要. 22 | 23 | ## ChannelFuture 24 | 上面我们说过,Netty是基于异步的.所以任何的操作都只会返回`ChannelFuture`对象,就是操作会立即返回不会阻塞,但是该返回结果并不表示操作的运行结果.所以我们想对最终结果进行处理,必需通过两种方式,一是等待`ChannelFuture`执行完成,即阻塞式.二是对`ChannelFuture`添加事件监听器,当执行完成时触发操作,即非阻塞似的. Netty作者推荐后一种方式. 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /netty/images/buffer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/netty/images/buffer.jpg -------------------------------------------------------------------------------- /netty/images/bufferfactory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/netty/images/bufferfactory.png -------------------------------------------------------------------------------- /netty/images/channel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/netty/images/channel.jpg -------------------------------------------------------------------------------- /netty/images/directbuffer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/netty/images/directbuffer.png -------------------------------------------------------------------------------- /netty/list.md: -------------------------------------------------------------------------------- 1 | netty学习笔记 2 | =============== 3 | 4 | 1. [BufferFactory 及 ChannelBuffer](buffer.md) 5 | 2. [Channel](channel.md) -------------------------------------------------------------------------------- /nlp/index.md: -------------------------------------------------------------------------------- 1 | # Speech and Language Processing 2 | 3 | 1. [Introduction](salp/chaptor_01.md) 4 | 1. [Regular Expression](salp/chaptor_02.md) 5 | 1. [Word Transducers](salp/chaptor_03.md) 6 | 1. [Ngrams](salp/chaptor_04.md) 7 | 1. [Word Classes And Part-Of-Speech Tagging](salp/chaptor_05.md) 8 | 1. [Hidden Markov And Maximum Entropy Models](salp/chaptor_06.md) 9 | 1. [Phonetics](salp/chaptor_07.md) 10 | 1. [Speech Synthesis](salp/chaptor_08.md) 11 | 1. [Automatic Speech Recognition](salp/chaptor_09.md) 12 | 1. [Speech Recongnition: Advanced Topics](salp/chaptor_10.md) 13 | 1. [Computational Phonology](salp/chaptor_11.md) 14 | 1. [Formal Grammars Of English](salp/chaptor_12.md) 15 | 1. [Parsing With Context-Free Grammars](salp/chaptor_13.md) 16 | 1. [Statistical Parsing](salp/chaptor_14.md) 17 | 1. [Language And Complexity](salp/chaptor_15.md) 18 | 1. [Features And Unification](salp/chaptor_16.md) 19 | 1. [Representing Meaning](salp/chaptor_17.md) 20 | 1. [Computational Semantics](salp/chaptor_18.md) 21 | 1. [Lexical Semantics](salp/chaptor_19.md) 22 | 1. [Computational Lexical Semantics](salp/chaptor_20.md) 23 | 1. [Computational Discourse](salp/chaptor_21.md) 24 | 1. [Information Extraction](salp/chaptor_22.md) 25 | 1. [Question Answering And Summarization](salp/chaptor_23.md) 26 | 1. [Dialogue And Conversational Agents](salp/chaptor_24.md) 27 | 1. [Machine Translation](salp/chaptor_25.md) 28 | -------------------------------------------------------------------------------- /nlp/salp/chaptor_01.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | -------------------------------------------------------------------------------- /python/Fluent_Python.md: -------------------------------------------------------------------------------- 1 | Fluent Python 读书手记 2 | 3 | - Python数据模型:特殊方法用来给整个语言模型特殊使用,一致性体现。如:\_\_len\_\_, \_\_getitem\_\_ 4 | - AOP: zope.inteface 5 | - 列表推导(list comprehensive)和 表达式生成器(generator expression),分别用 [...] 和 (...)表未。后者是迭代生成,更节省内存。 6 | - 元组tuple两大功能特性:不可变、用作数据记录结构(位置信息)。元组里的元素最好也是不可变数据。 7 | - array 和 列表相比的区别和优势。array只能存单一数据类型,比如array[int],而列表是任何数据类型的容器。但是array在存储上更节约内存,因为实现就是分配连续的内存记录二进制数据表示。 8 | - dict的 setdefault,可以方便处理可能不存在键的值操作。 9 | - dict的键是可散列的,满足三个条件。支持hash()函数,通过\_\_hash\_\_实现;通过 \_\_eq\_\_ 检测相等性;若 a == b,则 hash(a) == hash(b) 10 | - 接收函数参数或者返回函数的函数可以称为高阶函数 11 | - 自定义类中重写 \_\_call\_\_( ) 方法,可以把类实例变为可直接调用的函数对象。 12 | - python中的inspect模块,提供了很多内省方法,像java的reflect包。six库。 13 | - operator 和 functools 模块中有很多定义好的高阶函数可以,方便编写函数式代码风格。 14 | - 抽象类可以继承abc.ABC,使用 @abstractmethod 修饰。 15 | - 因为在Python中函数也是对象,可以用来传参和返回,所以23经典设计模式在Python中可能不完全适用,或者以更简单的方式使用。 16 | - 装饰器函数是导入模块时(load module)时就执行,而不是运行时执行。这个特性可用于框架处理一些启动注册的工作。 17 | - 在嵌套函数中,如果要引用外部的不可变象并重新赋值,则需要使用 nolocal 关键字声明变量再操作。 18 | - functools.lru_cache 可以缓存某个计算代价很大的函数结果。 19 | - functools.singledispatch 可以写出类似Java中方法重载的代码 20 | - @classmethod 和 @staticmethod 的区别。前者第一个参数是Class本身,后者就是一普通函数。 21 | - @Property 设置getter/setter属性 22 | - Python中接口,是指“鸭子类型”协议,即一个类具有相似的行为,但跟继承没有什么关系。但是抽象类(接口)在现实世界中是存在的,所以可以通过 abc.ABC 来定义抽象基类。 23 | - 不要直接继承内置的类,比如 list, dict。因为继承内置类,子类重写的方法如果通过python协议调用,不会使用子类的方法。比如 A extends list, A重写了 \_\_len\_\_,但是调用 len(a) 还是使用list的内置方法。解决办法是使用 pypy中的类,比如collections.abc中的类。 24 | - for/while/try - else 更应该按 for/while/try - then 语义理解更好些。 25 | - GIL指CPython实现一次只允许使用一个线程执行Python字节码,因为CPython解释器本来不是安全的。但是对于IO密集型场景无害,因为标准库中所有阻塞IO都会释放GIL(global interpreter locl)。但是CPU密集型计算则会有影响。 26 | 27 | -------------------------------------------------------------------------------- /rs/index.md: -------------------------------------------------------------------------------- 1 | # 「极客时间-推荐系统36式」学习笔记 2 | 3 | 刑无刀老师出品的这个推荐系统课程算不错的入门资料,刚好那个时间正在公司做这块的开发,从文本,图片,到视频信息的相关推荐。我的学习习惯是边看边做笔记,所以还是把整个学习过程中遇到的关键思想,代码算法等记录下。 4 | 5 | 1. [文本信息挖掘](tj36/chapter01.md) 6 | 1. [基于内容推荐](tj36/chapter02.md) 7 | 1. [近邻推荐](tj36/chapter03.md) 8 | 9 | -------------------------------------------------------------------------------- /rs/tj36/chapter02.md: -------------------------------------------------------------------------------- 1 | # 基于内容的推荐 2 | 3 | ## 内容推荐本质是一个信息检索系统 4 | 5 | 这一点我深有体会,第一次接触推荐系统并用于线上环境时,其实从来没有接受过推荐系统的理论体系知识,但是对 `Lucene` 和 `ES` 是比较熟悉的,所以完全按照自己的理解并使用信息检索系统做为技术栈完成的。流程就是:文本结构化处理和抽取标签,做物品画像;大数据统计用户行为建立用户画像;计算用户和物品的相似度,找出最相关的物品并且用户未消费的。 6 | 7 | 8 | ## 一些算法 9 | 10 | 1. 相似度计算一般使用余弦向量相邻度计算公司,或者 BM25F,这些代码可以直接参考 Lucene。 11 | 12 | -------------------------------------------------------------------------------- /rs/tj36/chapter03.md: -------------------------------------------------------------------------------- 1 | # 近邻推荐 2 | 3 | ## 基于用户的协同过滤 4 | 5 | 1. 用户之间相似度计算(找出兴趣相似的同户) 6 | 1. 计算用户和物品的关联权重(预测用户可能感兴趣的物品) 7 | 8 | ### 方案落地: 9 | 10 | 1. 用户向量矩阵构造:用户对物品的关系是稀疏的,在 Spark ML 和 NumPy 中都有相关的数据构造。 11 | 1. 用户向量相似度计算,如果数据量太大,可以用 MapReduce 分布式并行计算。 12 | 1. 用户和物品推荐计算,可以先缩小范围,比如只计算 Top N 相似用户的物品; 13 | 14 | ## 基于物品的协同过滤 15 | 16 | 1. 物品之间的相似度计算(找出受众目标用户相似的物品) 17 | 1. 根据某个物品可以得到 Top N 相似的物品(看了这个商品的用户又看了哪些商品) 18 | 19 | ### Slope One 算法改良 20 | 改良物品相似度计算的准确性 21 | 22 | ## 一些相似度计算公式 23 | 24 | 25 | 1. 欧氏距离 26 | 1. 余弦相似度 27 | 1. 皮尔逊相关度 28 | 1. 杰卡德相似度 29 | 30 | ## 更多阅读 31 | 32 | 我觉得项目基于近邻推荐算法落地中,项亮老师的推荐系统实战包含更多细节。 33 | -------------------------------------------------------------------------------- /shardingsphere/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/shardingsphere/index.md -------------------------------------------------------------------------------- /shardingsphere/uml.asta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/shardingsphere/uml.asta -------------------------------------------------------------------------------- /spring/images/beanFactory_life.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/spring/images/beanFactory_life.png -------------------------------------------------------------------------------- /spring/images/bean_life.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/spring/images/bean_life.png -------------------------------------------------------------------------------- /spring/images/class.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mty2015/study_notes/2299a997b24e9d4f81a2e7b3ea39b7b30d23b77c/spring/images/class.png -------------------------------------------------------------------------------- /spring/index.md: -------------------------------------------------------------------------------- 1 | # Spring学习笔记 2 | 3 | 4 | 1. [IOC核心](ioc.md) 5 | 6 | -------------------------------------------------------------------------------- /spring/ioc.md: -------------------------------------------------------------------------------- 1 | # `ApplicationContext`初始化流程 2 | ![ApplicationContext初始化流程](images/beanFactory_life.png) 3 | 4 | # Bean创建流程 5 | ![Bean初始化流程](images/bean_life.png) 6 | 7 | #IOC核心类结构 8 | ![IOC核心类结构](images/class.png) -------------------------------------------------------------------------------- /spring/samples/src/java/spring/HelloController.java: -------------------------------------------------------------------------------- 1 | package spring; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | import spring.util.ApiVersion; 10 | 11 | @Controller 12 | @RequestMapping("/{version}/") 13 | public class HelloController { 14 | 15 | @RequestMapping("hello/") 16 | @ApiVersion(1) 17 | @ResponseBody 18 | public String hello(HttpServletRequest request){ 19 | System.out.println("haha1.........."); 20 | 21 | return "hello"; 22 | } 23 | 24 | @RequestMapping("hello/") 25 | @ApiVersion(2) 26 | @ResponseBody 27 | public String hello2(HttpServletRequest request){ 28 | System.out.println("haha2........."); 29 | 30 | return "hello"; 31 | } 32 | 33 | @RequestMapping("hello/") 34 | @ApiVersion(5) 35 | @ResponseBody 36 | public String hello5(HttpServletRequest request){ 37 | System.out.println("haha5........."); 38 | 39 | return "hello"; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring/samples/src/java/spring/util/ApiVersion.java: -------------------------------------------------------------------------------- 1 | package spring.util; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.web.bind.annotation.Mapping; 10 | 11 | /** 12 | * 13 | * 接口版本标识注解 14 | * 15 | */ 16 | @Target({ElementType.METHOD, ElementType.TYPE}) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Documented 19 | @Mapping 20 | public @interface ApiVersion { 21 | int value(); 22 | } 23 | -------------------------------------------------------------------------------- /spring/samples/src/java/spring/util/ApiVesrsionCondition.java: -------------------------------------------------------------------------------- 1 | package spring.util; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | import org.springframework.web.servlet.mvc.condition.RequestCondition; 9 | 10 | public class ApiVesrsionCondition implements RequestCondition { 11 | 12 | // 路径中版本的前缀, 这里用 /v[1-9]/的形式 13 | private final static Pattern VERSION_PREFIX_PATTERN = Pattern.compile("v(\\d+)/"); 14 | 15 | private int apiVersion; 16 | 17 | public ApiVesrsionCondition(int apiVersion){ 18 | this.apiVersion = apiVersion; 19 | } 20 | 21 | public ApiVesrsionCondition combine(ApiVesrsionCondition other) { 22 | // 采用最后定义优先原则,则方法上的定义覆盖类上面的定义 23 | return new ApiVesrsionCondition(other.getApiVersion()); 24 | } 25 | 26 | public ApiVesrsionCondition getMatchingCondition(HttpServletRequest request) { 27 | Matcher m = VERSION_PREFIX_PATTERN.matcher(request.getPathInfo()); 28 | if(m.find()){ 29 | Integer version = Integer.valueOf(m.group(1)); 30 | if(version >= this.apiVersion) // 如果请求的版本号大于配置版本号, 则满足 31 | return this; 32 | } 33 | return null; 34 | } 35 | 36 | public int compareTo(ApiVesrsionCondition other, HttpServletRequest request) { 37 | // 优先匹配最新的版本号 38 | return other.getApiVersion() - this.apiVersion; 39 | } 40 | 41 | public int getApiVersion() { 42 | return apiVersion; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring/samples/src/java/spring/util/AuthInteceptor.java: -------------------------------------------------------------------------------- 1 | package spring.util; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 7 | 8 | public class AuthInteceptor extends HandlerInterceptorAdapter 9 | { 10 | 11 | @Override 12 | public boolean preHandle(HttpServletRequest request, 13 | HttpServletResponse response, Object handler) throws Exception 14 | { 15 | System.out.println("URI: " + request.getRequestURI()); 16 | return true; 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring/samples/src/java/spring/util/CustomRequestMappingHandlerMapping.java: -------------------------------------------------------------------------------- 1 | package spring.util; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import org.springframework.core.annotation.AnnotationUtils; 6 | import org.springframework.web.servlet.mvc.condition.RequestCondition; 7 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 8 | 9 | public class CustomRequestMappingHandlerMapping extends RequestMappingHandlerMapping { 10 | 11 | @Override 12 | protected RequestCondition getCustomTypeCondition(Class handlerType) { 13 | ApiVersion apiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class); 14 | return createCondition(apiVersion); 15 | } 16 | 17 | @Override 18 | protected RequestCondition getCustomMethodCondition(Method method) { 19 | ApiVersion apiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class); 20 | return createCondition(apiVersion); 21 | } 22 | 23 | private RequestCondition createCondition(ApiVersion apiVersion) { 24 | return apiVersion == null ? null : new ApiVesrsionCondition(apiVersion.value()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring/samples/src/java/spring/util/WebConfig.java: -------------------------------------------------------------------------------- 1 | package spring.util; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 6 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 7 | 8 | @Configuration 9 | public class WebConfig extends WebMvcConfigurationSupport{ 10 | 11 | @Override 12 | @Bean 13 | public RequestMappingHandlerMapping requestMappingHandlerMapping() { 14 | RequestMappingHandlerMapping handlerMapping = new CustomRequestMappingHandlerMapping(); 15 | handlerMapping.setOrder(0); 16 | handlerMapping.setInterceptors(getInterceptors()); 17 | return handlerMapping; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring/samples/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /spring/samples/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=WARN, stdout 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n 6 | 7 | 8 | log4j.logger.java.sql=DEBUG 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spring/samples/src/main/webapp/WEB-INF/mvc-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | /* 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /spring/samples/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | 9 | contextConfigLocation 10 | 11 | classpath:applicationContext.xml 12 | 13 | 14 | 15 | org.springframework.web.context.ContextLoaderListener 16 | 17 | 18 | 19 | mvc 20 | org.springframework.web.servlet.DispatcherServlet 21 | 22 | 23 | mvc 24 | /* 25 | 26 | 27 | -------------------------------------------------------------------------------- /spring/samples/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | --------------------------------------------------------------------------------