Esempio n. 1
0
        /// <summary>
        /// Add Document To Index Storage
        /// </summary>
        /// <param name="indexStorage">Index Storage</param>
        /// <param name="textSpot">TextSpotting Data</param>
        public static void AddDocumentToIndexStorage(IndexStorage indexStorage, TextSpot textSpot)
        {
            Document doc = new Document();

            doc.Add(new Field(FRAME_NAME, textSpot.FileName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TEXT_SPOT, textSpot.Text, Field.Store.YES, Field.Index.ANALYZED));

            indexStorage.GetIndexWriter().AddDocument(doc);
        }
Esempio n. 2
0
        /// <summary>
        /// Add Document TextCaption to IndexStorage
        /// </summary>
        /// <param name="indexStorage">Index Storage</param>
        /// <param name="textCaption">TextCaption data</param>

        public static void AddDocumentToIndexStorage(IndexStorage indexStorage, TextCaption textCaption)
        {
            Document doc = new Document();

            doc.Add(new Field(FRAME_NAME, textCaption.FrameName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(TEXT_CAPTION, textCaption.Caption, Field.Store.YES, Field.Index.ANALYZED));

            indexStorage.GetIndexWriter().AddDocument(doc);
        }
Esempio n. 3
0
 /// <summary>
 /// Add List TextCaption Data to IndexStorage
 /// </summary>
 /// <param name="indexStorage">Index Storage</param>
 /// <param name="textCaption">List TextCaption data</param>
 public static void IndexFromDatabaseStorage(IndexStorage indexStorage, List <TextCaption> textCaption)
 {
     if (textCaption != null && textCaption.Count > 0)
     {
         foreach (TextCaption item in textCaption)
         {
             AddDocumentToIndexStorage(indexStorage, item);
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Add List TextSpotting Data to IndexStorage
 /// </summary>
 /// <param name="indexStorage">IndexStorage</param>
 /// <param name="textSpot">List TextSpot data</param>
 public static void IndexFromDatabaseStorage(IndexStorage indexStorage, List <TextSpot> textSpot)
 {
     if (textSpot != null && textSpot.Count > 0)
     {
         foreach (TextSpot item in textSpot)
         {
             AddDocumentToIndexStorage(indexStorage, item);
         }
     }
 }
        public static List <Object> SearchByQueryPlusScore(IndexStorage indexStorage, int topRank, String query, SearchType searchType, out List <float> listScores)
        {
            listScores = new List <float>();
            if (String.IsNullOrEmpty(query))
            {
                return(null);
            }
            IndexSearcher indexSearch = new IndexSearcher(indexStorage.DirectoryIndexing);

            //var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new[]{
            //    Indexing.TEXT_SPOT}, indexStorage.analyzer);

            Lucene.Net.QueryParsers.QueryParser queryParser = null;
            if (searchType == SearchType.OCR)
            {
                queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, Indexing.TEXT_SPOT, indexStorage.analyzer);
            }
            else if (searchType == SearchType.CAPTION)
            {
                queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, Indexing.TEXT_CAPTION, indexStorage.analyzer);
            }


            Query   q       = queryParser.Parse(query);
            TopDocs topDocs = indexSearch.Search(q, topRank);

            if (topDocs == null || topDocs.ScoreDocs.Length == 0)
            {
                return(null);
            }

            List <Object> result = new List <Object>();

            for (int i = 0; i < topDocs.ScoreDocs.Length; i++)
            {
                ScoreDoc scoreDoc = topDocs.ScoreDocs[i];
                float    score    = scoreDoc.Score;
                listScores.Add(score);
                //Console.WriteLine(score);
                int docId = scoreDoc.Doc;

                Document doc = indexSearch.Doc(docId);

                if (searchType == SearchType.OCR)
                {
                    result.Add(new TextSpot(doc.Get(Indexing.FRAME_NAME), doc.Get(Indexing.TEXT_SPOT)));
                }
                else if (searchType == SearchType.CAPTION)
                {
                    result.Add(new TextCaption(doc.Get(Indexing.FRAME_NAME), doc.Get(Indexing.TEXT_CAPTION)));
                }
            }
            return(result);
        }