Пример #1
0
        public Data searchLucene(Data data)
        {
            Search_gl search = new Search_gl();
            List<string> item = new List<string>();
            Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo(Environment.CurrentDirectory + "\\LuceneIndex"));
            var analyzer = new StandardAnalyzer(Version.LUCENE_29);

            IndexReader reader = IndexReader.Open(directory, true);
            IndexSearcher searcher = new IndexSearcher(reader);

            //QueryParser queryParser = new QueryParser(Version.LUCENE_29, "summary", analyzer);  //search for single field
            MultiFieldQueryParser parser = new MultiFieldQueryParser(new string[] {"name", "summary"}, analyzer);  //search for multifield
            Query query = parser.Parse((data.getString("search")) + "*"); //cant search blank text with wildcard as first character

            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
            searcher.Search(query, collector);
            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
            int count = hits.Length;

            for (int i = 0; i < count; i++)
            {
                int docId = hits[i].doc;
                float score = hits[i].score;

                Document doc = searcher.Doc(docId);

                string id = doc.Get("id");
                item.Add(id);
            }
            Data list = search.search(data, item.ToArray());
            reader.Close();
            searcher.Close();

            return list;
        }
Пример #2
0
 public static String[] searchContent(string prefixText, int count)
 {
     Search_gl search = new Search_gl();
     Data data = new Data();
     data.add("search", prefixText);
     Lucene_gl lucene = new Lucene_gl();
     Data list = lucene.searchLucene(data);
     return search.list(list);
 }
Пример #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Data data = new Data();
            Search_gl search = new Search_gl();
            Paging_gl page = new Paging_gl();
            Profile_gl profile = new Profile_gl();
            Lucene_gl lucene = new Lucene_gl();
            Data list = null;
            data.add("search", search.searchUrlConversion(Param.getString("search")));
            data.add("page", page.getCurrentSearchPage(Param.getString("page")));
            data.add("range", Param.getString("range"));
            data.add("rate", Param.getString("rate"));

            if (data.getString("search") == "")
            {
                list = search.selectAll(data);
            }
            else
            {
                list = lucene.searchLucene(data);
            }
            int count = page.setPage(data);
            for (int i = 1; i <= count; i++)
            {
                dropDownPage.Items.Add(new ListItem(i.ToString()));
            }
            dropDownPage.SelectedValue = Param.getString("page");

            if (page.previousPage(Param.getString("page")) == true)
            {
                previous.Visible = false;
            }

            if (page.nextPage(Param.getString("page"), count) == true)
            {
                next.Visible = false;
            }
            // data.add all values in to same array, pass data array to advance search class in logical lib and split in to multiple search methods.
            if (data.getString("range") != "" && data.getString("search") != "")
            {
                int range = Convert.ToInt32(data.getString("range"));
                if (range > 0)
                {
                    data.add("address", data.getString("search"));
                    list = search.searchRadius(data);
                }
            }

            searchView.DataSource = list.Source;
            searchView.DataBind();

        }
    }
Пример #4
0
        public void addLucene(Data data)
        {
            Search_gl search = new Search_gl();
            Data searchForIndex = search.getSearchForIndex(data);
            Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo(Environment.CurrentDirectory + "\\LuceneIndex"));
            var analyzer = new StandardAnalyzer(Version.LUCENE_29);
            var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);

            for (int i = 0; i < searchForIndex.Count; i++)
            {
                Document document = new Document();
                document.Add(new Field("id", searchForIndex.getValue(i, "id").ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                document.Add(new Field("name", searchForIndex.getValue(i, "name").ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                document.Add(new Field("summary", searchForIndex.getValue(i, "summary").ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
                writer.AddDocument(document);
                writer.Optimize();
                writer.Commit();

            }
            writer.Close();
        }
Пример #5
0
 protected void searchBtn_Click(object sender, EventArgs e)
 {
     Search_gl search = new Search_gl();
     string urlString = search.urlSearch(Param);
     go("../search/list.aspx?search=" + Param.getString("search") + "&page=" + 1 + urlString); //dynamic url data
 }