1

我正在尝试从数据库中获取数据以显示在网页上,并可以通过页面上的文本框进行搜索,使用 solrnet 进行搜索和 asp.net。我已经实现了类似于在 solrnet wiki 上的文档中设置搜索的方式。第一个问题是,在尝试设置查询时,大约有一半的代码会中断,而且奇怪的是,仅针对特定的输入字符串(我已经确定“france”、“f”和“a”会中断)错误信息。

"Object of type 'System.String' cannot be converted to type 'System.Nullable`1[System.Int32]'." 

我尝试过调试,但它深入到 solrnet 代码中,我什至找不到它试图在哪里进行这种损坏的转换。另一个问题是,即使它没有损坏,也没有结果!我也不知道为什么会这样,尽管它可能与我们的 solr 模式的“默认字段”有关。

无论如何,这是代码的相关部分;如果您需要其他任何内容,请告诉我,我可以发布:

    public string Search(string text)
    {
        // Solr init stuff
        var solr = SolrOpsCache<Product>.GetSolrOperations();

        // Code will often break pointing this block below
        var matchingProducts = solr.Query(new SolrQuery(text), new QueryOptions {
            Start = 1,
            Rows = 30,
        });

        // This is just formatting the results correctly for the
        // stored proc I have on the database
        List<string> matchingItemCodes = new List<string>();

        foreach (Product p in matchingProducts)
        {
            matchingItemCodes.Add(p.itemCode);
        }
        string itemCodesDelimited = ToDelimitedString(matchingItemCodes, ",");
        return itemCodesDelimited;
    }


    protected void SearchButton_Click(object sender, EventArgs e)
    {
        // Search based on what's in the box
        string codes = Search(SearchBox.Text);
        productList = pr.GetProductsByItemcode(codes);
    }
}

架构.xml:

<schema name="RML Schema" version="1.1">
  <types>
    <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true" />
    <fieldType name="cat_string" class="solr.TextField" sortMissingLast="true" omitNorms="true">      
      <analyzer>  
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>  
      </analyzer>  
    </fieldType>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>

    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="int" class="solr.IntField" />
  </types>

 <fields>   

    <field name="ItemCode" type="string" indexed="true" stored="true" required="true" />  
     <field name="ItemName" type="text_general" indexed="true" stored="true"/>  
     <field name="RML" type="cat_string" indexed="true" stored="true"/>  
     <field name="Buyer" type="cat_string" indexed="true" stored="true"/>  
     <field name="Vendor" type="cat_string" indexed="true" stored="true"/> 

     <field name="AvgCost" type="float" indexed="true" stored="true"/> 
     <field name="SalePrice" type="float" indexed="true" stored="true"/> 
     <field name="Profit_Ave" type="float" indexed="true" stored="true"/> 
     <field name="Profit_MSRP" type="float" indexed="true" stored="true"/> 
     <field name="OnHand" type="int" indexed="true" stored="true"/> 
     <field name="IsCommited" type="int" indexed="true" stored="true"/> 
     <field name="OnOrder" type="int" indexed="true" stored="true"/> 
     <field name="ATS" type="int" indexed="true" stored="true"/> 
     <field name="AOH" type="int" indexed="true" stored="true"/> 

     <field name="text" type="text_general" indexed="true" stored="true" multiValued="true"/>
     <field name="Vintage" type="cat_string" indexed="true" stored="true"/>
     <field name="Producer" type="cat_string" indexed="true" stored="true" />
     <field name="Country" type="cat_string" indexed="true" stored="true" />
     <field name="Region" type="cat_string" indexed="true" stored="true" />
     <field name="Appellation" type="cat_string" indexed="true" stored="true" />
     <field name="CRU" type="cat_string" indexed="true" stored="true" />
     <field name="Size" type="cat_string" indexed="true" stored="true" />
     <field name="RtrakDept" type="cat_string" indexed="true" stored="true" />

 </fields>

还有我的产品课

public class Product
    {
        [SolrUniqueKey("ItemCode")]
        public string itemCode { get; set; }

        [SolrField("ItemName")]
        public string itemName { get; set; }

        /* Commented out because it's not in the database yet
        [SolrField("RML")]
        public string rml { get; set; }        
        */

        [SolrField("Buyer")]
        public string buyer { get; set; }

        [SolrField("Vendor")]
        public string vendor { get; set; }

        [SolrField("AvgCost")]
        public Nullable<float> avgCost { get; set; }

        [SolrField("SalePrice")]
        public Nullable<float> salePrice { get; set; }

        [SolrField("Profit_Ave")]
        public Nullable<float> profitAve { get; set; }

        [SolrField("Profit_MSRP")]
        public Nullable<float> profitMSRP { get; set; }

        [SolrField("OnHand")]
        public Nullable<int> onHand { get; set; }

        [SolrField("IsCommited")]
        public Nullable<int> isCommited { get; set; }

        [SolrField("OnOrder")]
        public Nullable<int> onOrder { get; set; }        

        [SolrField("ATS")]
        public Nullable<int> ats { get; set; }

        [SolrField("AOH")]
        public Nullable<int> aoh { get; set; }

        [SolrField("Vintage")]
        public string vintage { get; set; }

        [SolrField("Producer")]
        public string producer { get; set; }

        [SolrField("Country")]
        public string country { get; set; }

        [SolrField("Region")]
        public string region { get; set; }

        [SolrField("Appellation")]
        public string appellation { get; set; }

        [SolrField("CRU")]
        public string cru { get; set; }

        [SolrField("Size")]
        public string size { get; set; }

        [SolrField("RtrakDept")]
        public string rtrakDept { get; set; }
}

谢谢!

4

0 回答 0