Ejemplo n.º 1
0
        public static List <Document> SearchLuceneIndex(BooleanQueryContract oQuery, string sIndexName)
        {
            List <Document> oQueryResults;

            oQueryResults = new GenSearchService().ExecuteBooleanQuery(oQuery, sIndexName);

            return(oQueryResults);
        }
Ejemplo n.º 2
0
            public void Reset()
            {
                //create a query that we will use to search for results
                oQuery         = new BooleanQueryContract();
                oQuery.Clauses = new List <BooleanClauseContract>();

                //we are dirty
                bIsDirty = true;
            }
Ejemplo n.º 3
0
        public static List <Item> Search(BooleanQueryContract oQuery, string sIndexName, string fieldName)
        {
            List <Document> oDocumentFound;
            List <Item>     oItemsToReturn;
            string          sItemId;
            Item            oItem;

            Lucene.Net.Documents.Field oIdField;

            oItemsToReturn = new List <Item>();
            oDocumentFound = SearchLuceneIndex(oQuery, sIndexName);

            if (oDocumentFound != null)
            {
                foreach (Document oDoc in oDocumentFound)
                {
                    oIdField = oDoc.GetField(fieldName);

                    if (oIdField != null)
                    {
                        sItemId = oIdField.StringValue;

                        if (!string.IsNullOrEmpty(sItemId))
                        {
                            oItem = ContextExtension.CurrentDatabase.GetItem(sItemId);
                            if (oItem != null)
                            {
                                oItemsToReturn.Add(oItem);
                            }
                        }
                    }
                }
            }

            return(oItemsToReturn);
        }
 public List <Lucene.Net.Documents.Document> ExecuteBooleanQuery(BooleanQueryContract query, string indexName)
 {
     return(base.Channel.ExecuteBooleanQuery(query, indexName));
 }
Ejemplo n.º 5
0
        public List <Lucene.Net.Documents.Document> ExecuteBooleanQuery(BooleanQueryContract oQuery, string sIndexName)
        {
            #region VARIABLES

            List <Lucene.Net.Documents.Document> oLuceneQueryResults;
            Analyzer oAnalyzer;
            MultiFieldQueryParser oQueryParser;
            Query        oLuceneQuery;
            BooleanQuery oLuceneBooleanQuery;

            #endregion

            Sitecore.Diagnostics.Log.Info("GenSearchService - ExecuteBooleanQuery - Begins", this);

            Sitecore.Diagnostics.Log.Info(string.Format("Executing query  on Index {0}", sIndexName), this);

            oLuceneQueryResults = null;

            if (oQuery != null && oQuery.Clauses != null)
            {
                oLuceneBooleanQuery = new BooleanQuery();

                /*
                 * An Analyzer builds TokenStreams to analyze the text.
                 * The analyzer represents a policy for extracting index terms from the text.
                 * A common implementation is to build a Tokenizer, which breaks the stream
                 * of characters from the Reader into raw Tokens.
                 * One or more TokenFilters may then be applied to the output of the Tokenizer.
                 * spurious (stop) words using English dictionary
                 */
                oAnalyzer = new StandardAnalyzer(LuceneVersion);

                try
                {
                    foreach (var oClause in oQuery.Clauses)
                    {
                        if (oClause.MultiFieldQuery != null && oClause.MultiFieldQuery.Fields != null && oClause.MultiFieldQuery.Fields.Length > 0 && !string.IsNullOrEmpty(oClause.MultiFieldQuery.SearchCriteria))
                        {
                            /*
                             * QueryParser obtains token stream using the Analizer and creates the Query
                             * baseing on internal rules.
                             * QueryParser need to know content field in index to be able to parse queries like
                             * "Search" or "Example". These queries will be transformed into
                             * [content_field]:Search and [content_field]:Example
                             */

                            oQueryParser = new MultiFieldQueryParser(LuceneVersion, oClause.MultiFieldQuery.Fields, oAnalyzer);


                            /*
                             * In default mode (OR_OPERATOR) terms without any modifiers are considered optional:
                             * for example Test search is equal to Test OR search.
                             * In AND_OPERATOR mode terms are considered to be in conjuction: the above mentioned
                             * query is parsed as Test AND search
                             */
                            oQueryParser.DefaultOperator = QueryParser.Operator.OR;


                            /*
                             * This method converts string query to object Query that can be used in searching
                             */
                            oLuceneQuery = oQueryParser.Parse(oClause.MultiFieldQuery.SearchCriteria);


                            oLuceneBooleanQuery.Add(oLuceneQuery, ParseBooleanClauseOccur(oClause.Occur));
                        }
                    }

                    oLuceneQueryResults = ExecuteQuery(oLuceneBooleanQuery, sIndexName);
                }
                catch (Exception oSearchException)
                {
                    Sitecore.Diagnostics.Log.Error("Error executing search request", oSearchException, typeof(GenSearchService));
                }
            }

            if (oLuceneQueryResults == null)
            {
                Sitecore.Diagnostics.Log.Warn(string.Format(" Search on index {0} returned NULL", sIndexName), this);
            }
            else
            {
                Sitecore.Diagnostics.Log.Info(string.Format("Query executed result documents {0}", oLuceneQueryResults.Count), this);
            }
            Sitecore.Diagnostics.Log.Info("GenExternalSearchService - ExecuteBooleanQuery - Ends", this);

            return(oLuceneQueryResults);
        }