/// <summary> /// Lucene.Net 3.0.3 /// Lucene.Net.Analysis.PanGu 2.4.1 /// </summary> /// <param name="args"></param> static void Main(string[] args) { try { Console.WriteLine("欢迎来到.net高级班vip课程,今天是Eleven老师为大家带来的lucene.net"); //LuceneTest.InitIndex(); //LuceneTest.Show(); IndexBuilder.BuildIndex(); int total = 0; string pricefilter = "[50,2000]"; string priceorderby = "price desc"; List <Commodity> commoditylist = CommodityLucene.QueryCommodity(1, 30, out total, "书", null, pricefilter, priceorderby); foreach (Commodity commodity in commoditylist) { Console.WriteLine("title={0},price={1}", commodity.Title, commodity.Price); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
protected override void OnLoad(EventArgs e) { camImage.BackgroundImageLayout = ImageLayout.Stretch; var indexBuilder = new IndexBuilder(); indexBuilder.BuildIndex(); Task.Run(() => RunCamera()); }
/// <summary> /// 建索引 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { try { Console.WriteLine("{0} id={1} 开始索引的创建", DateTime.Now, Thread.CurrentThread.ManagedThreadId); this.btnStart.Enabled = false; CTS = new CancellationTokenSource(); new Action(() => IndexBuilder.BuildIndex(CTS)).BeginInvoke(null, null); this.btnStop.Enabled = true; } catch (Exception ex) { Console.WriteLine("{0} id={1} 索引创建出现异常:{2}", ex.Message); this.btnStart.Enabled = true; this.btnStop.Enabled = false; } }
public static void Build() { TagFileName scenario_tag = ProjectManager.ScenarioTagFileName; //new TagFileName(@"levels\test\beavercreek\beavercreek.scenario",MapfileVersion.XHALO1); IndexBuilder IndexBuild = new IndexBuilder(); string BasFolder = Application.StartupPath + @"\Extracted Tags\"; string StructFolder = Application.StartupPath + @"\Tag Structures\PcHalo\"; if (true) { //Create the index table Application.DoEvents(); string[] IndexList = IndexBuild.BuildIndex(scenario_tag.RelativePath, BasFolder, StructFolder, MapfileVersion.XHALO1); XBoxHaloMap.sXBoxHalo NewMap = new XBoxHaloMap.sXBoxHalo(); NewMap.XBoxIndexHeader.Create((uint)IndexList.Length); NewMap.XBoxIndexHeader.IndexMagic = 0x803a6024; //0x40440028; uint StringTableSize = 0; //Fixing index items ushort gt = 0xE174; Application.DoEvents(); for (int sc = 0; sc < IndexList.Length; sc++) { TagFileName tfnTAG = new TagFileName(IndexList[sc], MapfileVersion.XHALO1); TagBase tbTAG = new TagBase(); tbTAG.LoadTagBuffer(tfnTAG); NewMap.XBoxIndexHeader.IndexItems[sc].Create(); NewMap.XBoxIndexHeader.IndexItems[sc].TagClass1 = CompUtil.SwapUInt(tbTAG.Header.TagClass0); NewMap.XBoxIndexHeader.IndexItems[sc].TagClass2 = CompUtil.SwapUInt(tbTAG.Header.TagClass1); NewMap.XBoxIndexHeader.IndexItems[sc].TagClass3 = CompUtil.SwapUInt(tbTAG.Header.TagClass2); NewMap.XBoxIndexHeader.IndexItems[sc].IndexID1 = (ushort)sc; NewMap.XBoxIndexHeader.IndexItems[sc].IndexID2 = gt; NewMap.XBoxIndexHeader.IndexItems[sc].NameString = IndexList[sc]; if (tbTAG.Header.TagClass0 == 0x70736273 || tbTAG.Header.TagClass0 == 0x73627370) { NewMap.XBoxIndexHeader.IndexItems[sc].MetaSize = IndexBuild.BSPSizes[0]; } else { NewMap.XBoxIndexHeader.IndexItems[sc].MetaSize = 0; } if (tbTAG.Header.TagClass0 == 0x7274656d || tbTAG.Header.TagClass0 == 0x6d657472) // 6d657472) { gt += 2; } else { gt += 1; } string[] RemoveExt = IndexList[sc].Split(new char[] { '.' }, 256); NewMap.XBoxIndexHeader.IndexItems[sc].String = new byte[RemoveExt[0].Length + 1]; HaloPCMAP.StringToByteArray(ref NewMap.XBoxIndexHeader.IndexItems[sc].String, RemoveExt[0]); StringTableSize += (uint)(IndexList[sc].Length + 1); tbTAG = null; } //Creating the temp files for map building FileInfo MetaFile_info = new FileInfo(Application.StartupPath + "TempMeta.map"); FileStream MetaFile; MetaFile = MetaFile_info.Open(FileMode.Create, FileAccess.ReadWrite); FileInfo BSPFile_info = new FileInfo(Application.StartupPath + "TempBSP.map"); FileStream BSPFile; BSPFile = BSPFile_info.Open(FileMode.Create, FileAccess.ReadWrite); Application.DoEvents(); //writing the index table the temp files for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++) { NewMap.XBoxIndexHeader.IndexItems[sc].Write(ref MetaFile); } //Rewriting index items to temp file to fix string offsets. Application.DoEvents(); for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++) { NewMap.XBoxIndexHeader.IndexItems[sc].StringOffset = (uint)MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic; MetaFile.Write(NewMap.XBoxIndexHeader.IndexItems[sc].String, 0, NewMap.XBoxIndexHeader.IndexItems[sc].String.Length); } CompUtil.FixIntPosition(ref MetaFile); //save MetaFile position to return for meta writing. long TmpPosSave = MetaFile.Position; Application.DoEvents(); for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++) { MetaFile.Seek(NewMap.XBoxIndexHeader.IndexItems[sc].Position, SeekOrigin.Begin); NewMap.XBoxIndexHeader.IndexItems[sc].Write(ref MetaFile); } //restore position for meta writing #region ModelData MetaFile.Seek(TmpPosSave, SeekOrigin.Begin); NewMap.XBoxIndexHeader.VertsOffset = (uint)MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic; NewMap.XBoxIndexHeader.ModelCount1 = (uint)IndexBuild.XBoxMapData.XVerts.ModelCount; NewMap.IndirectVerts = (uint)MetaFile.Position; IndexBuild.XBoxMapData.XVerts.FixOffsets((uint)MetaFile.Position, NewMap.XBoxIndexHeader.IndexMagic); MetaFile.Write(IndexBuild.XBoxMapData.XVerts.IndirectOffsets, 0, IndexBuild.XBoxMapData.XVerts.IndirectOffsets.Length); MetaFile.Write(IndexBuild.XBoxMapData.XVerts.Verts, 0, IndexBuild.XBoxMapData.XVerts.Verts.Length); NewMap.XBoxIndexHeader.ModelCount2 = (uint)IndexBuild.XBoxMapData.XIndices.ModelCount; NewMap.XBoxIndexHeader.IndicesOffset = (uint)MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic; NewMap.IndirectIndices = (uint)MetaFile.Position; IndexBuild.XBoxMapData.XIndices.FixOffsets((uint)MetaFile.Position, NewMap.XBoxIndexHeader.IndexMagic); MetaFile.Write(IndexBuild.XBoxMapData.XIndices.IndirectOffsets, 0, IndexBuild.XBoxMapData.XIndices.IndirectOffsets.Length); MetaFile.Write(IndexBuild.XBoxMapData.XIndices.Verts, 0, IndexBuild.XBoxMapData.XIndices.Verts.Length); #endregion //Add info to the Meta info struct XBoxMeta.StructInfo Info = new XBoxMeta.StructInfo(); Info.MapMagic = NewMap.XBoxIndexHeader.IndexMagic; Info.TagMagic = NewMap.XBoxIndexHeader.IndexMagic; Info.StructurePath = StructFolder; Info.TagsPath = BasFolder; Info.Items = NewMap.XBoxIndexHeader.IndexItems; //Starts processing meta and writing it to the meta file Application.DoEvents(); for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++) { if (NewMap.XBoxIndexHeader.IndexItems[sc].TagClass1 != 0x70736273) // 70736273) { XBoxMeta Meta = new XBoxMeta(); Trace.WriteLine("Meta Processor: " + IndexList[sc]); TagFileName tfnTAG = new TagFileName(IndexList[sc], MapfileVersion.XHALO1); TagBase tbTAG = new TagBase(); tbTAG.LoadTagBuffer(tfnTAG); MTSFReader mr = new MTSFReader(); mr.MTSFRead("Core.Compiler.HALO_PC_SET.MTSF"); TSFReader STSF = new TSFReader(); STSF.TSF(ref mr, tbTAG.Header.TagClass0); HaloPCMAP.FixIntPosition(ref MetaFile); Info.CurrentOffset = (uint)MetaFile.Position; NewMap.XBoxIndexHeader.IndexItems[sc].MetaOffset = (uint)(MetaFile.Position + NewMap.XBoxIndexHeader.IndexMagic); Meta.DoProcessMeta(ref STSF, tbTAG.Stream, ref MetaFile, ref BSPFile, 1, IndexList, Info, ref NewMap, ref IndexBuild); tbTAG = null; } } //Create a new map header Application.DoEvents(); NewMap.XBoxHeader.Create(); string[] tmpName = scenario_tag.RelativePath.Split(new char[] { '\\' }, 256); tmpName = tmpName[tmpName.Length - 1].Split(new char[] { '.' }, 256); NewMap.XBoxHeader.MapName = tmpName[0]; //otf.FileName.Split(new char[]{'/'},256 //"Cool"; //Rewrite indextable of meta offsets Application.DoEvents(); TmpPosSave = MetaFile.Position; for (int sc = 0; sc < NewMap.XBoxIndexHeader.IndexItems.Length; sc++) { MetaFile.Seek(NewMap.XBoxIndexHeader.IndexItems[sc].Position, SeekOrigin.Begin); NewMap.XBoxIndexHeader.IndexItems[sc].Write(ref MetaFile); } MetaFile.Seek(TmpPosSave, SeekOrigin.Begin); //Create the new map file to begin construction of the new map. FileInfo Map_info = new FileInfo(Application.StartupPath + NewMap.XBoxHeader.MapName + ".Map"); FileStream Map; Map = Map_info.Open(FileMode.Create, FileAccess.ReadWrite); Application.DoEvents(); //Write the header to the new map file NewMap.XBoxHeader.Write(ref Map); //Flush the tmp BSPFile to get FileSize. CompUtil.FixIntPosition2K(ref BSPFile); BSPFile.Flush(); uint BSPFileSize = (uint)BSPFile.Length; //Seek to the begining of the tmp bsp file BSPFile.Seek(0, SeekOrigin.Begin); //Copy the Tmp bsp file to the new map file for (int bc = 0; bc < BSPFileSize; bc += 0x800) { byte[] copy = new byte[0x800]; BSPFile.Read(copy, 0, copy.Length); Map.Write(copy, 0, copy.Length); } //Put the Scnr index ID in the IndexHeader, you can move the scnr any were as long as you set this to the currect ID. NewMap.XBoxIndexHeader.ScnrID = (uint)((NewMap.XBoxIndexHeader.IndexItems[0].IndexID2 << 16) + NewMap.XBoxIndexHeader.IndexItems[0].IndexID1); //put the Current map position in the header so we know where the index header will be NewMap.XBoxHeader.IndexOffset = (uint)Map.Position; //Now we write the Index header to the map. NewMap.XBoxIndexHeader.Write(ref Map); //Flush the temp meta file so we can get the size. MetaFile.Flush(); uint MetaFileSize = (uint)MetaFile.Length; //seek to the begining of the temp meta file for coping to the new map file MetaFile.Seek(0, SeekOrigin.Begin); //Copy the meta file to the new map file. for (int bc = 0; bc < MetaFileSize; bc += 0x800) { byte[] copy = new byte[0x800]; MetaFile.Read(copy, 0, copy.Length); Map.Write(copy, 0, copy.Length); } //Now we fix the map version map size and rewrite it to the map. Map.Flush(); NewMap.XBoxHeader.MapVersion = 0x05; NewMap.XBoxHeader.MapSize = (uint)Map.Length; NewMap.XBoxHeader.MetaSize = MetaFileSize + 0x24; Map.Seek(NewMap.XBoxHeader.Position, SeekOrigin.Begin); NewMap.XBoxHeader.Write(ref Map); //Now close the files and delete the temp files. MetaFile.Flush(); MetaFile.Close(); File.Delete(MetaFile.Name); BSPFile.Close(); File.Delete(BSPFile.Name); Map.Close(); } }