コード例 #1
0
        private static void search(Guid applicationId, ref List <SearchDoc> retDocs, ref List <SearchDoc> toBeRemoved,
                                   Guid?currentUserId, ref int?lowerBoundary, int count, ref Query query, ref IndexSearcher searcher,
                                   string phrase, List <SearchDocType> docTypes, List <Guid> typeIds, List <string> types, bool additionalId, bool title,
                                   bool description, bool content, bool tags, bool fileContent, bool forceHasContent, bool highlight, ref int totalCount)
        {
            if (!lowerBoundary.HasValue)
            {
                lowerBoundary = 0;
            }

            int newBoundary = lowerBoundary.Value;

            List <SearchDoc> listDocs = new List <SearchDoc>();

            if (RaaiVanSettings.Solr.Enabled)
            {
                listDocs = SolrAPI.search(applicationId, phrase, docTypes, typeIds, types, additionalId, title,
                                          description, tags, content, fileContent, forceHasContent, count, newBoundary, highlight, ref totalCount)
                           .Select(d => SearchDoc.ToSearchDoc(d)).Where(d => d != null).ToList();
            }
            else
            {
                if (query == null || searcher == null)
                {
                    create_lucene_searcher(applicationId, docTypes, typeIds, types, additionalId,
                                           title, description, content, tags, fileContent, forceHasContent, phrase, ref query, ref searcher);

                    if (query == null || searcher == null)
                    {
                        return;
                    }
                }

                listDocs = lucene_search(applicationId, newBoundary, count, ref query, ref searcher,
                                         additionalId, title, description, content, tags, fileContent);
            }

            retDocs.AddRange(process_search_results(applicationId, listDocs, currentUserId, ref toBeRemoved, count));

            newBoundary += listDocs.Count;

            if (lowerBoundary != newBoundary)
            {
                lowerBoundary = newBoundary;
                if (retDocs.Count < count)
                {
                    search(applicationId, ref retDocs, ref toBeRemoved, currentUserId, ref lowerBoundary,
                           count - retDocs.Count, ref query, ref searcher, phrase, docTypes, typeIds, types, additionalId, title,
                           description, content, tags, fileContent, forceHasContent, highlight, ref totalCount);
                }
            }
        }
コード例 #2
0
        private static List <SearchDoc> lucene_search(Guid applicationId, int lowerBoundary, int count, ref Query query,
                                                      ref IndexSearcher searcher, bool additionalId, bool title, bool description, bool content, bool tags, bool fileContent)
        {
            try
            {
                List <SearchDoc> listDocs = new List <SearchDoc>();

                TopDocs hits = searcher.Search(query, lowerBoundary + count + (count / 2));
                FastVectorHighlighter fvHighlighter = new FastVectorHighlighter(true, true);

                for (int i = lowerBoundary, lnt = hits.ScoreDocs.Length; i < lnt; ++i)
                {
                    ScoreDoc sd = hits.ScoreDocs[i];

                    string addIdFr = !additionalId ? string.Empty :
                                     fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),
                                                                   searcher.IndexReader, docId: sd.Doc, fieldName: "AdditionalID", fragCharSize: 200);
                    string titleFr = !title ? string.Empty :
                                     fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),
                                                                   searcher.IndexReader, docId: sd.Doc, fieldName: "Title", fragCharSize: 200);
                    string descFr = !description ? string.Empty :
                                    fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),
                                                                  searcher.IndexReader, docId: sd.Doc, fieldName: "Description", fragCharSize: 200);
                    string contentFr = !content ? string.Empty :
                                       fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),
                                                                     searcher.IndexReader, docId: sd.Doc, fieldName: "Content", fragCharSize: 200);
                    string tagsFr = !tags ? string.Empty :
                                    fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),
                                                                  searcher.IndexReader, docId: sd.Doc, fieldName: "Tags", fragCharSize: 200);
                    string fileFr = !fileContent ? string.Empty :
                                    fvHighlighter.GetBestFragment(fvHighlighter.GetFieldQuery(query),
                                                                  searcher.IndexReader, docId: sd.Doc, fieldName: "FileContent", fragCharSize: 200);

                    if (!string.IsNullOrEmpty(titleFr))
                    {
                        titleFr = titleFr.Trim();
                    }
                    if (!string.IsNullOrEmpty(addIdFr))
                    {
                        addIdFr = addIdFr.Trim();
                    }

                    string highlightedText = ((string.IsNullOrEmpty(descFr) ? string.Empty : descFr + " ") +
                                              (string.IsNullOrEmpty(contentFr) ? string.Empty : contentFr + " ") +
                                              (string.IsNullOrEmpty(tagsFr) ? string.Empty : tagsFr + " ") +
                                              (string.IsNullOrEmpty(fileFr) ? string.Empty : fileFr)).Trim();

                    if (string.IsNullOrEmpty(addIdFr) && string.IsNullOrEmpty(titleFr) && string.IsNullOrEmpty(highlightedText))
                    {
                        break;
                    }

                    Document  doc  = searcher.Doc(sd.Doc);
                    SearchDoc item = SearchDoc.ToSearchDoc(doc);
                    item.Description = highlightedText;
                    listDocs.Add(item);
                }

                return(listDocs);
            }
            catch (Exception ex)
            {
                LogController.save_error_log(applicationId, null, "SearchIndexDocuments", ex, ModuleIdentifier.SRCH);
                return(new List <SearchDoc>());
            }
        }