예제 #1
0
        ///<summary>
        ///</summary>
        public override string[] MakePathAsArray(string path)
        {
            try
            {
                return(LuceneNodeIndexer.MakePathAsArray(path));
            }
            catch (Exception e)
            {
                Debug.Write(new Exception("LuceneIndexMgr: An error occurred in MakePathAsArray", e));
            }

            return(new string[] {});
        }
예제 #2
0
        ///<summary>
        ///</summary>
        public override string MakePath(Node node, string pathSeparator, bool includeEndToken)
        {
            try
            {
                return(LuceneNodeIndexer.MakePathForNode(node, pathSeparator, includeEndToken));
            }
            catch (Exception e)
            {
                Debug.Write(new Exception("LuceneIndexMgr: An error occurred in MakePath", e));
            }

            return(string.Empty);
        }
예제 #3
0
        ///<summary>
        ///</summary>
        public override string MakePath(Node node)
        {
            try
            {
                return(LuceneNodeIndexer.MakePathForNode(node));
            }
            catch (Exception e)
            {
                Debug.Write(new Exception("LuceneIndexMgr: An error occurred in MakePath", e));
            }

            return(string.Empty);
        }
예제 #4
0
        /// <summary>
        /// </summary>
        protected override void DoIndexNode(Node node, bool reindexAfterRemovingOld)
        {
            lock (this)
            {
                foreach (string langKey in luceneDirectoryIndexedByLanguageCodeThenView.Keys)
                {
                    foreach (string viewKey in luceneDirectoryIndexedByLanguageCodeThenView[langKey].Keys)
                    {
                        Directory d = luceneDirectoryIndexedByLanguageCodeThenView[langKey][viewKey];

                        IndexModifier modifier = new IndexModifier(d, LuceneLibrarySearchCriteriaAdaptor.ANALYZER, false);
                        try
                        {
                            foreach (int i in GetDocumentIdsForElementId(node.Id))
                            {
                                Document doc = GetDocument(i);
                                if (MakePath(node) == doc.GetField(LuceneNodeIndexer.PATH_FIELD).StringValue() && node.Order.ToString() == doc.GetField(LuceneNodeIndexer.ORDER_FIELD).StringValue())
                                {
                                    Debug.WriteLine(
                                        string.Format("DoIndexNode: Removing document {0} for element id {1}", i,
                                                      node.Id));
                                    modifier.DeleteDocument(i);
                                }
                            }
                        }
                        finally
                        {
                            Debug.WriteLine("DoIndexNode: Closing index reader");
                            modifier.Close();
                        }

                        if (!reindexAfterRemovingOld)
                        {
                            return;
                        }

                        indexWriter = new IndexWriter(d, LuceneLibrarySearchCriteriaAdaptor.ANALYZER, false);
                        LuceneNodeIndexer indexer = new LuceneNodeIndexer(indexWriter, langKey);
                        indexer.AddToIndex(node, node.PreferredLabel);
                    }
                }
            }
        }
예제 #5
0
        private string _MakeWordsQuery(ICollection <string> words, ICollection <LibrarySearchCriteria.SearchableTextField> inTheseTextFields, bool matchWholeWordsOnly, bool isConvertPluralsToSingular, string matchTypeOperator)
        {
            StringBuilder result = new StringBuilder();

            string matchWholeWordsFragment = matchWholeWordsOnly ? string.Empty : "*";

            int boost = words.Count * inTheseTextFields.Count;

            List <string> cleanedWords = new List <string>();

            foreach (string word in words)
            {
                if (!IsStopWord(word))
                {
                    cleanedWords.Add(CleanWord(word, isConvertPluralsToSingular));
                }
            }

            foreach (LibrarySearchCriteria.SearchableTextField tf in inTheseTextFields)
            {
                result.Append(string.Format("{0}:(", LuceneNodeIndexer.GetFieldName(tf)));

                if (words.Count > 1 && tf == LibrarySearchCriteria.SearchableTextField.Labels)
                {
                    result.Append(string.Format("\"{0}\"~6 ", string.Join(" ", new List <string>(words).ToArray())));
                }

                foreach (string cleanWord in cleanedWords)
                {
                    result.Append(string.Format("{0}{1}{2}^{3} ", matchTypeOperator, cleanWord, matchWholeWordsFragment, boost));
                    --boost;
                }

                result.Remove(result.Length - 1, 1); //Trim the last space from the end
                result.Append(") ");
            }

            if (result.Length > 1)
            {
                result.Remove(result.Length - 1, 1); //Trim the last space from the end
            }
            return(result.ToString());
        }
예제 #6
0
        /// <summary>
        /// </summary>
        protected override void DoIndexNode(Node node, bool reindexAfterRemovingOld)
        {
            lock(this)
            {
                foreach (string langKey in luceneDirectoryIndexedByLanguageCodeThenView.Keys)
                {
                    foreach (string viewKey in luceneDirectoryIndexedByLanguageCodeThenView[langKey].Keys)
                    {
                        Directory d = luceneDirectoryIndexedByLanguageCodeThenView[langKey][viewKey];

                        IndexModifier modifier = new IndexModifier(d, LuceneLibrarySearchCriteriaAdaptor.ANALYZER, false);
                        try
                        {
                            foreach (int i in GetDocumentIdsForElementId(node.Id))
                            {
                                Document doc = GetDocument(i);
                                if (MakePath(node) == doc.GetField(LuceneNodeIndexer.PATH_FIELD).StringValue() && node.Order.ToString() == doc.GetField(LuceneNodeIndexer.ORDER_FIELD).StringValue())
                                {
                                    Debug.WriteLine(
                                        string.Format("DoIndexNode: Removing document {0} for element id {1}", i,
                                                      node.Id));
                                    modifier.DeleteDocument(i);
                                }
                            }
                        }
                        finally
                        {
                            Debug.WriteLine("DoIndexNode: Closing index reader");
                            modifier.Close();
                        }

                        if (!reindexAfterRemovingOld) return;

                        indexWriter = new IndexWriter(d, LuceneLibrarySearchCriteriaAdaptor.ANALYZER, false);
                        LuceneNodeIndexer indexer = new LuceneNodeIndexer(indexWriter, langKey);
                        indexer.AddToIndex(node, node.PreferredLabel);
                    }
                }
            }
        }